user1986984
user1986984

Reputation: 151

single line appears as vertical-center aligned

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.

Upvotes: 0

Views: 96

Answers (2)

Sumit Mundra
Sumit Mundra

Reputation: 3901

Use below code:

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

Upvotes: 1

Dani Pralea
Dani Pralea

Reputation: 4551

specialities1.textAlignment = UITextAlignmentLeft; // UITextAlignmentCenter

Choose what you need, depending on the situation you encounter.

Upvotes: 0

Related Questions