iOS - Labels(標簽)
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. }
輸出
現在,當我們運行程序時,我們會得到下麵的輸出