OC 中的 Label函数

首页 / iOS入门教程 / OC 中的 Label函数

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

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,如下所示:

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

来源:LearnFk无涯教程网

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

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

无涯教程网

iOS Tutorial

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

从0开始学架构 -〔李运华〕

Java核心技术面试精讲 -〔杨晓峰〕

iOS开发高手课 -〔戴铭〕

Elasticsearch核心技术与实战 -〔阮一鸣〕

Kafka核心源码解读 -〔胡夕〕

深度学习推荐系统实战 -〔王喆〕

郭东白的架构课 -〔郭东白〕

零基础GPT应用入门课 -〔林健(键盘)〕

PPT设计进阶 · 从基础操作到高级创意 -〔李金宝(Bobbie)〕

好记忆不如烂笔头。留下您的足迹吧 :)