UILabel中心内容

发布于 2024-10-08 12:34:43 字数 655 浏览 5 评论 0原文

这是我的代码:

UILabel *myLabel;
myLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, 300, 480)];
myLabel.lineBreakMode = UILineBreakModeWordWrap;
myLabel.numberOfLines = 2; // 2 lines ; 0 - dynamical number of lines
myLabel.text = @"Please select at least one image category!";
myLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size: 24.0];
myLabel.center = CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/2);
myLabel.backgroundColor = [UIColor clearColor];
[self.view addSubview:myLabel];
[myLabel release];

我想知道是否可以将换行的文本居中,因为它与左侧对齐: 替代文字

Here's my code:

UILabel *myLabel;
myLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, 300, 480)];
myLabel.lineBreakMode = UILineBreakModeWordWrap;
myLabel.numberOfLines = 2; // 2 lines ; 0 - dynamical number of lines
myLabel.text = @"Please select at least one image category!";
myLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size: 24.0];
myLabel.center = CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/2);
myLabel.backgroundColor = [UIColor clearColor];
[self.view addSubview:myLabel];
[myLabel release];

I was wondering if it is possible to center the wrapped text as it is alined to the left side:
alt text

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

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

发布评论

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

评论(3

沙沙粒小 2024-10-15 12:34:43
myLabel.textAlignment=UITextAlignmentCenter;
myLabel.textAlignment=UITextAlignmentCenter;
紫竹語嫣☆ 2024-10-15 12:34:43

UITextAlignmentCenter 是使文本居中的正确方法,但现在已被弃用。 - 查看此问题和答案。

使用NSTextAlignmentCenter 相反:

label.textAlignment = NSTextAlignmentCenter;

这是在评论中提到的,只是让像我这样的新手清楚。

UITextAlignmentCenter was the correct method to center the text, but is now depreciated. - see this question and answer.

Use NSTextAlignmentCenter instead:

label.textAlignment = NSTextAlignmentCenter;

This was mentioned in a comment, just making it clear for rookies like myself.

情愿 2024-10-15 12:34:43

使用此:

myLabel.textAlignment = NSTextAlignmentCenter;

UITextAlignmentCenter 从 iOS 6 开始已弃用!

Use this:

myLabel.textAlignment = NSTextAlignmentCenter;

UITextAlignmentCenter is deprecated from iOS 6!

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