标签用于显示静态内容,该内容由单行或多行组成。
-(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. }
当无涯教程运行应用程序时,无涯教程将获得以下输出-
链接:https://www.learnfk.com/ios/ios-ui-elements-labels.html
来源:LearnFk无涯教程网
这一章《OC - UI控件 - Label 函数》你学到了什么?在下面做个笔记吧!做站不易,你的分享是对我们最大的支持
修复 Xcode 9 问题:“iPhone 正忙:为 iPhone 准备调试器支持”
Xcode 9 GM - WKWebView NSCoding 支持在以前的版本中被破坏
'automaticallyAdjustsScrollViewInsets' 在 iOS 11.0 中已弃用