将uiview作为子视图添加到主视图中 [英] adding uiview as a subview to the main view
问题描述
我想为小尺寸添加 UIView
作为现有视图的子视图。
i want to add an UIView
for small size as a subview to existing view.
我有一个 UIViewController
用一个nib名称推送,这是主视图,我试图创建一个 UIView
的对象并分配它视图控制器的 viewDidLoad
方法中具有以下代码的维度
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
UIView *view = [[UIView alloc] init];
但想法并不是建议 UIView $ c $上的分配c>如果我强行键入并运行则抛出错误
but the idea is not suggesting the alloc on UIView
and throwing an error if i forcefully type and run
请帮我解决这个问题
推荐答案
在上面的答案中添加一些内容(相当重要);
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];
然后,你想要实际将它添加到superview(假设视图是self.view)
Then, you want to actually add it to the superview (assuming the view is self.view)
[self.view addSubview:view];
这篇关于将uiview作为子视图添加到主视图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!