Iphone UIALertView带有文本的多个按钮
我有一个alertview,有3个按钮和文本(标签,而不是文本视图),如果我把它们放在一起,它会变得很难看,因为这个小小的滚动文本和所有的按钮占据了大部分空间。有人知道如何修复此问题吗?为什么不尝试为此创建自定义视图 您可以根据需要自定义大小、颜色、背景等 并将其显示为模式窗口/视图Iphone UIALertView带有文本的多个按钮,iphone,xcode,button,alertview,Iphone,Xcode,Button,Alertview,我有一个alertview,有3个按钮和文本(标签,而不是文本视图),如果我把它们放在一起,它会变得很难看,因为这个小小的滚动文本和所有的按钮占据了大部分空间。有人知道如何修复此问题吗?为什么不尝试为此创建自定义视图 您可以根据需要自定义大小、颜色、背景等 并将其显示为模式窗口/视图 如果仍要使用alertView,则可以将间距设置为: UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Title" message:@"\n\n!\n
如果仍要使用alertView,则可以将间距设置为:
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Title" message:@"\n\n!\n\n\n\n" delegate:self cancelButtonTitle:@"Button 1" otherButtonTitles:@"Button 2",@"Button 3", nil];
[alert show];
我建议你做两个UIAERTVIEW,然后使用
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
检查单击了哪个警报视图。如果你真的需要一个uialertview,下面的答案也很好
详细说明:
@interface ViewController : UIViewController <UIAlertViewDelegate>
UIAlertView *alert2 = [[UIAlertView alloc] initWithTitle:@"More Options" message:nil delegate:self cancelButtonTitle:@"Back" otherButtonTitle:@"Option 1", @"Option 2", @"Option 3", nil];
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
if (alertView == alert1) {
[alert2 show];
}
else if (alertView == alert2) {
NSString *string = [alertView buttonTitleAtIndex:buttonIndex];
if ([string isEqualToString:@"Option 1"]) {
//Do stuff
}
else if ([string isEqualToString:@"Option 2"]) {
//Do something else
}
else if ([string isEqualToString:@"Option 3"]) {
//Do something 3rd
}
}
向下移动文本视图的一种简单方法是添加消息
[alertViewObject setMessage:@"\n"];
帧未生效的原因是-show在开始动画之前设置帧并创建视图层次。您还应该使文本视图成为第一响应者,以便弹出键盘
使用以下代码自定义AlertView
// Customize Alert View
UIAlertView *alertView = [UIAlertView new];
alertView.title = @"Alert Title";
// Adding Your Buttons
[alertView addButtonWithTitle:@"Button1"];
[alertView addButtonWithTitle:@"Button2"];
[alertView addButtonWithTitle:@"Button3"];
[alertView addButtonWithTitle:@"Button4"];
// Add a Space for Text View
alertView.message = @"\n";
// View heirarchy, set its frame and begin bounce animation
[alertView show];
// Set the frame
CGRect frame = alertView.frame;
frame.origin.y -= 100.0f;
alertView.frame = frame;
// Adding TextField
UITextField* text = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 45.0, 245.0, 25.0)];
text.borderStyle = UITextBorderStyleRoundedRect;
[alertView addSubview:text];
[text becomeFirstResponder];
我希望这将对您有所帮助。iOS 9.0中不推荐使用UIAlertView。 改用UIAlertController的首选样式UIAlertControllerStyleAlert
let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
alertController.addAction(UIAlertAction(title: "AlertAction 0", style: .default, handler: { (alertAction: UIAlertAction) in
print("0")
}))
alertController.addAction(UIAlertAction(title: "AlertAction 1", style: .default, handler: { (alertAction: UIAlertAction) in
print("1")
}))
alertController.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: { (alertAction: UIAlertAction) in
print("cancel")
}))
感谢您提供了一个很好的答案,但由于我是Objective-C新手,我还没有开始使用多个视图,但仍然是一个很好的答案(希望我能投赞成票。)我尝试过,但问题是我需要显示一些信息,但感谢
一些信息
where代替代码>?你想把它放在哪里?你只有两个地方可以显示你的文本(标题和消息)。是的,很抱歉我不清楚,我想显示一条消息(不是标题),顺便说一句,很抱歉没有理解“!”应该是我的消息。这看起来很好,很完美,但我需要一条事先写好的消息,但我可能仍在其他情况下使用它。感谢您抽出时间回答!
let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
alertController.addAction(UIAlertAction(title: "AlertAction 0", style: .default, handler: { (alertAction: UIAlertAction) in
print("0")
}))
alertController.addAction(UIAlertAction(title: "AlertAction 1", style: .default, handler: { (alertAction: UIAlertAction) in
print("1")
}))
alertController.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: { (alertAction: UIAlertAction) in
print("cancel")
}))