UILabel

作者: 79d12e22ec53 | 来源:发表于2019-04-24 18:01 被阅读0次

    UIKit常用控件

    UILabel

    UILabel 不同样式

    UiButtonType: .system
    .contactAdd
    .detailDisclosure
    .infoDark
    .infoLight
    .roundedRect

    UILabel 按钮状态

    UIControlState.normal 正常
    UIControlState.hightlighted 高亮
    UIControlState.disabled 禁用
    UIControlState.selected 选中
    UIControlState.focused 焦点
    UIControlState.application 应用程序使用的附加状态
    UIControlState.reserved 保留为内部框架使用

    UIButton 按钮事件响应

    button.addTarget(self, action: , for: .UIController.Events.touchUpInside)

    UIlabel 标签控件

    //label 常用设置
    label.text
    label.textColor
    label.backgroundColor 
    label.textAlignment = NSTextAlignment.right
    label.shadowColor
    label.shadowOffset
    label.font=UIFont.systemFont(ofSize: 20)//一般方法
    label.font=UIFont.boldSystemFont(ofSize: 20)//加粗方法
    label.font=UIFont.init(name:"Avenir-Oblique", size: 20)////指定字体的方法
    
    

    长文本换行

    label.text = 
    label.numberOfLines = 0
    lable.lineBreakMode = NSLineBreakMode.byTruncatingTail //结尾以。。。省略
    

    ​ UILabel 的NSLineBreakMode样式列表

    byWordWrapping 换行发生在单词边界上
    byCharWrapping 换行发生在到达标签的第一个字符前
    byClipping 超过容器边界的文本行内容不会被绘制
    byTruncatingHead 在行首剪切,并以。。表示被剪切文字
    byTruncatingTail 在行尾剪切,并以。。表示被剪切文字
    byTruncatingMiddle 在行中剪切,并以。。表示被剪切文字

    标签文字样式的自定义

    ss富文本的简单实现

    import UIKit
    
    class ViewController: UIViewController {
        
        override func viewDidLoad() {
            super.viewDidLoad()
            
            self.view.backgroundColor = UIColor.lightGray
            
            let attributedText = NSMutableAttributedString(string: "hanyueminhaoshuai.com")
            attributedText.addAttribute(NSAttributedString.Key.font, value: UIFont.boldSystemFont(ofSize: 48), range: NSMakeRange(0, 4))
            attributedText.addAttribute(NSAttributedString.Key.foregroundColor, value: UIColor.purple, range: NSMakeRange(4, 7))
            attributedText.addAttribute(NSAttributedString.Key.backgroundColor, value: UIColor.orange, range: NSMakeRange(11, 3))
    
            let label = UILabel(frame: CGRect(x: 20, y: 100, width: 280, height: 60))
            label.attributedText = attributedText
            self.view.addSubview(label)
    
        }
        
    }
    
    

    相关文章

      网友评论

          本文标题:UILabel

          本文链接:https://www.haomeiwen.com/subject/qchngqtx.html