Created
April 16, 2018 03:40
-
-
Save Andrewmika/f17ec99cde22546c2846fb8ff20ed561 to your computer and use it in GitHub Desktop.
add Bottom Line
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 <UIKit/UIKit.h> | |
@interface UIView (EX) | |
@property (nonatomic, strong) UIView *bottomLine; // <##> | |
- (void)as_addBottomLine; | |
- (void)as_addBottomLineWithLeftOffset:(CGFloat)leftOffset rightOffset:(CGFloat)rightOffset; | |
@end |
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 "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