一种新的表达

  self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:({
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake(0, 0, 50, 40);
        [btn setTitle:@"下一步" forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
        btn;
    })];

在一个demo中看到的这种写法,很整洁,感觉很舒服,很多地方都可以用。
再举个例子:

self.tableView.tableHeaderView = ({
            UILabel *label = [[UILabel alloc] init];
            label.frame = CGRectMake(0, 0, CGRectGetWidth(self.view.frame), 900);
            label.text = @"This\nis\na\ntable\nheader\nview\nit\nis\nvery\nhigh!!!";
            label.textColor = [UIColor blackColor];
            label.font = [UIFont systemFontOfSize:14];
            label.textAlignment = NSTextAlignmentCenter;
            label.backgroundColor = [UIColor lightGrayColor];
            label.numberOfLines = 0;
            label;
        });

我以后应该会大量采用这种写法

你可能感兴趣的:(iOS)