创建UIView对象的两种方法

来源:互联网 发布:软件杯报名时间 编辑:程序博客网 时间:2024/05/21 08:02

1.使用xib文件

通过xib的⽅式来创建视图对象
NSBundle *bundle = [NSBundlemainBundle]; //获取当前程序的文件目录
NSArray *arr = [bundle loadNibNamed:@"myView"owner:self options:nil];
UIView *myView = [arr objectAtIndex:0];


2.手动绘制
CGRectviewRect = CGRectMake(0,0, 100, 100);
UIView *myView = [[UIViewalloc] initWithFrame:viewRect];


参考:
Unarchives the contents of a nib file located in the receiver's bundle.

- (NSArray *)loadNibNamed:(NSString *)name
                    owner:(id)owner
                  options:(NSDictionary *)options

Parameters

name

The name of the nib file, which need not include the .nib extension.

owner

The object to assign as the nib’s File's Owner object.

options

A dictionary containing the options to use when opening the nib file. For a list of available keys for this dictionary, see Nib File Loading Options.




0 0
原创粉丝点击