iOS开发中UITableview控件的基本使用及性能优化方法

2020-01-14 17:53:41于海丽

    {
        cell.accessoryView = [[UISwitch alloc] init];
    }
//    UIButton *btn = [[UIButton alloc] init];
//    btn.backgroundColor = [UIColor redColor];
//    cell.accessoryView = btn;
    
    
    // 2.4设置cell的背景颜色
    cell.backgroundColor = [UIColor blueColor];
    
    // 设置默认状态的背景
//    UIView *view = [[UIView alloc] init];
//    view.backgroundColor = [UIColor blueColor];
//    cell.backgroundView = view;
    
    UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"buttondelete"]];
    cell.backgroundView = iv;
    
    // 设置选中状态的背景
    UIView *view2 = [[UIView alloc] init];
    view2.backgroundColor = [UIColor purpleColor];
    cell.selectedBackgroundView = view2;
    // 3.返回cell
    return cell;
}


#pragma mark - 控制状态栏是否显示
/**
 *   返回YES代表隐藏状态栏, NO相反
 */
- (BOOL)prefersStatusBarHidden
{
    return YES;
}
@end


实现效果:

 

iOS开发中UITableview控件的基本使用及性能优化方法

cell的一些属性:

(1)设置cell的辅助视图,设置cell.accessoryView(系统提供了枚举型,也可以自定义@父类指针指向子类对象);

(2)设置cell的背景颜色,有两种方式可以设置cell的背景颜色:

通过backgroundColor 和 backgroundView都可以设置cell的背景。但是backgroundView 的优先级比 backgroundColor的高,所以如果同时设置了backgroundColor和backgroundView, 那么backgroundView会盖住backgroundColor

    示例:cell.backgroundColor = [UIColorblueColor];