我有一个很长的文字字符串,我将其输入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];
我的问题是,如果文本只包含单行,则它显示为垂直居中对齐。该对齐方式与我前面的标签不匹配。
答案 0 :(得分:1)
使用以下代码:
specialities1.lineBreakMode = UILineBreakModeWordWrap;
specialities1.textAlignment = UITextAlignmentLeft;
答案 1 :(得分:0)
specialities1.textAlignment = UITextAlignmentLeft; // UITextAlignmentCenter
根据您遇到的情况选择您需要的内容。