如何使用2个不同颜色的标签制作UITableViewCell? [英] How to make UITableViewCell with 2 labels of different color?

查看:133
本文介绍了如何使用2个不同颜色的标签制作UITableViewCell?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想像这样拥有UITableViewCell:

I would like to have UITableViewCell like this:

电话:的文字颜色必须与电话号码的文字颜色不同。现在我像往常一样将文本设置为单元格:

The text color of "Tel:" must be different from text color of number. Right now i set text to cell as usual:

cell.textLabel.text=@"Something";

是否可以拥有1个标签并更改部分标签的颜色?

Is it possible to have 1 label and change color of some parts of it?

如何在我的照片上制作表格单元?

How can I make table cell like on my picture?

谢谢。

推荐答案

你应该在两个标签和单元格中...并在UITableViewCell的子视图中添加这两个标签

You should have to take two Labels and in Cell...and add this both Label in subview of UITableViewCell

在cellForRowAtIndexPath方法中写这个。

Write this in cellForRowAtIndexPath method.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{

    static NSString *CellIdentifier = @"Cell";  
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

    for(UIView *eachView in [cell subviews])
        [eachView removeFromSuperview];

    //Initialize Label
    UILabel *lbl1 = [[UILabel alloc]initWithFrame:YOURFRAME];
    [lbl1 setFont:[UIFont fontWithName:@"FontName" size:12.0]];
    [lbl1 setTextColor:[UIColor grayColor]];
    lbl1.text = YOUR CELL TEXT;
    [cell addSubview:lbl1];
    [lbl1 release];

    UILabel *lbl2 = [[UILabel alloc]initWithFrame:YOURFRAME];
    [lbl2 setFont:[UIFont fontWithName:@"FontName" size:12.0]];
    [lbl2 setTextColor:[UIColor blackColor]];
    lbl2.text = YOUR CELL TEXT;
    [cel2 addSubview:lbl2];
    [lbl2 release];

    return cell;
}

更新:

除此之外,您还可以创建自定义单元格作为此处

Along with this you can also create Custom cell as define here

快乐编码..

这篇关于如何使用2个不同颜色的标签制作UITableViewCell?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆