Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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;
#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));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment