[英]adding uiview as a subview to the main view
i want to add an UIView
for small size as a subview to existing view. 我想添加一个小尺寸的
UIView
作为现有视图的子视图。
i have a UIViewController
pushed with a nib name which is the main view, i am trying to create an object of UIView
and alloc it with dimension with the following code in the viewcontroller's viewDidLoad
methoad 我有一个
UIViewController
与一个nib名称推送是主视图,我试图创建一个UIView
的对象,并在viewcontroller的viewDidLoad
方法中使用以下代码分配它
UIView *view = [[UIView alloc] init];
but the idea is not suggesting the alloc on UIView
and throwing an error if i forcefully type and run 但是,如果我强行键入并运行,那么这个想法并不是建议在
UIView
上使用alloc并抛出错误
please help me out with this 这个你能帮我吗
To add something (rather important) to the answers above; 为上面的答案添加一些东西(相当重要);
CGRect frame = CGRectMake(x, y, width, height); // Replacing with your dimensions
UIView *view = [[UIView alloc] initWithFrame:frame];
Then, you want to actually add it to the superview (assuming the view is self.view) 然后,你想要实际将它添加到superview(假设视图是self.view)
[self.view addSubview:view];
UIView needs to be alloc'ed and init'ed with a frame: 需要使用框架分配和初始化UIView:
CGRect frame = CGRectMake(x, y, width, height); // Replacing with your dimensions
UIView *view = [[UIView alloc] initWithFrame:frame];
UIView *view = [[UIView alloc] init];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.