UILabel中心内容 [英] UILabel Center contents

查看:136
本文介绍了UILabel中心内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:

  UILabel * myLabel; 
myLabel = [[UILabel alloc] initWithFrame:CGRectMake(20,0,300,480)];
myLabel.lineBreakMode = UILineBreakModeWordWrap;
myLabel.numberOfLines = 2; // 2行; 0 - 动态行数
myLabel.text = @请选择至少一个图像类别!;
myLabel.font = [UIFont fontWithName:@Arial-BoldMT大小: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];

我想知道是否可以将包装好的文本居中,因为它是左侧的:

解决方案

  myLabel.textAlignment = UITextAlignmentCenter; 


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:

解决方案

myLabel.textAlignment=UITextAlignmentCenter;

这篇关于UILabel中心内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆