ios - UIButton border on right and left sides -


i've been having trouble getting border or shadow between 3 buttons show separation. have tried getting border or shadow on left , right side of middle button shadow on 1 side. appreciated.

what have tried user shadow shows on right side:

    middlebutton.layer.backgroundcolor = uicolor.whitecolor().cgcolor     middlebutton.layer.bordercolor =  uicolor(red: 208/255, green: 208/255, blue: 208/255, alpha: 1.0).cgcolor     middlebutton.layer.borderwidth = 0.0     middlebutton.layer.maskstobounds = false     middlebutton.layer.shadowcolor = uicolor(red: 208/255, green: 208/255, blue: 208/255, alpha: 1.0).cgcolor     middlebutton.layer.shadowoffset = cgsizemake(0.5, 1.0)     middlebutton.layer.shadowopacity = 1.0     middlebutton.layer.shadowradius = 1.0 

below current view 3 buttons trying add separator between:

enter image description here

the hierarchy have in table cell:

enter image description here

swift 3 answer

you can make extension uibutton

extension uibutton {   func addrightborder(bordercolor: uicolor, borderwidth: cgfloat) {     let border = calayer()     border.backgroundcolor = bordercolor.cgcolor     border.frame = cgrect(x: self.frame.size.width - borderwidth,y: 0, width:borderwidth, height:self.frame.size.height)     self.layer.addsublayer(border)  }   func addleftborder(color: uicolor, width: cgfloat) {     let border = calayer()     border.backgroundcolor = color.cgcolor     border.frame = cgrect(x:0, y:0, width:width, height:self.frame.size.height)     self.layer.addsublayer(border)  } } 

then can use of buttons.

middlebutton.addrightborder(bordercolor: uicolor.white, borderwidth: 1.0)  middlebutton.addleftborder(bordercolor: uicolor.white, borderwidth: 1.0) 

should work fine. happy coding !


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -