在单元格样式值为1的表视图中,在文本标签中,我显示日期&时间详细地,文本标签I显示**Title:-Comments**
,
所有标题和评论的长度都不一样。
[在此输入图像描述][1]现在我需要用一种颜色显示标题,用另一种颜色和字体显示字体和注释我需要做什么
创建单元格时,您需要在文本标签中设置所需的所有属性:
-(UITableViewCell *)tableView:(UITableView *)_tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath {
static NSString *kCellId = @"CellId";
UITableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:kCellId];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellId];
cell.accessoryType = UITableViewCellAccessoryNone;
cell.textLabel.font = [UIFont fontWithName:@"CenturyGothic-Bold" size:17];
cell.textLabel.textColor = [UIColor colorWithRed:53/255.0 green:55/255.0 blue:53/255.0 alpha:1];
cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame];
cell.selectedBackgroundView.backgroundColor = [UIColor colorWithRed:(73/255.0) green:(14/255.0) blue:(111/255.0) alpha:1];
}
id obj = [filteredList objectAtIndex:indexPath.row];
cell.textLabel.text = [obj valueForKey:@"title"];
return cell;
}
有两种方法可以解决这个问题。
您可以创建一个自定义的UITableViewCell
,并布局三个独立的UILabel
实例,根据自己的喜好进行样式设置;或者,您可以创建一个自定义的UITableViewCell
,并使用一个允许使用NSAttributedString
的UILabel
的插件替换。第一种解决方案将更加简单明了。