是否可以将UILabel添加到已经将UIButton作为子视图的UITableView Cell?

时间:2012-10-19 14:33:08

标签: objective-c xcode uitableview

Hii可以将UILabel添加到UITutView Cell,其中UIButton为Subview。我的意思是这个UILabel必须作为DetailLabel添加到UIButton,即Button的标题下面?

E.x我的编码是

    UIButton *button=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, 320, 44)];
    [button setImage:[UIImage imageNamed:@"launchpad.png"]forState:UIControlStateNormal];
    [button setTag:001];
    [button addTarget:self action:@selector(buttonPressed:)forControlEvents:UIControlEventTouchUpInside];
    [cell addSubview:button];

在标题文本下面,我希望标签作为子视图在运行时加载动态文本。

希望我能解释清楚。请帮我编写代码和添加UILabel的方法。

1 个答案:

答案 0 :(得分:0)

您可以将此标签作为子视图添加到UIButton:

UIButton *button=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, 320, 44)];
[button setImage:[UIImage imageNamed:@"launchpad.png"]forState:UIControlStateNormal];
[button setTag:001];
[button addTarget:self action:@selector(buttonPressed:)forControlEvents:UIControlEventTouchUpInside];

UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(0,24, 320, 20)];
label.text = @"Some text"
[button addSubview:label];

[cell addSubview:button];