Skip to content

Instantly share code, notes, and snippets.

@Andrewmika
Created April 16, 2018 03:40
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 Andrewmika/f17ec99cde22546c2846fb8ff20ed561 to your computer and use it in GitHub Desktop.
Save Andrewmika/f17ec99cde22546c2846fb8ff20ed561 to your computer and use it in GitHub Desktop.
add Bottom Line
#import <UIKit/UIKit.h>
@interface UIView (EX)
@property (nonatomic, strong) UIView *bottomLine; // <##>
- (void)as_addBottomLine;
- (void)as_addBottomLineWithLeftOffset:(CGFloat)leftOffset rightOffset:(CGFloat)rightOffset;
@end
#import "UIView+EX.h"
#import <objc/runtime.h>
@implementation UIView (EX)
- (UIView *)bottomLine {
return objc_getAssociatedObject(self, _cmd);
}
- (void)setBottomLine:(UIView *)bottomLine {
objc_setAssociatedObject(self, @selector(bottomLine), bottomLine, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
- (void)as_addBottomLine {
[self as_addBottomLineWithLeftOffset:0 rightOffset:0];
}
- (void)as_addBottomLineWithLeftOffset:(CGFloat)leftOffset rightOffset:(CGFloat)rightOffset {
if (!self.bottomLine) {
UIView *line = [UIView new];
line.backgroundColor = [UIColor yd_grey_dddddd];
[self addSubview:line];
self.bottomLine = line;
}
[self.bottomLine mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.right.bottom.mas_equalTo(self).insets(UIEdgeInsetsMake(0, leftOffset, 0, rightOffset));
make.height.mas_equalTo(0.5);
}];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment