zoukankan      html  css  js  c++  java
  • swift

    1、label的声明

    class FirstyViewController: UIViewController {
        
        var label = UILabel()//初始化
        
        override func viewDidLoad() {

    2、背景颜色和文字颜色的设置及坐标设置

    label.textColor=UIColor.white  //白色文字
    label.backgroundColor=UIColor.black //黑色背景
    label.frame = CGRect(x:10,y:70,300,height:100)//初始化坐标

    3,对齐方式的设置

    label.textAlignment=.right //文字右对齐

    4,文字阴影的设置

    label.shadowColor=UIColor.gray  //灰色阴影
    label.shadowOffset=CGSize(1.5,height:1.5)  //阴影的偏移量

    5,字体的设置

    label.font = UIFont(name:"Zapfino", size:20)

    6,文字过长时的省略方式

    label.lineBreakMode=.byTruncatingTail  //隐藏尾部并显示省略号
    label.lineBreakMode=.byTruncatingMiddle  //隐藏中间部分并显示省略号
    label.lineBreakMode=.byTruncatingHead  //隐藏头部并显示省略号
    label.lineBreakMode=.byClipping  //截去多余部分也不显示省略号

    7,文字大小自适应标签宽度

    label.adjustsFontSizeToFitWidth=true //当文字超出标签宽度时,自动调整文字大小,使其不被截断

    8,使标签可以显示多行文字

    label.numberOfLines=2  //显示两行文字(默认只显示一行,设为0表示没有行数限制)

    9,设置文本高亮

    //设置文本高亮
    label.isHighlighted = true
    //设置文本高亮颜色
    label.highlightedTextColor = UIColor.green

    10,富文本设置

    //富文本设置
    var attributeString = 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
  • 相关阅读:
    google git的使用方法
    C/C++ 开发库 | C/C++ Development Library
    log4cplus c++开源日志系统
    c++配置类
    Markdown基础语法
    Nhibernate 映射关系,一对多 多对一与多对手在映射文件中的体现。
    Nhibernate refers to an unmapped class nhibernate问题的解决(初学者)
    UICollectionView的使用
    Runloop
    UITableView(转)
  • 原文地址:https://www.cnblogs.com/hero11223/p/5690618.html
Copyright © 2011-2022 走看看