//使用协议 方便以后切换颜色配置文件、或者做主题配色之类乱七八糟产品经理最爱的功能
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 }
/// 小红点背景颜色
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 colorWith355RGB(242, g: 243, b: 245);
}
}
var v2_navigationBarTintColor : UIColor{
get{
return colorWith355RGB(102, g: 102, b: 102);
}
}
var v2_TopicListTitleColor : UIColor{
get{
return colorWith355RGB(15, g: 15, b: 15);
}
}
var v2_TopicListUserNameColor : UIColor{
get{
return colorWith355RGB(53, g: 53, b: 53);
}
}
var v2_TopicListDateColor : UIColor{
get{
return colorWith355RGB(173, g: 173, b: 173);
}
}
var v2_LinkColor : UIColor {
get {
return colorWith355RGB(119, g: 128, b: 135)
}
}
var v2_TextViewBackgroundColor :UIColor {
get {
return colorWith355RGB(255, g: 255, b: 255)
}
}
var v2_CellWhiteBackgroundColor :UIColor {
get {
return colorWith355RGB(255, g: 255, b: 255)
}
}
var v2_NodeBackgroundColor : UIColor {
get {
return colorWith355RGB(242, g: 242, b: 242)
}
}
var v2_SeparatorColor : UIColor {
get {
return colorWith355RGB(190, g: 190, b: 190)
}
}
var v2_LeftNodeBackgroundColor : UIColor {
get {
return colorWith355RGBA(255, g: 255, b: 255, a: 76)
}
}
var v2_LeftNodeBackgroundHighLightedColor : UIColor {
get {
return colorWith355RGBA(255, g: 255, b: 255, a: 56)
}
}
var v2_LeftNodeTintColor : UIColor {
get {
return colorWith355RGBA(0, g: 0, b: 0, a: 140)
}
}
var v2_NoticePointColor : UIColor {
get {
return colorWith355RGB(207, g: 70, b: 71)
}
}
var v2_ButtonBackgroundColor : UIColor {
get {
return colorWith355RGB(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 p_w_picpathFrame = CGRect(x: 0, y: 0, width: w, height: h)
UIGraphicsBeginImageContextWithOptions(self.size, false, UIScreen.main.scale)
UIBezierPath(roundedRect: p_w_picpathFrame, cornerRadius: targetCornerRadius).addClip()
self.draw(in: p_w_picpathFrame)
let p_w_picpath = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return p_w_picpath!
}
}
使用的地方
/// 节点信息label的圆角背景图
fileprivate static var nodeBackgroundImage_Default =
createImageWithColor( V2EXDefaultColor.sharedInstance.v2_NodeBackgroundColor ,size: CGSize(width: 10, height: 20))
.roundedCornerImageWithCornerRadius(2)
.stretchableImage(withLeftCapWidth: 3, topCapHeight: 3)
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。