UILabel中心内容
这是我的代码:
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:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
UITextAlignmentCenter
是使文本居中的正确方法,但现在已被弃用。 - 查看此问题和答案。使用
NSTextAlignmentCenter 相反:
这是在评论中提到的,只是让像我这样的新手清楚。
UITextAlignmentCenter
was the correct method to center the text, but is now depreciated. - see this question and answer.Use
NSTextAlignmentCenter
instead:This was mentioned in a comment, just making it clear for rookies like myself.
使用此:
UITextAlignmentCenter
从 iOS 6 开始已弃用!Use this:
UITextAlignmentCenter
is deprecated from iOS 6!