swift 第三课 宏定义 宏方法

swift 与oc 不同,没有宏的定义就像 oc 可以这样写,直接调用:

/*
 默认颜色
 */
#define RGBCOLOR_HEX(h) RGBCOLOR((((h)>>16)&0xFF), (((h)>>8)&0xFF), ((h)&0xFF))
#define RGBCOLOR(r,g,b) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1]
#define userGreenColor [UIColor colorWithRed:23.0/255 green:146.0/255 blue:137.0/255 alpha:1] #define userBackColor RGBCOLOR_HEX(0xe6e6e6) #define userReportButtonColor RGBCOLOR_HEX(0xF3F3F3)

#define kStatusBarFrame [UIApplication sharedApplication].statusBarFrame

 

swift 就要这样写了:

/*
 默认颜色
 */
func RGBColor(r :CGFloat ,g:CGFloat,b:CGFloat) ->UIColor{
    return UIColor.init(colorLiteralRed: Float(r / 255.0), green:Float(g / 255.0) , blue:Float (b / 255.0), alpha: 1)
}

func RGBCOLOR_HEX(h:Int) ->UIColor {
    return RGBColor(r: CGFloat(((h)>>16) & 0xFF), g:   CGFloat(((h)>>8) & 0xFF), b:  CGFloat((h) & 0xFF))
}

let userBackColor = RGBCOLOR_HEX(h: 0xe6e6e6)
let userGreenColor  =  RGBColor(r: 23.0, g: 146.0, b: 137.0)
let  userReportButtonColor = RGBCOLOR_HEX(h: 0xF3F3F3)

let statusBarFrame = UIApplication.shared.statusBarFrame

 

swift 的调用方法:

class ConstController: UIViewController {
    class func customSetting()  {

        self.tabBar.tintColor = userGreenColor //这里是调用的颜色
        UINavigationBar.appearance().tintColor = UIColor.white
        UINavigationBar.appearance().barTintColor = userGreenColor
        UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName:UIColor.white,NSFontAttributeName: UIFont.systemFont(ofSize: 25.0)] //为导航栏设置字体颜色等
    }
}

 

转载于:https://www.cnblogs.com/Bob-blogs/p/6564396.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值