IOS allows the view UIView to display the border lines on one side separately. iosuiview
Sometimes you need to display the border line on one side of the view. In this case, setting the border of the layer cannot achieve the effect. I found that there is an opportunistic way to check the information on the Internet. The principle is to add another layer to the view layer so that the layer can act as the border line. According to this method, I wrote a function. If you need it, you can try it out.
- (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]; }}
This article is from the "rainbownight" blog, please be sure to keep this source http://rainbownight.blog.51cto.com/1336585/1332286