温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

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

发布时间:2020-07-07 03:54:26 来源:网络 阅读:728 作者:卓行天下 栏目:移动开发
  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. }  


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI