标签用于显示静态内容,该内容由单行或多行组成。

Label - 重要属性

  • textAlignment
  • textColor
  • text
  • numberOflines
  • lineBreakMode

Label - 自定义方法

-(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];
}

更新ViewController.m中的viewDidLoad,如下所示:

- (void)viewDidLoad {
   [super viewDidLoad];
   
   //创建我们的标签的自定义方法称为
   [self addLabel];
   //Do any additional setup after loading the view, typically from a nib.
}

当无涯教程运行应用程序时,无涯教程将获得以下输出-

iOS Tutorial

参考链接

https://www.learnfk.com/ios/ios-ui-elements-labels.html