Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create programmatically an UILabel

Tags:

iphone

label

I did by code the following:

UILabel  * label = [[UILabel alloc] initWithFrame:CGRectMake(40, 70, 300, 50)];
    label.backgroundColor = [UIColor clearColor];
    label.textAlignment = UITextAlignmentCenter; // UITextAlignmentCenter, UITextAlignmentLeft
    label.textColor=[UIColor whiteColor];
    label.text = @"Telechargez et consultez les catalogues et les tarifs de la gamme Audi au format PDF";
    [self.view addSubview:label];

And it looks like this but I want it to look like this. How to change the label's properties?

like image 833
adrian Avatar asked Sep 15 '11 09:09

adrian


2 Answers

Try this:

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(40, 30, 300, 50)];
    label.backgroundColor = [UIColor clearColor];
    label.textAlignment = NSTextAlignmentCenter;
    label.textColor = [UIColor whiteColor];
    label.numberOfLines = 0;
    label.lineBreakMode = UILineBreakModeWordWrap;
    label.text = @"Telechargez et consultez les catalogues et les tarifs de la gamme Audi au format PDF";
    [self.view addSubview:label];
like image 114
Narayana Avatar answered Sep 21 '22 17:09

Narayana


To show the UILable as your displayed in your image, you need to set the following property of UILabel and also increase the height of your Label.

@property(nonatomic) NSInteger numberOfLines;
@property(nonatomic) UILineBreakMode lineBreakMode;

Should be like as below ..

    UILabel  * label = [[UILabel alloc] initWithFrame:CGRectMake(40, 70, 300, 100)];
     .................................
    label.numberOfLines=0;
    label.lineBreakMode=UILineBreakModeCharacterWrap;
    ............................
like image 32
Jhaliya - Praveen Sharma Avatar answered Sep 20 '22 17:09

Jhaliya - Praveen Sharma