Created
November 26, 2014 05:22
-
-
Save Altimor/f48715200dc049fca69d to your computer and use it in GitHub Desktop.
UIView+Border
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <PureLayout/PureLayout.h> | |
@interface UIView (Border) | |
- (void)addBorder:(ALEdge)side withColor:(UIColor *)borderColor width:(CGFloat)width; | |
@end | |
@implementation UIView (Border) | |
- (void)addBorder:(ALEdge)side withColor:(UIColor *)borderColor width:(CGFloat)width { | |
UIView *borderView = [UIView new]; | |
borderView.backgroundColor = borderColor; | |
BOOL verticalBorder = side == ALEdgeLeft || side == ALEdgeRight; | |
ALDimension minorDimension = verticalBorder ? ALDimensionWidth : ALDimensionHeight; | |
ALDimension majorDimension = verticalBorder ? ALDimensionHeight : ALDimensionWidth; | |
[self addSubview:borderView]; | |
[borderView autoSetDimension:minorDimension toSize:width]; | |
[borderView autoMatchDimension:majorDimension toDimension:majorDimension ofView:self]; | |
[borderView autoPinEdgeToSuperviewEdge:side]; | |
[borderView autoPinEdgeToSuperviewEdge:verticalBorder ? ALEdgeTop : ALEdgeLeft]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment