IOS allows the view UIView to display the border lines on one side separately. iosuiview

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.