ios - Set the CALayer's borderWidth property to affect only the left and right borders? -


i'm trying make custom color uitableviewcell selection. don't want entire cell highlight when press it, in other words frame of selection background should (10,cell.frame.origin.y,300,cell.frame.size.height). tried give backgroundcolorview.layer.borderwidth property value of 10, affects entire view, , not left-right borders. code i'm stuck on:

uiview *backgroundcolorview = [[uiview alloc] init]; backgroundcolorview.backgroundcolor = switch_color_on; backgroundcolorview.layer.maskstobounds = yes; // backgroundcolorview.layer.borderwidth = 10.0f; // shrinks entire view [cell setselectedbackgroundview:backgroundcolorview]; 

any tips on how make work? thanks.

i think easiest solution add 2 layers view this:

calayer *leftborder = [calayer layer]; [leftborder setbackgroundcolor:[[uicolor blackcolor] cgcolor]]; [leftborder setframe:cgrectmake(0, 0, 5, yourview.frame.size.height)]; [yourview.layer addsublayer:leftborder];  calayer *rightborder = [calayer layer]; [rightborder setbackgroundcolor:[[uicolor blackcolor] cgcolor]]; [rightborder setframe:cgrectmake(yourview.frame.size.width-5, 0, 5, yourview.frame.size.height)]; [yourview.layer addsublayer:rightborder]; 

this code add 2 black borders of 5 pixels width , black color. hope helps.


Comments