iphone - 将标签作为 subview 添加到 UIView

标签 iphone uiview uilabel

任何人都可以告诉我如何为我在 UITableView Cell 上添加的 View 添加两个标签。我已将该 View 创建为具有某个名称的 UIView。并且我已在 UIView 类中创建了两个标签,并为标签设置了框架,设置文本等。我​​的问题是在表格 View 单元格中获取该 View ,而不是那些标签。

    countLabel.text = @"4";
    countLabel.frame=CGRectMake(275, 10, 20, 15);
    countLabel.font=[UIFont boldSystemFontOfSize:15.0];
    countLabel.textColor=[UIColor colorWithWhite:0.0 alpha:0.5];
    countLabel.backgroundColor=[UIColor clearColor];

    hrsLabel.text = @"Hours";
    hrsLabel.frame=CGRectMake(260, 30, 45, 15);
    hrsLabel.font=[UIFont boldSystemFontOfSize:15.0];
    hrsLabel.textColor=[UIColor colorWithWhite:0.0 alpha:0.5];
    hrsLabel.backgroundColor=[UIColor clearColor];

这只是我正在将框架、文本设置为 UIView 中的标签。

GreenView *greenView = [[GreenView alloc] initWithFrame:CGRectMake(250, 8, 60, 50)];
greenView.backgroundColor = [UIColor colorWithRed:0.000 green:0.690 blue:0.313 alpha:0.5];
[cell.contentView addSubview:greenView];

在这里,我将该 UIView 添加到 tableview 单元格中。我不知道如何将这些标签添加到我的 UIView 中。请帮助我。

抱歉,如果有任何英语错误。 请任何人帮助我。 提前非常感谢。

最佳答案

创建 label 和 label1 等标签并添加到 UIView

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 30, 250, 15)];

[label setText:@"Hello"];

UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 50, 250, 15)];

[label1 setText:@"Hello1"];

UIView *myView = [UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)];

[myView addSubview:label];
[myView addSubview:label1];

关于iphone - 将标签作为 subview 添加到 UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12072257/

相关文章:

objective-c - iOS:addObserver 和 superview 查询

swift - Firebase 快照以在 Swift 中标记

objective-c - UILabel字体大小?

iphone - 如何将属性设为私有(private)?

iPhone - 入门

swift - 将一条线分成 n 等份

iphone - UIAnimation 阻止奇怪的行为

ios - 向内部内容大小添加填充在 UILabel 中不起作用

iphone - 创建一个图书馆什么时候变得值得?

iphone - 显示的 NSLog 数组计数代码有什么作用?