swift - Apply vertical alpha gradient to UITableView -
i'm new ios development , trying learn swift. i'd apply vertical alpha gradient uitableview, having trouble.
originally following this post, did following:
var gradientmasklayer:cagradientlayer = cagradientlayer() gradientmasklayer.frame = mytableview.bounds gradientmasklayer.colors = [uicolor.clearcolor().cgcolor, uicolor.blackcolor().cgcolor] gradientmasklayer.locations = [0.0, 0.05] mytableview.layer.mask = gradientmasklayer
after getting error array element cannot bridged objective-c
, reading this post modified 2 arrays used:
var gradientmasklayer:cagradientlayer = cagradientlayer() var gradientmaskcolors:nsarray = [uicolor.clearcolor().cgcolor, uicolor.blackcolor().cgcolor] var gradientmasklocations:nsarray = [0.0, 0.05] gradientmasklayer.frame = mytableview.bounds gradientmasklayer.colors = gradientmaskcolors gradientmasklayer.locations = gradientmasklocations mytableview.layer.mask = gradientmasklayer
and error value failed bridge swift type objective-c type
i'm struggling find solution. can lend assistance?
so believe have solution problem, i'm not sure understand it. problem seems arise when try create implicitly unwrapped anyobject
array, containing only implicitly unwrapped core foundation types, i.e.:
let implicitlyunwrappedcgcolor:cgcolor! = uicolor.clearcolor().cgcolor let implicitlyunwrappedanyobjectarray:[anyobject]! = [implicitlyunwrappedcgcolor]
gives array element cannot bridged objective-c
error.
it feels must swift compiler issue, particularly following, implicitly unwrapped cgcolor
declared implicitly unwrapped anyobject
, seems make compiler happy again:
let implicitlyunwrappedcgcolor:anyobject! = uicolor.clearcolor().cgcolor let implicitlyunwrappedanyobjectarray:[anyobject]! = [implicitlyunwrappedcgcolor]
as sticking standard objective-c object array:
let implicitlyunwrappedcgcolor:cgcolor! = uicolor.clearcolor().cgcolor let uicolor = uicolor.clearcolor() let implicitlyunwrappedanyobjectarray:[anyobject]! = [implicitlyunwrappedcgcolor, uicolor]
in case, try following solution issue:
var gradientmasklayer:cagradientlayer = cagradientlayer() gradientmasklayer.frame = mytableview.bounds gradientmasklayer.colors = [uicolor.clearcolor().cgcolor!, uicolor.blackcolor().cgcolor!] gradientmasklayer.locations = [0.0, 0.05] mytableview.layer.mask = gradientmasklayer
Comments
Post a Comment