iphone - UIButton with rounded corners and border -


i want set border on uibutton , rounded corners in 1 side

i use code:

//set rounded corners on top uibezierpath *maskpath =  [uibezierpath bezierpathwithroundedrect:self.scanbutton.bounds byroundingcorners:(uirectcornertopleft | uirectcornertopright) cornerradii:cgsizemake(10.0, 10.0)];  cashapelayer *masklayer = [cashapelayer layer]; masklayer.frame = self.scanbutton.bounds; masklayer.path = maskpath.cgpath;  self.scanbutton.layer.mask = masklayer;  // set border self.scanbutton.layer.bordercolor = [uicolor blackcolor].cgcolor; self.scanbutton.layer.borderwidth = 2.0f; [self.scanbutton.layer setmaskstobounds:yes]; 

enter image description here

how can make proper border in top corners?

swift 2.0 version

the corners of border clipping because you've set background color of view on uiview itself. better way set fill color directly on layer. done this:

let button = ... // existing uibutton let borderlayer = cashapelayer() borderlayer.strokecolor = uicolor.blackcolor().cgcolor borderlayer.fillcolor = uicolor.yellowcolor().cgcolor borderlayer.borderwidth = 2.0  let borderpath = uibezierpath(roundedrect: button.bounds,     byroundingcorners: [.topleft, .topright],     cornerradii: cgsize(width:10.0, height: 10.0))     borderlayer.path = borderpath.cgpath  button.layer.insertsublayer(borderlayer, atindex: 0) 

the above give result without clipped corners:

example button

i've put uibutton subclass using method border radius can set on each corner of button individually, check out here: https://gist.github.com/alexpls/95279b3f9a2da7f2d7bf, helps!


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -