UILabel multiple attributes, UILabel strikethrough text



letstyle1: [String:Any] = [NSForegroundColorAttributeName:UIColor.darkGray,NSFontAttributeName:UIFont.systemFont(ofSize:12),NSStrikethroughStyleAttributeName:NSUnderlineStyle.styleSingle.rawValue,NSStrikethroughColorAttributeName:UIColor.cyan]
       
     
let style2: [String: Any] = [NSForegroundColorAttributeName: UIColor.red, NSFontAttributeName: UIFont(name: "Georgia", size: 25.0)!]
     
     
let style3: [String: Any] = [NSForegroundColorAttributeName: UIColor.blue, NSBackgroundColorAttributeName: UIColor.yellow, NSFontAttributeName: UIFont.boldSystemFont(ofSize: 13), NSUnderlineStyleAttributeName : NSUnderlineStyle.styleSingle.rawValue]
     
     
let style1Text = "회색 12폰트 취소선 cyan"
     
let style2Text = "빨간색 25폰트 폰트지정"
     
let style3Text = "파란색 13폰트 볼드 밑줄 배경 노랑"
     
     
let style1String = NSMutableAttributedString(string: style1Text, attributes: style1)
     
let style2String = NSMutableAttributedString(string: style2Text, attributes: style2)
     
let style3String = NSMutableAttributedString(string: style3Text, attributes: style3)
     
       style1String.
append(style2String)
       style1String.
append(style3String)
     

        lblMultiFontStyle.attributedText = style1String












/**
 * swift 2.x
let style1: [String : AnyObject] = [
                    NSForegroundColorAttributeName: UIColor.darkGrayColor(),
                    NSFontAttributeName: UIFont.systemFontOfSize(12),
                    NSStrikethroughStyleAttributeName: NSUnderlineStyle.StyleSingle.rawValue]
                let style2: [String : AnyObject] = [
                    NSForegroundColorAttributeName: UIColor.blackColor(),
                    NSFontAttributeName: UIFont.systemFontOfSize(12)]
                let style3: [String : AnyObject] = [
                    NSForegroundColorAttributeName: ColorUtil.hexStringToUIColor("#AF0A2B"),
                    NSFontAttributeName: UIFont.boldSystemFontOfSize(13)]

                let style1Text = "첫번째 12폰트 취소선 회색"
                let style2Text  = "두번째 12폰트 검은색"
                let style3Text = "세번째 볼드 13폰트 컬러 : AF0A2B"

                let style1String = NSMutableAttributedString(string: style1Text, attributes: style1)
                let style2String = NSMutableAttributedString(string: style2Text, attributes: style2)
                let style3String = NSMutableAttributedString(string: style3Text, attributes: style3)

                style1String.appendAttributedString(style2String)
                style1String.appendAttributedString(style3String)
                lblMultiFontStyle.attributedText = style1String
*/


사용자 삽입 이미지

전체소스 : multiFontStye.zip

Posted by incree

2017/01/24 21:13 2017/01/24 21:13
, ,
Response
0 Trackbacks , 0 Comments
RSS :
http://www.incree.com/tc/incree/rss/response/374

Trackback URL : 이 글에는 트랙백을 보낼 수 없습니다

« Previous : 1 : ... 3 : 4 : 5 : 6 : 7 : 8 : 9 : 10 : 11 : ... 130 : Next »

Notices

Archives

Authors

  1. incree

Recent Trackbacks

Calendar

«   2017/04   »
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30            

Site Stats

Total hits:
400066
Today:
52
Yesterday:
183