UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Enter Student Name" message:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Save", @"Save and Add", nil];
alert.tag = 1;
alert.transform=CGAffineTransformMakeScale(1.0, 0.75);
alert.alertViewStyle=UIAlertViewStylePlainTextInput;
[alert show];
-(void)willPresentAlertView:(UIAlertView *)alertView {
if (alertView.tag == 1) {
for (UIView *view in alertView.subviews) {
if ([view isKindOfClass:[UITextField class]]||
[view isKindOfClass:[UIButton class]] || view.frame.size.height==31) {
CGRect rect=view.frame;
rect.origin.y += 65;
view.frame = rect;
}
}
}
}
因为我正在使用textfield和三个按钮显示alertview,它在ios 7中工作正常,但在ios 6中没有。 看看两个ios图像 - >
因为你们都可以看到ios 6的警报视图受到干扰......但是我没有得到我在那里做错了什么。
答案 0 :(得分:3)
我也在这里试过,似乎风格“UIAlertViewStylePlainTextInput”与UIAlertView中的3个或更多按钮不相符。
你的问题似乎与此直接相关:
iOS5: Has somebody managed to fix UIAlertView with three buttons and textfield (UIAlertViewStylePlainTextInput)?
不建议使用UIAlertView的视图层次结构(因为有些州App Store拒绝) 参考:如何Move buttons down in UIAlertView
您可以创建自己的自定义alertView:
http://iosdevtricks.blogspot.in/2013/04/creating-custom-alert-view-for-iphone.html
或使用预制的,例如:
https://github.com/TomSwift/TSAlertView
如果您仍然想冒风险,那么请参考Kalpesh在此建议的内容(但我不会推荐它)
答案 1 :(得分:3)
除了弄乱UIAlertView
之外,您应该使用自定义呈现(或模态)视图。 Apple也不喜欢你搞砸UIAlertView
。
所以,我(也是最好)的建议是使用自定义呈现(或模态)视图,这也是一种正确的方法。
答案 2 :(得分:3)
试试此代码
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Enter Student Name"
message:@""
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Save",@"Save & Add",nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
[alert show];
-(void)willPresentAlertView:(UIAlertView *)alertView {
if ([[[UIDevice currentDevice] systemVersion] floatValue] <7)
{
[alertView setFrame:CGRectMake(17, 30, 286, 280)];
NSArray *subviewArray = [alertView subviews];
UILabel *message = (UILabel *)[subviewArray objectAtIndex:2];
[message setFrame:CGRectMake(10, 46, 260, 20)];
UIButton *cancelbutton = (UIButton *)[subviewArray objectAtIndex:3];
[cancelbutton setFrame:CGRectMake(10, 125, 260, 42)];
UIButton *savebutton = (UIButton *)[subviewArray objectAtIndex:4];
[savebutton setFrame:CGRectMake(10, 170, 260, 42)];
UIButton *saveAddbutton = (UIButton *)[subviewArray objectAtIndex:5];
[saveAddbutton setFrame:CGRectMake(10, 220, 260, 42)];
UITextField *textfield = (UITextField *)[subviewArray objectAtIndex:6];
[textfield setFrame:CGRectMake(10, 80, 266, 50)];
UITextField *placeTF = (UITextField *)[subviewArray objectAtIndex:7];
[placeTF setFrame:CGRectMake(15, 70, 256, 50)];
}
}
检查ios 6图像
修改强>
对于旋转问题,请使用此代码
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
if (UIInterfaceOrientationPortrait == UIInterfaceOrientationIsPortrait(fromInterfaceOrientation))
{
[alert setFrame:CGRectMake(100, 10, 286, 320)];
NSArray *subviewArray = [alert subviews];
UILabel *messageLB = (UILabel *)[subviewArray objectAtIndex:2];
[messageLB setFrame:CGRectMake(10, 46, 260, 20)];
UIButton *cancelBT = (UIButton *)[subviewArray objectAtIndex:3];
[cancelBT setFrame:CGRectMake(10, 125, 260, 42)];
UIButton *okBT = (UIButton *)[subviewArray objectAtIndex:4];
[okBT setFrame:CGRectMake(10, 170, 260, 42)];
UIButton *searchBT = (UIButton *)[subviewArray objectAtIndex:5];
[searchBT setFrame:CGRectMake(10, 220, 260, 42)];
UITextField *plateTF = (UITextField *)[subviewArray objectAtIndex:6];
[plateTF setFrame:CGRectMake(10, 80, 266, 50)];
UITextField *placeTF = (UITextField *)[subviewArray objectAtIndex:7];
[placeTF setFrame:CGRectMake(15, 70, 256, 50)];
}
else{
[alert setFrame:CGRectMake(17, 30, 286, 280)];
NSArray *subviewArray = [alert subviews];
UILabel *messageLB = (UILabel *)[subviewArray objectAtIndex:2];
[messageLB setFrame:CGRectMake(10, 46, 260, 20)];
UIButton *cancelBT = (UIButton *)[subviewArray objectAtIndex:3];
[cancelBT setFrame:CGRectMake(10, 125, 260, 42)];
UIButton *okBT = (UIButton *)[subviewArray objectAtIndex:4];
[okBT setFrame:CGRectMake(10, 170, 260, 42)];
UIButton *searchBT = (UIButton *)[subviewArray objectAtIndex:5];
[searchBT setFrame:CGRectMake(10, 220, 260, 42)];
UITextField *plateTF = (UITextField *)[subviewArray objectAtIndex:6];
[plateTF setFrame:CGRectMake(10, 80, 266, 50)];
UITextField *placeTF = (UITextField *)[subviewArray objectAtIndex:7];
[placeTF setFrame:CGRectMake(15, 70, 256, 50)];
}
}
答案 3 :(得分:2)
你做错了是你正在尝试自定义UIAlertView并将子视图放入其中。 Apple一般不喜欢并禁止这种做法。 你可以尝试做的是:
您可以尝试自定义提醒 - 查看&#39;复制&#39; like this one
编写自己的复制&#39;警报视图将满足您的需求并在iOS6 / 7上运行相同。