将 UILabel 添加到 UITableView - iphone

发布于 11-27 13:00 字数 781 浏览 1 评论 0原文

我是一个iOS开发新手。我有一个设置屏幕,它是 UITableView。我想添加一些解释。我正在使用以下代码来执行此操作,但它完全扭曲了文本。知道我做错了什么吗?

UILabel *subjectLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,0, 300, 175)];
subjectLabel.font = [UIFont systemFontOfSize:16.0];
subjectLabel.numberOfLines = 0;
subjectLabel.font = [UIFont fontWithName:@"Arial Rounded MT Bold" size:(10.0)];
subjectLabel.backgroundColor = [UIColor clearColor];
//bodyLabel.textAlignment = UITextAlignmentLeft;   
subjectLabel.text = @"mytext";

settingTableView = [[[UITableView alloc] initWithFrame:CGRectMake(0,0,  320, 370) style:UITableViewStyleGrouped] autorelease]; 
settingTableView.dataSource = self;
settingTableView.delegate = self;
[settingTableView addSubview:subjectLabel];
[self.view addSubview:settingTableView];

I am an iOS development newbie. I have a settings screen which is a UITableView. I want to add some explanation to it. I am using the following code to do it, but it skews up the text completely. Any idea what I am doing wrong?

UILabel *subjectLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,0, 300, 175)];
subjectLabel.font = [UIFont systemFontOfSize:16.0];
subjectLabel.numberOfLines = 0;
subjectLabel.font = [UIFont fontWithName:@"Arial Rounded MT Bold" size:(10.0)];
subjectLabel.backgroundColor = [UIColor clearColor];
//bodyLabel.textAlignment = UITextAlignmentLeft;   
subjectLabel.text = @"mytext";

settingTableView = [[[UITableView alloc] initWithFrame:CGRectMake(0,0,  320, 370) style:UITableViewStyleGrouped] autorelease]; 
settingTableView.dataSource = self;
settingTableView.delegate = self;
[settingTableView addSubview:subjectLabel];
[self.view addSubview:settingTableView];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦年海沫深2024-12-04 13:00:20

建议1:您可以创建一个包含 UILabel 的单独视图,并将其放置在 UITableView 上方,并将 tableView y 位置放置在 UIView 的高度处。

备注:这很有用,因为当您滚动 tableView 时,默认标题将粘在顶部。

建议2:您可以使用 viewForHeaderInSection 委托方法。您可以在其中创建视图并添加 UILabel。 viewForHeaderInSection 返回 UIView,您可以返回包含 UILabel 的视图

备注:当您滚动 tableView 时,默认标题将随着 tableView 一起移动

Suggestion1 : You could have create a separate view which contains your UILabel and place above the UITableView and place your tableView y position would be from the height of the UIView.

Remark : This is useful because when you scroll the tableView the default header will be stick to top.

Suggestion2 : you can use viewForHeaderInSection delegate method. where you can create a view and add the UILabel. viewForHeaderInSection returns the UIView, which you can return your view which contains the UILabel

Remark : when you scroll the tableView the default header will move along with your tableView

枕梦2024-12-04 13:00:19

tableViewHeader 是一个 UIView,它被设置为 tableView 的 tableViewHeader 属性。如果您想在标题视图中使用 UILabel,请创建一个单独的 UIView (在代码中或在笔尖中),并将其设置为 tableView .tableHeaderView 属性。更多信息可以在这里找到: TableView 参考< /a>.希望有帮助!

A tableViewHeader is a UIView which is set as the tableViewHeader property of a tableView. If you want to have a UILabel in a header view, make a separate UIView (either in code, or in a nib), and set it as the tableView.tableHeaderView property. More information can be found here: TableView Reference. Hope that helps!

吻安2024-12-04 13:00:19

在视图控制器中创建一个视图,并将标签添加到其中并绑定它...

IBOutlet UIView *headerView1;

并添加此代码

settingTableView.tableHeaderView = headerView1;

create a view in your view controller and add your lable to that and bind it ...

IBOutlet UIView *headerView1;

and add this code

settingTableView.tableHeaderView = headerView1;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文