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

記載一些常用的公共方法 不斷更新中····

/**
     判斷字符串是否爲空

     - 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)
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章