我试图在运行时向屏幕添加一堆 UIButton。根据用户输入,我想在不同的位置显示不同的按钮。这可能吗?
最佳答案
是的,这是可能的。
在 objective-C 中创建一个按钮:
UIButton *btnPrefix = [UIButton buttonWithType:UIButtonTypeCustom];
[btnPrefix setFrame:CGRectMake(0, 0, 20, 20)];
[btnPrefix setUserInteractionEnabled: YES];
[btnPrefix addTarget:self action:@selector(buttonTapped) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview: btnPrefix];
关于objective-c - iOS动态添加UIControls,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10713137/