Reputation: 151
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
Reputation: 3901
Use below code:
specialities1.lineBreakMode = UILineBreakModeWordWrap;
specialities1.textAlignment = UITextAlignmentLeft;
Upvotes: 1
Reputation: 4551
specialities1.textAlignment = UITextAlignmentLeft; // UITextAlignmentCenter
Choose what you need, depending on the situation you encounter.
Upvotes: 0