单行显示为垂直
我有一个很长的文本字符串,我将其输入到UILabel
进行显示。 UILabel
动态设置为文本提供足够的空间
specialities1 =[[UILabel alloc]init];
[specialities1 setFrame:CGRectMake(124,218,size8.width, size8.height)];
specialities1.backgroundColor=[UIColor clearColor];**strong text**
specialities1.lineBreakMode=UILineBreakModeClip;
specialities1.font=[UIFont fontWithName:@"Helvetica-Bold" size:14];
specialities1.text=[NSString stringWithFormat:@"%@ ",temp ];
specialities1.textAlignment=UITextAlignmentRight;
[specialities1 setNumberOfLines:0];
[specialities1 sizeToFit];
[testscroll addSubview:specialities1];
我的问题是如果文本只包含单行,那么它显示为垂直中心对齐。 该对齐与我前面的相应标签不匹配。
使用下面的代码:
specialities1.lineBreakMode = UILineBreakModeWordWrap;
specialities1.textAlignment = UITextAlignmentLeft;
specialities1.textAlignment = UITextAlignmentLeft; // UITextAlignmentCenter
根据你遇到的情况选择你需要的东西。
链接地址: http://www.djcxy.com/p/28257.html上一篇: single line appears as vertical
下一篇: Button with Image and Text vertically aligned using autolayout constraints