views:

153

answers:

2

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?

+2  A: 

You can set

[descriptionLabel setTextAlignment:UITextAlignmentLeft];

or if you prefer dot syntax

descriptionLabel.textAlignment = UITextAlignmentLeft;

prendio2
Unfortunately, the text still appears in the middle after making these changes.
Sheehan Alam
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
A: 

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

for more fine tuning you can override drawTextInRect:

Meltemi