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;

}

发布了15 篇原创文章 · 获赞 2 · 访问量 4万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章