- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section == 0) {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kTableViewCell];
if (indexPath.row == 0) {
cell.textLabel.text = @"新浪微博"; //cell的text内容
UIView *lbl = [[UIView alloc] 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 = [UIColor lightGrayColor];
[cell.contentView addSubview:lbl];
}
UILabel *label = [[UILabel alloc] init]; //定义一个在cell最右边显示的label
label.text = @"Dark0921";
label.font = [UIFont boldSystemFontOfSize:14];
[label sizeToFit];
label.backgroundColor = [UIColor clearColor];
label.frame =CGRectMake(375 -label.frame.size.width - 10, 12, label.frame.size.width, label.frame.size.height);
[cell.contentView addSubview:label];
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor grayColor];
return cell;
} else{
UITableViewCell *cell1 = [tableView dequeueReusableCellWithIdentifier:kTableViewCell1];
cell1.accessoryType = UITableViewCellAccessoryDisclosureIndicator; //显示最右边的箭头
cell1.textLabel.text = @"添加好友";
return cell1;
}
}
实现后的效果: