你的位置:首页 > 软件开发 > 操作系统 > iOS 监听控件某个属性的改变observeValueForKeyPath

iOS 监听控件某个属性的改变observeValueForKeyPath

发布时间:2015-06-30 13:00:06
创建一个测试的UIButton#import "ViewController.h"@interface ViewController ()@property(nonatomic, strong)UIButton *button;@end@implementat ...

 

创建一个测试的UIButton

#import "ViewController.h"@interface ViewController ()@property(nonatomic, strong)UIButton *button;@end@implementation ViewController- (void)viewDidLoad {  [super viewDidLoad];    self.button = [[UIButton alloc] initWithFrame:CGRectMake(30, 50, 50, 30)];  [self.button setTitle:@"测试" forState:UIControlStateNormal];  [self.button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];  self.button.layer.borderWidth = 1.0f;  [self.view addSubview:self.button];    //注册监听button的enabled状态  [self.button addObserver:self forKeyPath:@"enabled" options:NSKeyValueObservingOptionNew context:@"test_button"];    // 3秒钟后改变当前button的enabled状态  dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{    self.button.enabled = YES;  });}

 

海外公司注册、海外银行开户、跨境平台代入驻、VAT、EPR等知识和在线办理:https://www.xlkjsw.com

原标题:iOS 监听控件某个属性的改变observeValueForKeyPath

关键词:IOS

IOS
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。