在分组的 tableView 中显示具有不同背景颜色的标签? [英] Displaying labels with different background color in grouped tableView ?
本文介绍了在分组的 tableView 中显示具有不同背景颜色的标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
朋友们好.我需要在 UItableView 中显示标签.我怎样才能做到这一点.请参考截图.
Hi friends. i Need to display the labels in a UItableView. How can i do that. Kindly refer the screenshot.
推荐答案
您可以使用 UITableViewCell 的 UITableViewCellStyleValue1
样式.对节标题使用自定义视图.
You can use the UITableViewCellStyleValue1
style of UITableViewCell. Use Custom view for the section header.
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 22.0f;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UILabel *sectionLabel = [[UILabel alloc]initWithFrame:CGRectZero];
sectionLabel.backgroundColor = [UIColor purpleColor];//Choose your color
sectionLabel.textColor = [UIColor whiteColor];
sectionLabel.font = [UIFont boldSystemFontOfSize:17.0f];
sectionLabel.text = @"Section Name";
return sectionLabel;
}
- (UITableViewCell *)tableView:(UITableView *)TableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
//Default detailTextLabel would have blue text color change it to your choice
cell.detailTextLabel.textColor = [UIColor darkGrayColor];
}
cell.textLabel.text = @"Mobile Number";
cell.detailTextLabel.text = @"Type";
return cell;
}
这篇关于在分组的 tableView 中显示具有不同背景颜色的标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文