Label标签用法
在IOS中 Label(标签)用于显示静态的内容,可以是一个单一的一行或多行。
重要的属性
-
textAlignment
-
textColor
-
text
-
numberOflines
-
lineBreakMode
添加一个自定义的方法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 of multiple lines. here number of lines is not limited."; [self.view addSubview:aLabel]; }
更新在ViewController.m 中方法 viewDidLoad 如下
- (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. }
输出
现在,当我们运行程序时,我们会得到下面的输出