(十五)UITableViewCell的常见属性

UItableViewCellStyle:windows

typedef NS_ENUM(NSInteger, UITableViewCellStyle) {
    UITableViewCellStyleDefault,	//左边imageView,右边显示textLabel
    UITableViewCellStyleValue1,		// 左边显示imageView,右边显示textLabel与detailTextLabel(横排)
    UITableViewCellStyleValue2,		// 左边显示蓝色的textLabel,右边显示黑色的detailTextLabel
    UITableViewCellStyleSubtitle	// 左边显示imageView,有textLabel和detailTextLabel(竖排)
};

accessoryType属性,右边的指示器(如箭头,指示用户点击后跳转)。缓存

它是枚举类型,一共有5种。spa

typedef NS_ENUM(NSInteger, UITableViewCellAccessoryType) {
    UITableViewCellAccessoryNone,                   // 无
    UITableViewCellAccessoryDisclosureIndicator,    // 向右的指示箭头
    UITableViewCellAccessoryDetailDisclosureButton, // 对号 + 向右的指示箭头
    UITableViewCellAccessoryCheckmark,              // 对号
    UITableViewCellAccessoryDetailButton NS_ENUM_AVAILABLE_IOS(7_0) // 带圈的i标志(iOS7.0开始支持)
};

Tip:访问资源库(Library)文件夹的方法,按住option键选择Finder的菜单能够看到灰色的library选项,点开便可。

Tip:发现Xcode报错头文件被修改,能够经过清理缓存实现,打开Library/Developer/Xcode 删除DerivedData文件夹。code

若是系统自带的样式不够用,还能够本身定义样式,使用accessoryView属性,能够本身加入控件,例如加入一个开关。图片

Tip:常常打开的文件夹能够制做替身(alias,相似于windows快捷方式)来快速访问。ip

cell.accessoryView = [[UISwitch alloc] init];

Tip:有固定尺寸的控件是没法修改固定的尺寸的。

backgroundView与selectedbackgroundView能够设定普通和点选的样式。也能够使用backgroundColor设置,可是前者优先级高。资源

设定颜色:it

UIView *bgView = [[UIView alloc] init];
bgView.backgroundColor = [UIColor grayColor];
cell.backgroundView = bgView;
    
UIView *bgViewSelceted = [[UIView alloc] init];
bgViewSelceted.backgroundColor = [UIColor brownColor];
cell.selectedBackgroundView = bgViewSelceted;

注意一个细节,UIView必须建立两次,若是只建立一个,在对选中的背景色设置前更换backgroundColor,会使得第一个设置失效

也能够直接设定图片,backgrounView能够接受任何类型的UIView,所以也能够接收UIImageView。io

Tip:系统会自动填充,不用将背景设置尺寸。尽可能使用backgroundView而不是Color。table

相关文章
相关标签/搜索