A custom UIView subclass to easily turn on drawing of each single border on a view.
Usage is easy.
Add the dependency to your
platform :ios pod 'TWRBorderedView' ...
pod install to install the dependencies.
Next, import the header file wherever you want to use the custom view:
The bordered view can be set up either via Interface Builder (XIB and Storyboards) or programmatically.
Just set up TWRBorderedView as the class of any UIView and use the Identity Inspector to set User Defined Runtime Attributes.
The following key paths can be defined:
Here is an example of how it looks like setting the properties from Xcode's Interface Builder:
If you prefer adding you subviews from code, you can work with TWRBorderedView programmatically with a pretty sweet one-liner:
CGRect borderedViewRect = CGRectMake(0, 0, 100, 100); TWRBorderMask mask = (TWRBorderMaskBottom | TWRBorderMaskTop); TWRBorderedView *borderedView = [[TWRBorderedView alloc] initWithFrame:borderedViewRect borderWidth:5.0f color:[UIColor greenColor] andMask:mask]; [self.view addSubview:borderedView];
The following screenshot is a very basic demonstration of the two ways of dealing with borders.
The two red views at the top and at the bottom have been defined from IB. The top one has a bottom border and the bottom one has a border on the top.
The two green views have both 3 borders and have been added as subviews from code. You can download the demo project to run the example by yourself.
TWRBorderedView requires iOS 6.x or greater.
Usage is provided under the MIT License. See LICENSE for the full details.