iOS基础(四)——UIButton和UITableView

1、懒加载button

-(UIButton *)button{
    if (!_button) {
        _button = ({
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            [button setTitle:@"内容显示" forState:UIControlStateNormal];
            button.titleLabel.font = [UIFont systemFontOfSize:14];
            [button addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
            button;
        });
    }
    return _button;
}

2、懒加载tableview

-(UITableView *)tableView
{
    if (!_tableView) {
        _tableView = ({
            UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
            tableView.dataSource = self;
            tableView.delegate = self;
            tableView.backgroundColor = [UIColor whiteColor];
            //设置分割线样式
            tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
            //tableview弹跳效果
            tableView.bounces=YES;
            //隐藏滚动条
            tableView.showsVerticalScrollIndicator = NO ;
            //隐藏底部多余分割线
            tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
            tableView ;
        }) ;
    }
    
    return _tableView;
}
原文地址:https://www.cnblogs.com/smileK/p/9554128.html