最原始的
let color_rgb = { r,g,b,a in
return UIColor(red: r, green: g, blue: b, alpha: a)
}
因为UIColor(_red: , green: _, blue: _, alpha: _)是初始化函数,有个返回值类型UIColor,其实可以这么写
let color_rgb = { r,g,b,a in
UIColor(red: r, green: g, blue: b, alpha: a)
}
在闭包中可以省略in前面的参数,可以写成
let color_rgba = {UIColor(red: $0, green: $1, blue: $2, alpha: $3)}```
应用
let navigationBar_color = color_rgba(227/255,23/255,13/255,1)```
如果想要提示的话,你可以这样
typealias colorBlock = (CGFloat,CGFloat,CGFloat,CGFloat) -> UIColor
let color_rgba:colorBlock = {UIColor(red: $0, green: $1, blue: $2, alpha: $3)}```
网友评论