iphone - 如何将复选框添加到 uialertview 中?

标签 iphone uialertview

我是 iPhone 开发新手。我想在警报 View 中添加一个复选框。过去两天我正在对此警报 View 进行测试,但没有得到任何有效的演示项目。我正是想要这个警报框!

enter image description here

谁能帮我吗?

最佳答案

尝试使用此代码在 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/

相关文章:

iphone - 如何判断 UIView 何时获得焦点

iOS:从 AppDelegate 添加 subview 未加载

iphone - 突出显示 UIAlertView 中的顶部按钮

ios - 我如何直观地表明 UIAlertView 是重要的?

iphone - 无法从委托(delegate)调用 Controller 方法

ios - 使用 xcodebuild 命令从 Cordova 项目创建 IPA

ios - 获取 TextField 和键盘之间的高度

ios - 如何在警报 View 中创建两个文本字段,IOS

iphone - 更新警报消息中的文本

ios - 如何在触摸 UIAlertView 之外的任何地方时关闭它?