swift:使用协议protocol设置颜色,UIImage的切圆角ImageWithCornerRadius

前端之家收集整理的这篇文章主要介绍了swift:使用协议protocol设置颜色,UIImage的切圆角ImageWithCornerRadius前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

//使用协议 方便以后切换颜色配置文件、或者做主题配色之类乱七八糟产品经理最爱的功能


protocol V2EXColorProtocol{

var v2_backgroundColor: UIColor { get }

var v2_navigationBarTintColor: UIColor { get }

var v2_TopicListTitleColor : UIColor { get }

var v2_TopicListUserNameColor : UIColor { get }

var v2_TopicListDateColor : UIColor { get }

var v2_LinkColor : UIColor { get }

var v2_TextViewBackgroundColor: UIColor { get }

var v2_CellWhiteBackgroundColor : UIColor { get }

var v2_NodeBackgroundColor : UIColor { get }

var v2_SeparatorColor : UIColor { get }

var v2_LeftNodeBackgroundColor : UIColor { get }

var v2_LeftNodeBackgroundHighLightedColor : UIColor { get }

var v2_LeftNodeTintColor: UIColor { get }

@H_403_257@ /// 小红点背景颜色

var v2_NoticePointColor : UIColor { get }

var v2_ButtonBackgroundColor : UIColor { get }

}


class V2EXDefaultColor: NSObject,V2EXColorProtocol {

static let sharedInstance = V2EXDefaultColor()

fileprivate override init(){

super.init()

}

var v2_backgroundColor : UIColor{

get{

return @H_259_403@colorWith255RGB(242,g: 243,b: 245);

}

}

var v2_navigationBarTintColor : UIColor{

get{

return @H_259_403@colorWith255RGB(102,g: 102,b: 102);

}

}

var v2_TopicListTitleColor : UIColor{

get{

return @H_259_403@colorWith255RGB(15,g: 15,b: 15);

}

}

var v2_TopicListUserNameColor : UIColor{

get{

return @H_259_403@colorWith255RGB(53,g: 53,b: 53);

}

}

var v2_TopicListDateColor : UIColor{

get{

return @H_259_403@colorWith255RGB(173,g: 173,b: 173);

}

}

var v2_LinkColor : UIColor {

get {

return @H_259_403@colorWith255RGB(119,g: 128,b: 135)

}

}

var v2_TextViewBackgroundColor :UIColor {

get {

return @H_259_403@colorWith255RGB(255,g: 255,b: 255)

}

}

var v2_CellWhiteBackgroundColor :UIColor {

get {

return @H_259_403@colorWith255RGB(255,b: 255)

}

}

var v2_NodeBackgroundColor : UIColor {

get {

return @H_259_403@colorWith255RGB(242,g: 242,b: 242)

}

}

var v2_SeparatorColor : UIColor {

get {

return @H_259_403@colorWith255RGB(190,g: 190,b: 190)

}

}

var v2_LeftNodeBackgroundColor : UIColor {

get {

return @H_259_403@colorWith255RGBA(255,b: 255,a: 76)

}

}

var v2_LeftNodeBackgroundHighLightedColor : UIColor {

get {

return @H_259_403@colorWith255RGBA(255,a: 56)

}

}

var v2_LeftNodeTintColor : UIColor {

get {

return @H_259_403@colorWith255RGBA(0,g: 0,b: 0,a: 140)

}

}

var v2_NoticePointColor : UIColor {

get {

return @H_259_403@colorWith255RGB(207,g: 70,b: 71)

}

}

var v2_ButtonBackgroundColor : UIColor {

get {

return @H_259_403@colorWith255RGB(85,g: 172,b: 238)

}

}

}



/////////////////////////



import UIKit


extension UIImage {

func roundedCornerImageWithCornerRadius(_ cornerRadius:CGFloat) -> UIImage {

let w = self.size.width

let h = self.size.height


var targetCornerRadius = cornerRadius

if cornerRadius < 0 {

targetCornerRadius = 0

}

if cornerRadius > min(w,h) {

targetCornerRadius = min(w,h)

}

let imageFrame = CGRect(x: 0,y: 0,width: w,height: h)

UIGraphicsBeginImageContextWithOptions(self.size,false,UIScreen.main.scale)

UIBezierPath(roundedRect: imageFrame,cornerRadius: targetCornerRadius).addClip()

self.draw(in: imageFrame)


let image = UIGraphicsGetImageFromCurrentImageContext()

UIGraphicsEndImageContext()


return image!

}

}


使用的地方


@H_403_257@/// 节点信息label的圆角背景图

fileprivate static var nodeBackgroundImage_Default =

@H_259_403@createImageWithColor( V2EXDefaultColor.sharedInstance.v2_NodeBackgroundColor,size: CGSize(width: 10,height: 20))

.roundedCornerImageWithCornerRadius(2)

.stretchableImage(withLeftCapWidth: 3,topCapHeight: 3)

原文链接:https://www.f2er.com/swift/321774.html

猜你在找的Swift相关文章