想请教一下各位大大,本人最近研究如何把一些控件抽出来复用,就遇到这个问题。
问题是这样的,创建一个UIView,简称V1,背景颜色设置成红色,设置size Freedom,大小300 X 300,左上弄一个Button,左下弄一个Button,分别设置好左上,还有右下等宽高约束。然后在控制器的StoryBoard里面创建一个一个UIView,简称V2, 大小 200 X 200,按照多种网上的方法,比如设置StoryBoard里面V2的class是V1...,或者什么都不设置,在m文件配置nib...等方法,我最后只能显示左上的Button,看不到右下角的label。又或者看到两个子空间,但是红色部分200x200,右下角的Button就会超出红色部分父控件的View。
现在就是想请教一下,如何能在StoryBoard里面,创建一个UIView,然后调用我自定义UIView的内容,通过修改在StoryBoard里面的View的大小,在加了约束的时候,不会出现以上子控件超出父控件的情况?
uiview does not have Xib by default but can be added manually. This has happened in previous projects: create an empty Xib, set the size of the xib to freedom, and then associate it with the corresponding class. Implement the following method in the class
(TextXibView*)textXibView
{
NSArray *nibView = [[NSBundle mainBundle]loadNibNamed:@"TextXibView" owner:nil options:nil];
return [nibView objectAtIndex:0]; // This method is to get Out of xib view
}
In this case, the uiview and the class are already associated, and you can call it anywhere else.
TextXibView *textView = [TextXibView textXibView];
textView.frame = CGRectMake(100, 500, 200, 200);
Or there is an article here that you can refer to http://www.cnblogs.com/wendingding/p/3750378.html