如何在 XCode 中将标签文本居中

发布于 2024-09-05 09:49:08 字数 46 浏览 0 评论 0原文

我有一个带有两个标签的单元格。如何以编程方式居中对齐顶部标签并隐藏第二个标签?

I have a cell with two labels. How can I programmatically center-align the top label and hide the second label?

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

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

发布评论

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

评论(3

旧街凉风 2024-09-12 09:49:08

UITextAlignmentCenter 已弃用。您应该使用以下内容:

labelOne.textAlignment = NSTextAlignmentCenter;

UITextAlignmentCenter is deprecated. You should use the following:

labelOne.textAlignment = NSTextAlignmentCenter;
我为君王 2024-09-12 09:49:08

[labelOne setTextAlignment:UITextAlignmentCenter]; //将文本置于 UILabel 中居中
[labelTwo setHidden:YES] //存在,但不可见。

[labelOne setTextAlignment:UITextAlignmentCenter]; //to center text in the UILabel
[labelTwo setHidden:YES] //there, but not visible.

雨轻弹 2024-09-12 09:49:08

我认为你想做的是:
像这样的东西..

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    firstLabel.frame = cell.frame; // or reconfigure your frame or some reason(i dont know)
    firstLabel.textAlignment = NSTextAlignmentCenter;
    secondLabel.hidden = YES;
}

您希望第一个标签中的文本位于单元格的中心吗?

I think what you are trying to do is:
Something like this..

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    firstLabel.frame = cell.frame; // or reconfigure your frame or some reason(i dont know)
    firstLabel.textAlignment = NSTextAlignmentCenter;
    secondLabel.hidden = YES;
}

you want you text from the firstLabel to be at the center of the cell?

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