您的位置:首页 > 移动开发 > IOS开发

IOS动态为类添加属性

2016-03-17 11:33 453 查看
IOS使用Category时候动态为类添加属性:

#import <UIKit/UIKit.h>
#import "JTNavigationController.h"

@interface UIViewController (JTNavigationExtension)

//是否允许滑动
@property (nonatomic, assign) BOOL jt_screenPopGestureEnabled;

@end
#import "UIViewController+JTNavigationExtension.h"
#import <objc/runtime.h>

@implementation UIViewController (JTNavigationExtension)

/************jt_screenPopGestureEnabled************/
-(void)setJt_screenPopGestureEnabled:(BOOL)jt_screenPopGestureEnabled{
objc_setAssociatedObject(self, @selector(jt_screenPopGestureEnabled), @(jt_screenPopGestureEnabled), OBJC_ASSOCIATION_RETAIN);
}

-(BOOL)jt_screenPopGestureEnabled{
return [objc_getAssociatedObject(self, _cmd) boolValue];
}

@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: