iOS开发笔记--cell最右边显示箭头,字符,自定义分割线
2016-05-03 16:52
453 查看
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
CellIdentifier];
if (0 == indexPath.section) {
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier] autorelease];
if (0 == indexPath.row) {
cell.textLabel.text = @"好的"; //cell的text内容
UIView *lbl = [[UIView alloc] init]; //定义一个label用于显示cell之间的分割线(未使用系统自带的分割线),也可以用view来画分割线
lbl.frame = CGRectMake(cell.frame.origin.x + 10, cell.frame.size.height - 5, cell.frame.size.width - 20, 1);
lbl.backgroundColor = [UIColor lightGrayColor];
[cell.contentView addSubview:lbl];
[lbl release];
}
UILabel *label = [[UILabel alloc] init]; //定义一个在cell最右边显示的label
label.text = @"Dark0921";
label.font = [UIFont boldSystemFontOfSize:14];
[label sizeToFit];
label.backgroundColor = [UIColor clearColor];
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
label.frame =CGRectMake(SCREEN_WIDTH - label.frame.size.width - 10,\
12, label.frame.size.width, label.frame.size.height);
} else {
label.frame =CGRectMake(SCREEN_WIDTH - label.frame.size.width - 20,\
12, label.frame.size.width, label.frame.size.height);
}
[cell.contentView addSubview:label];
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor grayColor];
[label release];
}
else if (1 == indexPath.row){
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; //显示最右边的箭头
cell.textLabel.text = @"添加好友";
}
}
return cell;
}
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
CellIdentifier];
if (0 == indexPath.section) {
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier] autorelease];
if (0 == indexPath.row) {
cell.textLabel.text = @"好的"; //cell的text内容
UIView *lbl = [[UIView alloc] init]; //定义一个label用于显示cell之间的分割线(未使用系统自带的分割线),也可以用view来画分割线
lbl.frame = CGRectMake(cell.frame.origin.x + 10, cell.frame.size.height - 5, cell.frame.size.width - 20, 1);
lbl.backgroundColor = [UIColor lightGrayColor];
[cell.contentView addSubview:lbl];
[lbl release];
}
UILabel *label = [[UILabel alloc] init]; //定义一个在cell最右边显示的label
label.text = @"Dark0921";
label.font = [UIFont boldSystemFontOfSize:14];
[label sizeToFit];
label.backgroundColor = [UIColor clearColor];
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
label.frame =CGRectMake(SCREEN_WIDTH - label.frame.size.width - 10,\
12, label.frame.size.width, label.frame.size.height);
} else {
label.frame =CGRectMake(SCREEN_WIDTH - label.frame.size.width - 20,\
12, label.frame.size.width, label.frame.size.height);
}
[cell.contentView addSubview:label];
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor grayColor];
[label release];
}
else if (1 == indexPath.row){
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; //显示最右边的箭头
cell.textLabel.text = @"添加好友";
}
}
return cell;
}
相关文章推荐
- 如何成为一名专家级的开发人员
- gitinspector+jenkins 开发代码统计CI
- .NET微信公众号开发之公众号消息处理
- Node.js开发者必须了解的4个JS要点
- 使用nodejs开发cli项目实例
- 谷歌Chrome浏览器扩展程序开发小记
- nodejs开发微博实例
- Egret引擎开发指南之创建项目
- Android开发自学笔记(二):工程文件剖析
- Java开发人员需知的十大戒律
- Web 开发常用工具 大家自己查找下载
- 三种Web开发主流技术的性价评价
- 在B/S开发中经常用到的JavaScript技术第1/3页
- 深入Android开发FAQ的详解
- Android生存指南之:开发中的注意事项
- asp.net 开发的一些常用技巧
- windows开发记事本程序纪实(二)逻辑篇1
- C#开发纽曼USB来电小秘书客户端总结
- node.js调用C++开发的模块实例
- 在EditPlus中配置Perl开发编译环境