UIView with Selective Borders

UIView with Selective Borders

Want to do something like this?
Or this?
UIView lets you add a border on all edges easily like:
myView.layer.borderWidth = 1.0f;
myView.layer.borderColor = [UIColor darkGrayColor].CGColor;
But CALayer does not support selective borders out of the box.

That’s why I created a simple open source UIView subclass available on github here:
It is easy and simple to use.

Here’s a snippet from the README:
Basic use case:
– Change your UIView in Interface Builder to class type NAUIViewWithBorders
– In your view controller’s viewDidLoad

/* For a top border only ———————————————- */
self.myBorderView.borderColorTop = [UIColor redColor];
self.myBorderView..borderWidthsAll = 1.0f;

/* For borders with different colors and widths ————————— */
self.myBorderView.borderWidths = UIEdgeInsetsMake(2.0, 4.0, 6.0, 8.0);
self.myBorderView.borderColorTop = [UIColor blueColor];
self.myBorderView.borderColorRight = [UIColor redColor];
self.myBorderView.borderColorBottom = [UIColor greenColor];
self.myBorderView.borderColorLeft = [UIColor darkGrayColor];

Be sure to check out the demo project!


Leave a Reply

Your email address will not be published. Required fields are marked *