IOS UITableViewCell样式

来源:互联网 发布:周期表中原子半径数据 编辑:程序博客网 时间:2024/06/08 05:45

IOS UI阶段学习 UITableView样式  UITableViewCell样式的图示    

首先奉上一个通过plist文件的方式,高效,方便快捷的创建不同样式cell 的方法

当我们需要定义不同类型的cell的时候,如果通过纯代码创建,可能任务量会比较大,而且效率不高,所以我举一个开发中常用到的 方法

  1.首先,我们自定义一个Cell  继承自UITableViewCell  在里面封装好那些基础的东西.这些就不说了.....我在这里直接给大家呈上我今天所说的这段重点代码了

这个plist文件中的一个数组 保存的着若干个字典  (每个字典其实是包含若干个同类型的自定义cell ,添加一个键值对,指定一个cell样式的类型)

+ (UITableViewCellStyle)cellStyleWithDict:(NSDictionary *)dict

{

    UITableViewCellStyle cellStyle = UITableViewCellStyleDefault;

    

    if ([dict[@"cellStyle"isEqualToString:@"UITableViewCellStyleSubtitle"]) {

        cellStyle = UITableViewCellStyleSubtitle;

    } else if ([dict[@"cellStyle"isEqualToString:@"UITableViewCellStyleValue1"]) {

        cellStyle = UITableViewCellStyleValue1;

    } else  if ([dict[@"cellStyle"isEqualToString:@"UITableViewCellStyleValue2"]) {

        cellStyle = UITableViewCellStyleValue2;

    }

    return cellStyle;

}



相信大家看到这块代码后就能想到了点什么.....   接着 在其他控制器中创建 自定义cell的时候,调用这个类方法,传入plist文件中对象的字典中的  键值,是不是就能创建出该样式的cell.

下面呈现出 UITableViewCell样式及图示

UITableView样式有两种

1.UITableViewStylePlain:

Plain样式的是方形的,充满你给的view.frame坐标。

2.2.UITableViewStyleGrouped:


Grouped样式主要是以圆角形显示。跟iphone自带的通讯录编辑页面类似。

二、系统自己的UITableViewCell样式有四种:

1.UITableViewCellStyleDefault:

Default样式:左边一个显示图片的imageView,一个标题textLabel,没有detailTextLabel。

2.UITableViewCellStyleSubtitle:

Subtitle样式:左边一个显示图片的imageView,上边一个主标题textLabel,一个副标题detailTextLabel。主标题字体大且加黑,副标题字体小在主标题下边。

3.UITableViewCellStyleValue1:

Value1样式:左边一个显示图片的imageView,左边一个主标题textLabel,右边一个副标题detailTextLabel,主标题字体比较黑。


4.UITableViewCellStyleValue2:

Value2样式:左边一个主标题textLabel字体偏小,挨着右边一个副标题detailTextLabel,字体大且加黑。


 样式图示 部分  转至  http://blog.csdn.net/crazyzhang1990/article/details/12503163



    


1 0
原创粉丝点击