Skip to content

Instantly share code, notes, and snippets.

@Altimor
Created November 26, 2014 05:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Altimor/f48715200dc049fca69d to your computer and use it in GitHub Desktop.
Save Altimor/f48715200dc049fca69d to your computer and use it in GitHub Desktop.
UIView+Border
#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