實現透明度漸變和顏色漸變


 //Transparent Gradient Layer

    func insertTransparentGradient(#frame: CGRect) {

        

        let colorOne = UIColor(red: 100/255, green: 100/255, blue: 100/255, alpha: 0)

        let colorTwo = UIColor(red: 100/255, green: 100/255, blue: 100/255, alpha: 1)

        

        let colors = [colorOne.CGColor, colorTwo.CGColor]

        let stopOne = 0.0

        let stopTwo = 1.0

        let locations = [stopOne, stopTwo]

        

        let headerLayer = CAGradientLayer()

        headerLayer.colors = colors

        headerLayer.locations = locations

        headerLayer.frame = frame

        self.layer.insertSublayer(headerLayer, atIndex: 0)

    }

    

    //color gradient layer

    func insertColorGradient(#frame: CGRect) {

        

        let colorOne = UIColor(red: 255/255, green: 255/255, blue: 255/255, alpha: 1)

        let colorTwo = UIColor(red: 33/255, green: 33/255, blue: 33/255, alpha: 1)

        

        let colors = [colorOne.CGColor, colorTwo.CGColor]

        let stopOne = 0.0

        let stopTwo = 1.0

        let locations = [stopOne, stopTwo]

        

        let headerLayer = CAGradientLayer()

        headerLayer.colors = colors

        headerLayer.locations = locations

        headerLayer.frame = frame

        self.layer.insertSublayer(headerLayer, above: nil)


    }


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章