Utilisation des libellés
Les libellés sont utilisés pour afficher du contenu statique, y compris une seule ligne ou plusieurs lignes.
Propriétés importantes
- textAlignment
- textColor
- text
- numberOflines
- lineBreakMode
Ajouter une méthode personnalisée addLabel
-(void)addLabel{
UILabel *aLabel = [[UILabel alloc]initWithFrame:
CGRectMake(20, 200, 280, 80)];
aLabel.numberOfLines = 0;
aLabel.textColor = [UIColor blueColor];
aLabel.backgroundColor = [UIColor clearColor];
aLabel.textAlignment = UITextAlignmentCenter;
aLabel.text = @"This is a sample text\n of multiple lines.
here number of lines is not limited.";
[self.view addSubview:aLabel];
}
Mettez à jour viewDidLoad dans ViewController.m comme suit :
- (void)viewDidLoad
{
[super viewDidLoad];
//The custom method to create our label is called
[self addLabel];
// Do any additional setup after loading the view, typically from a nib.
}
Sortie
Exécutez l'application, et vous obtiendrez la sortie suivante :
