TWRBorderedView 0.2

TWRBorderedView 0.2

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Dec 2014

Maintained by Michelangelo Chasseur.



TWRBorderedView

A custom UIView subclass to easily turn on drawing of each single border on a view.

Usage

Usage is easy.

Add the dependency to your Podfile:

platform :ios
pod 'TWRBorderedView'
...

Run pod install to install the dependencies.

Next, import the header file wherever you want to use the custom view:

#import "TWRBorderedView.h"

The bordered view can be set up either via Interface Builder (XIB and Storyboards) or programmatically.

Interface Builder

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:

  • topBorder (Boolean) - a YES value will draw the border
  • bottomBorder (Boolean)
  • leftBorder (Boolean)
  • rightBorder (Boolean)
  • borderColor (Color)
  • borderWidth (Number) - in points

Here is an example of how it looks like setting the properties from Xcode's Interface Builder:

Programmatically

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];

Demo

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.

Requirements

TWRBorderedView requires iOS 6.x or greater.

License

Usage is provided under the MIT License. See LICENSE for the full details.