ios - my view looks different on iphone 5 and iphone 6 even though it has constraints - what is wrong here? -
in swift
app applying gradient view. following code:
@iboutlet weak var gradientview: uiview! override func viewdidload(){ super.viewdidload() let layer = cagradientlayer() layer.frame = cgrect(x: 0, y: 0, width: self.gradientview.frame.width, height: self.gradientview.frame.height) layer.colors = [uicolor.clear.cgcolor, uicolor.white.cgcolor] gradientview.layer.addsublayer(layer) }
in storyboard gradientview
black 1 here:
its constraints are:
so touches edges on each side, top , white panel on bottom.
when run in iphone5 simulator have:
and that's fine. when run on iphone 6s, see:
what's problem here, since constraints applied?
the problem gradientview
's frame not updated yet in viewdidload
. try instead:
let gradientlayer = cagradientlayer() override func viewdidload(){ super.viewdidload() gradientlayer.colors = [uicolor.clear.cgcolor, uicolor.white.cgcolor] gradientview.layer.addsublayer(gradientlayer) } override func viewdidlayoutsubviews(){ super.viewdidlayoutsubviews() gradientlayer.frame = gradientview.bounds }
Comments
Post a Comment