single line appears as vertical

I have a long text string that I feed into a UILabel for display. The UILabel is dynamically set up to provide sufficient space for the text

        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];

My problem is if text contains only single line then it appears as vertical-center aligned. That alignment is not matching with my respective label in front of it.


使用下面的代码:

specialities1.lineBreakMode = UILineBreakModeWordWrap;
specialities1.textAlignment = UITextAlignmentLeft;

specialities1.textAlignment = UITextAlignmentLeft; // UITextAlignmentCenter

根据你遇到的情况选择你需要的东西。

链接地址: http://www.djcxy.com/p/28258.html

上一篇: AutoEllipsis = true会影响文本的垂直位置

下一篇: 单行显示为垂直