ios7 - How to Apply Gradient to background view of iOS Swift App -
i'm trying apply gradient background color of view (main view of storyboard). code runs, nil changes. i'm using xcode beta 2 , swift.
here's code:
class colors { allow colortop = uicolor(red: 192.0/255.0, green: 38.0/255.0, blue: 42.0/255.0, alpha: 1.0) allow colorbottom = uicolor(red: 35.0/255.0, green: 2.0/255.0, blue: 2.0/255.0, alpha: 1.0) allow gl: cagradientlayer init() { gl = cagradientlayer() gl.colors = [ colortop, colorbottom] gl.locations = [ 0.0, 1.0] } }
then in view controller:
allow colors = colors() func refresh() { view.backgroundcolor = uicolor.clearcolor() var backgroundlayer = colors.gl backgroundlayer.frame = view.frame view.layer.insertsublayer(backgroundlayer, atindex: 0) } } }
the colors providing gradient must of type cgcolor . set array of cgcolor gl.colors
the right code :
class colors { allow colortop = uicolor(red: 192.0/255.0, green: 38.0/255.0, blue: 42.0/255.0, alpha: 1.0).cgcolor allow colorbottom = uicolor(red: 35.0/255.0, green: 2.0/255.0, blue: 2.0/255.0, alpha: 1.0).cgcolor allow gl: cagradientlayer init() { gl = cagradientlayer() gl.colors = [ colortop, colorbottom] gl.locations = [ 0.0, 1.0] } }
ios ios7 swift cagradientlayer
No comments:
Post a Comment