zoukankan      html  css  js  c++  java
  • Swift

     let label = UILabel(frame: CGRect(x: 10, y: 20,  300, height: 100))
            label.text = "Hello WorldHello WorldHello WorldHello World"
            label.textColor = UIColor.red;
            label.backgroundColor = UIColor.blue
            label.textAlignment = .right//文字右对齐
            label.shadowColor = UIColor.yellow//黄色阴影
            label.shadowOffset = CGSize( 1.5, height: 1.5)//阴影的偏移量
            label.font = UIFont(name:"Zapfino",size:20)//字体设置
            label.lineBreakMode = .byTruncatingTail//隐藏尾部并显示省略号
            label.adjustsFontSizeToFitWidth = true//当文字超出标签宽度时,自动调整文字大小,使其不被截断
            label.numberOfLines = 0
            label.isHighlighted = true//设置文本高亮
            label.highlightedTextColor = UIColor.green//设置文本高亮颜色
            self.view.addSubview(label)
            
            //富文本设置
            let attributestring = NSMutableAttributedString(string:"welcome to china")
            //从文本0开始6个字符字体HelveticaNeue-Bold,16号
            attributestring.addAttribute(NSAttributedStringKey.font, value: UIFont(name: "HelveticaNeue-Bold", size: 16)!,
                                         range: NSMakeRange(0,6))
            //设置字体颜色
            attributestring.addAttribute(NSAttributedStringKey.foregroundColor, value: UIColor.blue, range: NSMakeRange(0, 3))
            
            //设置文字背景颜色
            attributestring.addAttribute(NSAttributedStringKey.backgroundColor, value: UIColor.green, range: NSMakeRange(3, 3))
            
            label.attributedText = attributestring;
    
  • 相关阅读:
    Java 基础知识总结
    AppScan-文件参数Shell命令注入
    AndroidKiller-下载使用
    代码技巧之常用快捷键的整理
    z-index的特点
    定位元素的异同点
    定位之固定定位
    定位之相对定位
    clear的值和特点及伪元素before和after的使用
    如何让元素消失在我们的视野中(面试题)
  • 原文地址:https://www.cnblogs.com/baidaye/p/8781478.html
Copyright © 2011-2022 走看看