我是 iPhone 开发新手。我想在警报 View 中添加一个复选框。过去两天我正在对此警报 View 进行测试,但没有得到任何有效的演示项目。我正是想要这个警报框!
谁能帮我吗?
最佳答案
尝试使用此代码在 alertview
中添加复选框。
swift
let nameField = UIButton(frame: CGRect(x: 0.0, y: 0, width: 50, height: 50.0))
let v = UIView(frame: CGRect(x: 0, y: 0, width: 250, height: 40))
nameField.setImage(UIImage(named: "checkbox_off.png"), for: .normal)
v.addSubview(nameField)
var av = UIAlertView(title: "TEST", message: "subview", delegate: nil, cancelButtonTitle: "NO", otherButtonTitles: "YES")
av.setValue(v, forKey: "accessoryView")
av.show()
objective-c
UIButton *nameField = [[UIButton alloc] initWithFrame:CGRectMake(0.0, 0, 50, 50.0)];
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 250, 40)];
[nameField setImage:[UIImage imageNamed:@"checkbox_off.png"] forState:UIControlStateNormal];
[v addSubview:nameField];
UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"TEST" message:@"subview" delegate:nil cancelButtonTitle:@"NO" otherButtonTitles:@"YES", nil];
[av setValue:v forKey:@"accessoryView"];
[av show];
我希望这段代码对您有用。
关于iphone - 如何将复选框添加到 uialertview 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22727842/