iOS开发笔记--cell最右边显示箭头,字符,自定义分割线
-(UITableViewCell*)tableView:(UITableView*)tableViewcellForRowAtIndexPath:(NSIndexPath*)indexPath
{
staticNSString*CellIdentifier=@"Cell";
UITableViewCell*cell=[tableViewdequeueReusableCellWithIdentifier:
CellIdentifier];
if(0==indexPath.section){
cell=[[[UITableViewCellalloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier]autorelease];
if(0==indexPath.row){
cell.textLabel.text=@"好的";//cell的text内容
UIView*lbl=[[UIViewalloc]init];//定义一个label用于显示cell之间的分割线(未使用系统自带的分割线),也可以用view来画分割线
lbl.frame=CGRectMake(cell.frame.origin.x+10,cell.frame.size.height-5,cell.frame.size.width-20,1);
lbl.backgroundColor=[UIColorlightGrayColor];
[cell.contentViewaddSubview:lbl];
[lblrelease];
}
UILabel*label=[[UILabelalloc]init];//定义一个在cell最右边显示的label
label.text=@"Dark0921";
label.font=[UIFontboldSystemFontOfSize:14];
[labelsizeToFit];
label.backgroundColor=[UIColorclearColor];
if([[[UIDevicecurrentDevice]systemVersion]floatValue]>=7.0){
label.frame=CGRectMake(SCREEN_WIDTH-label.frame.size.width-10,\
12,label.frame.size.width,label.frame.size.height);
}else{
label.frame=CGRectMake(SCREEN_WIDTH-label.frame.size.width-20,\
12,label.frame.size.width,label.frame.size.height);
}
[cell.contentViewaddSubview:label];
label.backgroundColor=[UIColorclearColor];
label.textColor=[UIColorgrayColor];
[labelrelease];
}
elseif(1==indexPath.row){
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;//显示最右边的箭头
cell.textLabel.text=@"添加好友";
}
}
returncell;
}
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。