UILabel标签

UILabel基础知识:

UILabel *label1=[[UILabel alloc]initWithFrame:CGRectMake(100, 100, 120, 120)];//创建并设置Frame

    label1.numberOfLines=3;//设置文本最多行数,为0时没有最大行数限制

    label1.textAlignment=NSTextAlignmentCenter;//设置对齐方式

    label1.font=[UIFont systemFontOfSize:30];//设置字体大小

    

  label1.highlighted=YES;文本高亮

    label1.textColor=[UIColor blackColor];//设置字体颜色

    label1.text=@"1234567890123456789";//设置文本

    label1.backgroundColor=[UIColor grayColor];//设置文本框背景色

    

    [self.view addSubview:label1];//提交显示

//文本对齐方式有以下三种:

//typedef enum {

// UITextAlignmentLeft = 0,左对齐

// UITextAlignmentCenter,居中对齐

// UITextAlignmentRight, 右对齐

//} UITextAlignment;

 

//超出label边界文字的截取方式:

label1.lineBreakMode = UILineBreakModeTailTruncation;

//截取方式有以下6种

//typedef enum {

// UILineBreakModeWordWrap = 0, 以空格为边界,保留整个单词

// UILineBreakModeCharacterWrap, 保留整个字符

// UILineBreakModeClip, 到边界为止

// UILineBreakModeHeadTruncation, 省略开始,以……代替

// UILineBreakModeTailTruncation, 省略结尾,以……代替

// UILineBreakModeMiddleTruncation,省略中间,以……代替,多行时作用于最后一行

//} UILineBreakMode;
//文本高亮
label1.highlighted = YES;

//文本是否可变 
label1.enabled = YES;

//去掉label背景色
//label1.backgroundColor = [UIColor clearColor];

//文本阴影颜色
label1.shadowColor = [UIColor grayColor]; 

//阴影大小
label1.shadowOffset = CGSizeMake(1.0, 1.0);

//是否能与用户交互
label1.userInteractionEnabled = YES;

 

 

 

 

原文地址:https://www.cnblogs.com/liuyingjie/p/4966653.html