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

[objc]  view plain copy 在CODE上查看代码片 派生到我的代码片
  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. }  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值