iOS开发笔记--cell最右边显示箭头,字符,自定义分割线

本文介绍如何在 iOS 开发中使用 UITableView 并自定义 UITableViewCell 的样式,包括设置文本、添加辅助视图以及绘制分割线等操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  1. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath  

  2. {  

  3.     static NSString *CellIdentifier = @"Cell";  

  4.     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:  

  5.                              CellIdentifier];  

  6.       

  7.     if (0 == indexPath.section) {  

  8.         cell = [[[UITableViewCell alloc]  

  9.                 initWithStyle:UITableViewCellStyleDefault  

  10.                 reuseIdentifier:CellIdentifier] autorelease];  

  11.         if (0 == indexPath.row) {  

  12.                 cell.textLabel.text = @"好的"//cell的text内容  

  13.                 UIView *lbl = [[UIView alloc] init]; //定义一个label用于显示cell之间的分割线(未使用系统自带的分割线),也可以用view来画分割线  

  14.                 lbl.frame = CGRectMake(cell.frame.origin.x + 10, cell.frame.size.height - 5, cell.frame.size.width - 201);  

  15.                 lbl.backgroundColor =  [UIColor lightGrayColor];  

  16.                 [cell.contentView addSubview:lbl];  

  17.                 [lbl release];  

  18.             }  

  19.             UILabel *label = [[UILabel alloc] init]; //定义一个在cell最右边显示的label  

  20.             label.text = @"Dark0921";  

  21.             label.font = [UIFont boldSystemFontOfSize:14];  

  22.             [label sizeToFit];  

  23.             label.backgroundColor = [UIColor clearColor];  

  24.             if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {  

  25.                 label.frame =CGRectMake(SCREEN_WIDTH - label.frame.size.width - 10,\  

  26.                                         12, label.frame.size.width, label.frame.size.height);  

  27.             } else {  

  28.                 label.frame =CGRectMake(SCREEN_WIDTH - label.frame.size.width - 20,\  

  29.                                         12, label.frame.size.width, label.frame.size.height);  

  30.             }  

  31.             [cell.contentView addSubview:label];  

  32.             label.backgroundColor = [UIColor clearColor];  

  33.             label.textColor = [UIColor grayColor];  

  34.             [label release];  

  35.         }  

  36.         else if (1 == indexPath.row){  

  37.             cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; //显示最右边的箭头  

  38.             cell.textLabel.text = @"添加好友";  

  39.         }     

  40.     }  

  41.     return cell;  

  42. }  











本文转自 卓行天下  51CTO博客,原文链接:http://blog.51cto.com/9951038/1769777,如需转载请自行联系原作者
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值