Tag: addsubview

如何使用iOS 6中的多个子视图自动布局现有的自定义视图

我想使用约束的布局,但我有许多内部嵌套Subviews的自定义控件。 而且我将约束添加到顶视图(CustomView),但没有正确布置子视图。 防爆。 我有TextFieldWithLabel类,它显示上方和下方的标签,我创build了TextFieldWithLabel实例的UITextField,并添加到具有约束的超级视图。 但没有按预期显示结果。 虽然它的可见,但不是我想要的地方。为此我不想改变整个TextFieldWithLabel类仇敌自动布局。 请帮忙! usernameTextField = [[TextFieldWithLabel alloc] initWithFrame:CGRectMake(0, 0, 100, 50) name:@"UserName"]; [usernameTextField setTranslatesAutoresizingMaskIntoConstraints:NO]; [superview addSubview:usernameTextField]; NSLayoutConstraint* myConstraint = [NSLayoutConstraint constraintWithItem:usernameTextField attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:superview attribute:NSLayoutAttributeCenterY multiplier:1 constant:0]; [superview addConstraint:myConstraint]; myConstraint = [NSLayoutConstraint constraintWithItem:usernameTextField attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:superview attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]; [superview addConstraint:myConstraint]; 屏幕截图:这里没有居中,文本字段(RedColor)也是不可点击的。标签和文本字段放在TextFieldWithLabel中。 请注意:TextFieldWithLabel是ComponentView的子类,ComponentView是UIView的子类。所以我怀疑这可能是问题? 我是否也需要自动布局ComponentsView。

Swift – 以编程方式将自定义Xib视图添加为子视图

我做了一个定制的xib,我已经在我的故事板中使用过,我只想创build一个自定义视图resize的实例,然后将其作为子视图添加到uiscrollview。 我试过在我的视图控制器的viewdidload func中使用这块代码 let cardView = CardView(coder: NSCoder()) cardView!.frame.size.width = 100 cardView!.frame.size.height = 100 scrollView.addSubview(cardView!) 但我得到这个错误 Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -containsValueForKey: cannot be sent to an abstract object of class NSCoder: Create a concrete instance!' 编辑:这是连接到CardView.xib的swift文件的代码 import UIKit class CardView: UIView { @IBOutlet var view: UIView! @IBOutlet weak var cornerView: […]

子视图从屏幕底部向上滑动

我试图创build一个animation,这是一个视图,我把它放在屏幕视图之外的视图框架中。 然后,我想将它从当前帧位置animation到屏幕上方的新位置。 目前我的代码看起来像这样 //.. ButtonOneViewController *b1VC = [[ButtonOneViewController alloc] initWithNibName:@"ButtonOneViewController" bundle:[NSBundle mainBundle]]; UIView *animatedActionView = [[UIView alloc] initWithFrame:CGRectMake(10.0, 490.0, 300.0, 380.0)]; //off screen [animatedActionView addSubview:b1VC.view]; [otherNav.view insertSubview:animatedActionView belowSubview:tbView]; // what do I do to animate it up to a position of (10.0, 10.0, 300.0, 380.0) 任何帮助将不胜感激。

添加子视图时,如果应用处于横向模式,视图不会resize

我有一个在Interface Builder中创build的视图,并configuration为根据方向resize。 如果在应用程序处于纵向模式时创build视图并将其添加到显示器,则一切正常。 然后,我可以旋转设备/模拟器和视图的大小,我所期望的。 但是,如果在横向模式下添加视图,则不会正确resize。 该视图的创build和大小就好像应用程序仍处于纵向模式一样。 该视图添加了以下代码: self.viewController = [[MyViewController alloc] initWithNibName:nibName bundle:bundle]; [self addSubview:self.viewController.view]; 这里没什么神奇的事情发生 另外,视图控制器指定: – (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; } 同样,只要在纵向模式下添加视图,它就会按预期工作。 我已经尝试了几个不同的东西,包括在视图上手动设置autoresizingMask属性,调用setNeedsLayout,并调用layoutIfNeeded,但似乎没有任何工作。 我能够手动设置框架的宽度和高度来强制视图的大小,但是这打破了视图的dynamic特性。 例如,如果我手动设置宽度高度不调整作为内容不重新布局。 有任何想法吗?

将UITableView添加到现有的ViewController

我试图以编程方式将UITableView添加到现有的UIViewController 。 我的run.h文件有这样的: @interface runTests : UIViewController <UINavigationControllerDelegate,UITextFieldDelegate,UIAlertViewDelegate,UITableViewDelegate,UITableViewDataSource> {NSTimer *Timer;} @property (strong, nonatomic) UITableView *tableView; 我的应用程序运行速度testing,并在testing结束时,我试图添加一个TableView到视图。 目前我有这个: -(void)addSpeedTable { self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds]; self.tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth; self.tableView.rowHeight = 45; self.tableView.sectionFooterHeight = 22; self.tableView.sectionHeaderHeight = 22; self.tableView.delegate = self; self.tableView.dataSource = self; [self.view addSubview:self.tableView]; } – (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } – (NSInteger)tableView:(UITableView *)tableView […]

把以前增加的观点带到前面

我的问题是以下几点: 我有一个视图,并为该视图添加3个子视图( view1 , view2 , view3 )的顺序。 意见略有重叠。 我想把第一个观点带到最前面,但是我不能得到它的工作。 我试图用insertSubview:atIndex:添加视图,并给view1一个更大的索引,我尝试使用addSubview:然后bringSubviewToTop但似乎没有工作。 有任何想法吗? PS我不能以不同的顺序添加视图。 他们必须按此顺序添加。

ViewController addSubview

我几乎要疯了: GolOlurActionViewController *golOlur = [[GolOlurActionViewController alloc] init]; [self.view addSubview:golOlur.view]; 我有上面的代码,我在一个ViewController中的IBACtion调用它。 GolOlurActionViewController是一个ViewController ,你可以猜到。 当这个过程开始时,golOlur的viewDidLoad和viewDidAppear方法被调用,但是这个视图不会被显示。 我已经尝试了我所知道的一切,但无法解决这个问题。

iOS视图在addSubview上重置

我有一个正方形的imageView在中间的故事板:280,140(垂直)当应用程序启动时,我可以通过按下button来移动这个imageView。 我移动imageView使用: _mainImage.frame = CGRectMake(_mainImage.frame.origin.x + 2, _mainImage.frame.origin.y, _mainImage.frame.size.width, _mainImage.frame.size.height); 而应用程序正在运行,我不断添加新的imageViews到mainView: UIImageView *imgView; imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, yCoordinate, 50, 10)]; imgView.backgroundColor = [UIColor whiteColor]; [self.view addSubview:imgView]; 每次我把这个代码称为方形imageView,我已经放在中间,四处移动,回到原来的位置。 每次调用addSubview时,似乎mainView都会“重置”。 有没有什么办法,我可以添加一个子视图,而没有主视图“重置”?

将自定义视图添加到警报视图

我有这样的问题: 我想在一个警报视图中显示一个自定义的视图。 所以我创build了一个单独的xib文件,并devise了我的界面,并为它实现了类。但是当我应用下面的代码时,它给了我一个错误。 这是代码: UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Confirm your Action" message:@"Click OK to confirm" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Cancel",nil]; NSArray *subviewArray = [[NSBundle mainBundle] loadNibNamed:@"customDialogViewController" owner:self options:nil]; customDialogViewController *myView = (customDialogViewController*) [subviewArray objectAtIndex:0]; [alert setValue:myView forKey:@"accessoryView"]; //alert.alertViewStyle = UIAlertViewStylePlainTextInput; alert.tag = KAlertViewthree; [alert show]; 这是我的错误: Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'child view […]

连续更改UISlider的拇指图像上的UILabel的值

我有一个UISlider (最less1,最多10)。 我希望它的拇指有一个UILabel放在它的顶部,不断更新和改变其移动UISlider的拇指的文字。 所以,我从UISlider了一个UILabel图像,并添加了一个UILabel ,但是标签似乎覆盖了它自己,而没有删除之前的值。 – (IBAction)SnoozeSliderValueChanged:(id)sender { UIImageView *handleView = [_snoozeSlider.subviews lastObject]; UILabel *label = [[UILabel alloc] initWithFrame:handleView.bounds]; label.text = [NSString stringWithFormat:@"%0.0f", self.snoozeSlider.value]; label.backgroundColor = [UIColor clearColor]; label.textAlignment = NSTextAlignmentCenter; [handleView addSubview:label]; } 原来, 然后,当我开始拖动, 我希望标签可以删除以前的值,并在拇指移动时显示当前值。 任何帮助表示赞赏。谢谢!