- (void)createButton { UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; myButton.frame = CGRectMake(100, 100, 100, 50); [myButton setTitle:@"click me!" forState:UIControlStateNormal]; SEL eventHandler = @selector(clickHandler); [myButton addTarget:self action:eventHandler forControlEvents:UIControlEventTouchUpInside]; [window addSubview:myButton]; } - (void)clickHandler { NSLog(@"You clicked button!"); }
objective c 手动创建按钮并绑定事件处理程序
最新推荐文章于 2022-07-25 23:53:31 发布