2016年10月19日 星期三

swift3 Day5 UIColor textColor

在 swift2 的 UIColor 用法為:



testLabel.textColor = UIColor.redColor()


 



在 swift3 時,不用加後面的 Color()



加了會出 error,直接使用即可,例如要紅色:



testLabel.textColor = UIColor.red



內建顏色有:







當然也可以自己設定顏色:



//alpha是透明度,數字越小越透明



testLabel.textColor = UIColor(red: 1, green: 0, blue: 0, alpha: 1)





黑白:



//white越大越白,越小越黑



testLabel.textColor = UIColor(white: 0.3, alpha: 0.7)





文字的顏色用圖片:



檔案位置:





09_cuteseal.jpg原圖:





@IBOutlet weak var testOne: UILabel!



testOne.textColor = UIColor(patternImage: .init(imageLiteralResourceName: "09_cuteseal.jpg"))





 





還有幾個我沒有列出來的方法,按住 command 點進去就會看到 UIColor class 的內容!




0 意見:

張貼留言