ios - CALayer in awakeFromNib vs drawRect -
i'm confused, why following code work if add awakefromnib
or initwithframe:
, doesn't work if add drawrect:
or call directly?
self.layer.cornerradius = cgrectgetwidth(self.bounds) / 2.0f; self.layer.shadowcolor = [uicolor blackcolor].cgcolor; self.layer.shadowradius = 3; self.layer.shadowoffset = cgsizemake(0.0f, 0.0f); self.layer.shadowopacity = 0.75f;
for programatically created buttons, should add method to? button might created init
, size changed later via constraints.
specification: working, mean button rounded (circle if aspect ratio 1:1) drop shadow. not working, mean it'll remain square.
check out detailed description in the apple docs, it's because you're setting layer configurations (cornerradius, shadow, etc.) in middle of draw cycle when should have completed before draw cycle began.
from drawrect: documentation:
by time method called, uikit has configured drawing environment appropriately view , can call whatever drawing methods , functions need render content.
other functions, awakefromnib:
or initwithframe:
occur before draw cycle, meaning configurations taken account before rendered on screen. comparison, drawrect:
assumes these basic configurations set , works on rendering you've specified on screen.
Comments
Post a Comment