自己写的常用方法(Swfit版)

来源:互联网 发布:第一视角软件 编辑:程序博客网 时间:2024/05/10 04:57

记载一些常用的公共方法 不断更新中····

/**     判断字符串是否为空     - parameter str: String     - returns: true Or false     */    class func judgeIsEmptyWithString(str:String) -> Bool {        if str.isEmpty {            return true        }        return false    }    /**     设置UIButton圆角     */    class func setButtonBorderRadius(button:UIButton, radius:CGFloat) {        button.layer.masksToBounds = true        button.layer.cornerRadius = radius    }    /**     设置UIImageView圆角     */    class func setImageViewBorderRadius(imageView:UIImageView, radius:CGFloat) {        imageView.layer.masksToBounds = true        imageView.layer.cornerRadius = radius    }    /**     随机颜色     - returns: 返回一个颜色     */    class func randomColor() ->UIColor{        return self.init(red: CGFloat(CGFloat(random())/CGFloat(RAND_MAX)), green: CGFloat(CGFloat(random())/CGFloat(RAND_MAX)), blue: CGFloat(CGFloat(random())/CGFloat(RAND_MAX)), alpha: 1)    }    /**     设置RGB颜色值     - parameter red:   red     - parameter green: green     - parameter blue:  blue     - parameter alpha: alpha     - returns: 一个颜色值     */    class func RGBColor(red:CGFloat, green:CGFloat, blue:CGFloat, alpha:CGFloat) ->UIColor {        return self.init(red: red / 255.0, green: green / 255.0, blue: blue / 255.0, alpha: alpha)    }
0 0