您的位置:首页 > 产品设计 > UI/UE

iOS-为UITableViewCell添加详情指示图,和说明文字

2016-03-25 10:40 471 查看
一、创建数据源

self.menuArray = [[NSMutableArrayalloc]
initWithCapacity:0];

    NSArray *m1Array =@[@{@"name":@"消息中心",@"icon":@"xxzx",@"ctr":@"CYMessageListViewController"},

                        
@{@"name":@"设置",@"icon":@"set",@"ctr":@"MCSettingViewController"}];

    [self.menuArrayaddObject:m1Array];

二、创建UITableViewCell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
*)indexPath{

   static
NSString *Identifier =@"Cell";
   UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:Identifier];

    [[cell viewWithTag:10]removeFromSuperview];

    [[cell viewWithTag:20]removeFromSuperview];

   if (!cell) {

        cell = [[UITableViewCellalloc]
initWithStyle:UITableViewCellStyleValue1reuseIdentifier:Identifier];

        cell.backgroundColor = [UIColorwhiteColor];
    }

   NSArray *funcArray = 
self.menuArray[indexPath.section];
   NSDictionary *menuDit = funcArray[indexPath.row];
    cell.textLabel.text = menuDit[@"name"];

    cell.textLabel.font = [UIFontsystemFontOfSize:15];
    [cell.imageViewsetImage:[UIImageimageNamed:menuDit[@"icon"]]];

    cell.detailTextLabel.textColor=EHMO_COLOR_TEXT;

    
   UIImageView *accessoryView=[[UIImageViewalloc]initWithFrame:CGRectMake(WIDTH-30,12.5,
20, 20)];
    accessoryView.tag=10;
    accessoryView.image=[UIImageimageNamed:@"btn-more_g@2x"];
    [celladdSubview:accessoryView];

    
   UILabel *detailLabel=[[UILabelalloc]
initWithFrame:CGRectMake(WIDTH-130,2.5,
100, 40)];

    detailLabel.backgroundColor=[UIColorwhiteColor];
    detailLabel.font=[UIFontsystemFontOfSize:13];

    detailLabel.textAlignment=NSTextAlignmentRight;
    detailLabel.textColor=[UIColorgrayColor];
    detailLabel.tag=20;
    [celladdSubview:detailLabel];

    
   return cell;
}

实现效果图:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息