swift - Gradient starts to early -
this code:
let gradient = cagradientlayer() gradient.opacity = 0.8 let startcolor = uicolor(red: 1, green: 0, blue: 0, alpha: 1).cgcolor let endcolor = uicolor(red: 0, green: 1, blue: 0, alpha: 1).cgcolor gradient.colors = [startcolor, endcolor, startcolor] gradient.locations = [0.0, 0.1, 0.95] gradient.frame = viewinstack1background.frame viewinstack1background.layer.addsublayer(gradient) let gradient2 = cagradientlayer() gradient2.colors = [startcolor, uicolor.clear.cgcolor, startcolor] gradient2.locations = [0.0, 0.1, 0.95] gradient2.opacity = 0.8 gradient2.startpoint = cgpoint(x: 0.0, y: 0.5) gradient2.endpoint = cgpoint(x: 1.0, y: 0.5) gradient2.frame = viewinstack1background.frame viewinstack1background.layer.addsublayer(gradient2) i want red color on outside , green color on inside. looks now:
why there red when start location set 0.95? thanks.
try
gradient.locations = [0.0, 0.5, 1.0] that transitions full green in middle -- right have full green @ 10% near left. if want transition faster green, try
gradient.colors = [startcolor, endcolor, endcolor, startcolor] gradient.locations = [0.0, 0.05, 0.95, 1.0] 
Comments
Post a Comment