XCODE 动态生成 BUTTON
CGRect frame = CGRectMake(90, 200, 200, 60);
UIButton *someAddButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
someAddButton.backgroundColor = [UIColor clearColor];
[someAddButton setTitle:@"动态添加一个按钮!" forState:UIControlStateNormal];
someAddButton.frame = frame;
[someAddButton addTarget:self action:@selector(someButtonClicked) forControlEvents:UIControlEventTouchUpInside];
然后我需要删除这个 BUTTON 如何处理呢?
xcode
------解决方案--------------------
1、给这个button设置一个tag,比如someAddButton.tag=999;要删除时通过这个tag找到button(self viewWithTag:)后remove之。
2、一样是通过tag来判断
------解决方案--------------------
通过tag获取到button对象,然后removeFromSuperview