0

I have a UILabel:

    descriptionLabel = [[UILabel alloc] initWithFrame:CGRectMake(200, 30, 130, 150)];
    [descriptionLabel setFont:[Utils getSystemFontWithSize:14]];
    [descriptionLabel setBackgroundColor:[UIColor clearColor]];
    [descriptionLabel setTextColor:[UIColor whiteColor]];
    descriptionLabel.numberOfLines = 0;
    descriptionLabel.lineBreakMode = UILineBreakModeWordWrap;
    [self addSubview:descriptionLabel];

If the text is only 1 line long it will appear in the middle of the label.

Is there anyway I can have the text display from the top left corner of the label instead of the middle center?

Sheehan Alam
  • 60,111
  • 124
  • 355
  • 556

2 Answers2

2

You can set

[descriptionLabel setTextAlignment:UITextAlignmentLeft];

or if you prefer dot syntax

descriptionLabel.textAlignment = UITextAlignmentLeft;

prendio2
  • 1,885
  • 17
  • 25
  • Unfortunately, the text still appears in the middle after making these changes. – Sheehan Alam Apr 21 '10 at 17:51
  • 1
    Do you mean vertically in the middle? It is left-aligned though yeah? You could set the height of your label after calculating with NSString's sizeWithFont method — more details: http://stackoverflow.com/questions/455553/what-is-nsstring-sizewithfontforwidthlinebreakmode-good-for – prendio2 Apr 21 '10 at 17:56
0

for left/right alignment set the textAlignment property of UILabel to either UITextAlignmentLeft or UITextAlignmentRight.

for more fine tuning you can override drawTextInRect:

Meltemi
  • 37,979
  • 50
  • 195
  • 293