UITableViewCell的各种功能

-(UITableViewCell*)customCellWithOutXib:(UITableView *)tableView withIndexPath:(NSIndexPath*)indexPath{   

//定义标识符

static NSString*customCellIndentifier = @"CustomCellIndentifier";

  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:customCellIndentifier]; 

//定义新的cell 

 if(cell == nil){

//使用默认的UITableViewCell,但是不使用默认的imagetext,改为添加自定义的控件      

cell = [[UITableViewCell  alloc] initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:customCellIndentifier]; 

//姓名

CGRect nameRect = CGRectMake(88, 15, 70,25);        UILabel *nameLabel =[[UILabel alloc]initWithFrame:nameRect];       nameLabel.font = [UIFont boldSystemFontOfSize:nameFontSize];        nameLabel.tag = nameTag;//设置tag,以便后面的定位

nameLabel.textColor = [UIColorbrownColor];        [cell.contentViewaddSubview:nameLabel];                //班级

 CGRect classTipRect = CGRectMake(88, 40, 40, 14);        UILabel *classTipLabel = [[UILabelalloc]initWithFrame:classTipRect];       classTipLabel.text = @"班级:";        classTipLabel.font = [UIFontboldSystemFontOfSize:fontSize];       [cell.contentView addSubview:classTipLabel];                        CGRect classRect =CGRectMake(135, 40, 40, 14);       UILabel *classLabel = [[UILabel alloc]initWithFrame:classRect];        classLabel.tag = classTag;       

classLabel.font = [UIFontboldSystemFontOfSize:fontSize];       [cell.contentView addSubview:classLabel];

                //学号       

CGRect stuNameTipRect = CGRectMake(88, 60,40, 12);        UILabel *stuNameTipLabel= [[UILabel alloc]initWithFrame:stuNameTipRect];        stuNameTipLabel.text = @"学号:";        stuNameTipLabel.font = [UIFontboldSystemFontOfSize:fontSize];       [cell.contentView addSubview:stuNameTipLabel];                CGRect stuNameRect =CGRectMake(135, 60, 150, 14);       UILabel *stuNameLabel = [[UILabel alloc]initWithFrame:stuNameRect];        stuNameLabel.tag = stuNumberTag;        stuNameLabel.font = [UIFontboldSystemFontOfSize:fontSize];               [cell.contentView addSubview:stuNameLabel];  

//图片      

 CGRect imageRect = CGRectMake(15, 15, 60,60);        UIImageView *imageView =[[UIImageView alloc]initWithFrame:imageRect];        imageView.tag = imageTag;               

//为图片添加边框       

CALayer *layer = [imageView layer];        layer.cornerRadius = 8;//角的弧度        layer.borderColor = [[UIColorwhiteColor]CGColor];       layer.borderWidth = 1;//边框宽度       layer.masksToBounds = YES;//图片填充边框       [cell.contentView addSubview:imageView];

  }   

//获得行数   

NSUInteger row = [indexPath row];      

 //取得相应行数的数据(NSDictionary类型,包括姓名、班级、学号、图片名称)  

 NSDictionary *dic = [_stuArrayobjectAtIndex:row];        //设置图片  

 UIImageView *imageV = (UIImageView *) [cell.contentViewviewWithTag:imageTag];    imageV.image =[UIImage imageNamed:[dic objectForKey:@"image"]];       

 

//设置姓名   

UILabel *name = (UILabel*)[cell.contentView viewWithTag:nameTag];   

name.text = [dicobjectForKey:@"name"];       

//设置班级   

UILabel *class = (UILabel*)[cell.contentView viewWithTag:classTag];   

class.text = [dicobjectForKey:@"class"];      

 //设置学号   

UILabel *stuNumber = (UILabel*)[cell.contentView viewWithTag:stuNumberTag];   

stuNumber.text = [dicobjectForKey:@"stuNumber"];       //设置右侧箭头   

cell.accessoryType =UITableViewCellAccessoryDisclosureIndicator;   return cell;

}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值