iOS NSObject 常用 Category(类目)分享

西门桃桃 2020-07-28 PM 1391℃ 0条

1、获取当前类名:

+ (NSString *)className {
    return NSStringFromClass(self);
}

2、设置TableViewCell

@property (nonatomic, copy) NSString *tableViewCellName;
@property (nonatomic, assign) CGFloat tableViewCellHeight;
@property (nonatomic, assign) CGFloat tableViewCellWidth;

- (void)setTableViewCellName:(NSString *)tableViewCellName {
    objc_setAssociatedObject(self, @selector(tableViewCellName), tableViewCellName, OBJC_ASSOCIATION_COPY);
}

- (NSString *)tableViewCellName {
    return objc_getAssociatedObject(self, _cmd);
}

- (void)setTableViewCellHeight:(CGFloat)tableViewCellHeight {
    objc_setAssociatedObject(self, @selector(tableViewCellHeight), @(tableViewCellHeight), OBJC_ASSOCIATION_RETAIN);
}

- (CGFloat)tableViewCellHeight {
    return [objc_getAssociatedObject(self, _cmd) floatValue];
}

- (void)setTableViewCellWidth:(CGFloat)tableViewCellWidth {
    objc_setAssociatedObject(self, @selector(tableViewCellWidth), @(tableViewCellWidth), OBJC_ASSOCIATION_RETAIN);
}

- (CGFloat)tableViewCellWidth {
    return [objc_getAssociatedObject(self, _cmd) floatValue];
}
标签: Category, NSObject

非特殊说明,本博所有文章均为博主原创。

评论啦~