以编程方式创建UILabel
问题描述:
我通过以下代码进行了操作:
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?
答
要在图像中显示UILable,您需要设置UILabel ,还可以增加标签的高度.
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;
应如下所示.
UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(40, 70, 300, 100)];
.................................
label.numberOfLines=0;
label.lineBreakMode=UILineBreakModeCharacterWrap;
............................