无法同时使用Numberoflines和textAlignment

时间:2013-03-15 21:22:06

标签: xcode uilabel

当我第一次创建UIButton时,NSTextAlignment始终是正确的。

label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0,landscapes?450:380, 120)];
label.frame = CGRectMake(0, 0,landscapes?450:380, 120);
label.font = [UIFont fontWithName:@"Futura" size:60];
label.textColor = [UIColor blackColor];
label.backgroundColor = [UIColor clearColor];
label.minimumScaleFactor = 0.2;
label.adjustsFontSizeToFitWidth = true;
label.adjustsLetterSpacingToFitWidth = true;
label.textAlignment = NSTextAlignmentCenter;
NSLog(@"%i",label.textAlignment);
label.text = n;
[self addSubview:label];

但是,每次我输入一个参数为行数

label.numberOfLines = 2;

标签不是文字对齐的。

1 个答案:

答案 0 :(得分:0)

看一下有关垂直对齐的其他stackoverflow帖子。我认为使用带有numberOfLines = 0的sizeToFit,然后指定宽度将帮助您将其水平居中 - Vertically align text to top within a UILabel