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 怎么样处理呢?
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 怎么样处理呢?
解决方案:20分
1、给这个button设置一个tag,例如someAddButton.tag=999;要删除时通过这个tag找到button(self viewWithTag:)后remove之。
2、一样是通过tag来判断
2、一样是通过tag来判断
解决方案:20分
通过tag获取到button对象,然后removeFromSuperview