iOS开发中addSubview的参数放在一个”({})”代码块中
例子1
[
self.view addSubview:({
UIView *view = [[
UIView alloc]initWithFrame:(
CGRect){
100,
200,
200,
100}];
view
.backgroundColor = [
UIColor redColor];
view;
})];
例子2
[self
.tabBar addSubview:({
TabBar *tabBar = [[TabBar alloc] init]
tabBar
.frame = self
.tabBar.bounds
tabBar
.delegate = self
self
.TabBar = tabBar
})]
注释:通常我们是先创建一个视图再将这个视图添加到父类视图中,而上述的方法就是直接将要添加到父类的视图放在”({})”代码块中