swift中标签的使用
1,标签的创建
 
2,背景颜色和文字颜色的设置
 
3,对齐方式的设置
 
4,文字阴影的设置
 
5,字体的设置
 
6,文字过长时的省略方式
 
7,文字大小自适应标签宽度
 
8,使标签可以显示多行文字
9,设置文本高亮
10,富文本设置
| 1 2 3 4 5 6 7 8 9 10 | importUIKitclassViewController: UIViewController{    overridefuncviewDidLoad() {    super.viewDidLoad()    //设置标签x坐标:10,y坐标:20,长:300,宽:100    varlabel=UILabel(frame:CGRectMake(10,20, 300, 100))    label.text="hangge.com"    self.view.addSubview(label);    }} | 
| 1 2 | label.textColor=UIColor.whiteColor()  //白色文字label.backgroundColor=UIColor.blackColor() //黑色背景 | 
| 1 | label.textAlignment=NSTextAlignment.Right//文字右对齐 | 
| 1 2 | label.shadowColor=UIColor.grayColor()  //灰色阴影label.shadowOffset=CGSizeMake(-5,5)  //阴影的偏移量 | 
| 1 | label.font = UIFont(name:"Zapfino", size:20) | 
| 1 2 3 4 | label.lineBreakMode=NSLineBreakMode.ByTruncatingTail//隐藏尾部并显示省略号label.lineBreakMode=NSLineBreakMode.ByTruncatingMiddle//隐藏中间部分并显示省略号label.lineBreakMode=NSLineBreakMode.ByTruncatingHead//隐藏头部并显示省略号label.lineBreakMode=NSLineBreakMode.ByClipping//截去多余部分也不显示省略号 | 
| 1 | label.adjustsFontSizeToFitWidth=true//当文字超出标签宽度时,自动调整文字大小,使其不被截断 | 
| 1 | label.numberOfLines=2  //显示两行文字(默认只显示一行,设为0表示没有行数限制) | 
9,设置文本高亮
| 1 2 3 4 | //设置文本高亮label.highlighted = true//设置文本高亮颜色label.highlightedTextColor = UIColor.greenColor() | 
10,富文本设置
| 1 2 3 4 5 6 7 8 9 10 11 12 | //富文本设置varattributeString = NSMutableAttributedString(string:"welcome to hangge.com")//从文本0开始6个字符字体HelveticaNeue-Bold,16号attributeString.addAttribute(NSFontAttributeName, value: UIFont(name: "HelveticaNeue-Bold", size: 16)!,    range: NSMakeRange(0,6))//设置字体颜色attributeString.addAttribute(NSForegroundColorAttributeName, value: UIColor.blueColor(),    range: NSMakeRange(0, 3))//设置文字背景颜色attributeString.addAttribute(NSBackgroundColorAttributeName, value: UIColor.greenColor(),    range: NSMakeRange(3,3))label.attributedText = attributeString | 
    我叫无敌小蚂蚱,学名:呆萌程序猿,艺名:炸毛攻城狮
 
                    
                
 
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号