Sometimes it is necessary to have the view show the border line on one side, when setting the layer's border is not effective. Online access to information found there is an opportunistic approach, the principle is to add a layer to the view layer, so that the layer as a border line role. According to this method I wrote a function, a friend of need can take to try.
-(void) Setborderwithview: (UIView *) View top: (BOOL) top left: (bool) left bottom: (bool) Bottom right: (bool) Right BorderColor: (Uicolor *) color borderWidth: (cgfloat) width{if (top) {Calayer *layer = [Calayer layer]; Layer.frame = CGRectMake (0, 0, view.frame.size.width, width); Layer.backgroundcolor = color. Cgcolor; [View.layer Addsublayer:layer]; } if (left) {Calayer *layer = [Calayer layer]; Layer.frame = CGRectMake (0, 0, width, view.frame.size.height); Layer.backgroundcolor = color. Cgcolor; [View.layer Addsublayer:layer]; } if (bottom) {calayer *layer = [Calayer layer]; Layer.frame = CGRectMake (0, View.frame.size.height-width, view.frame.size.width, width); Layer.backgroundcolor = color. Cgcolor; [View.layer Addsublayer:layer]; } if (right) {Calayer *layer = [Calayer layer]; Layer.frame = CGRectMake (view.frame.size.width-width, 0, Width, view.frame.size.height); Layer.backgroundcolor = color. Cgcolor; [View.layer Addsublayer:layer]; }}
IOS lets view uiview display a border line on one side individually