1. 程式人生 > >oc 無中生有新增協議

oc 無中生有新增協議

    @protocol MyClassJavaScriptMethods <JSExport>

    - (void)foo;

    @end

 

    @interface MyClass : NSObject <MyClassJavaScriptMethods>

    - (void)foo;

    - (void)bar;

    @end

 

class_addProtocol([UIButton class],@protocol(UIButtonExport));

 

@protocol UIButtonExport <JSExport>

- (void)setTitle:(NSString *)title forState:(UIControlState)state;

- (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state;

@end