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;
}
}
}
}
As i am showing alertview with textfield and three buttons its working fine in ios 7 but not in ios 6 . have a look at both ios images -- >
as you all can see the alertview of ios 6 is disturbed ... but i am not getting what i am doing wrong there .
What you are doing wrong is you're trying to customize UIAlertView and put subviews into it. Apple generally dislikes and prohibits this approach. What you can try to do is the following:
You can try custom alert-view 'replication' like this one
Write your own 'replication' of alert-view that will fit your needs and work the same on both iOS6/7.
In stead of messing with
UIAlertView
, you should use a custom presented (or a modal) view. Apple also doesn't like you to mess up withUIAlertView
.So, my (and also the best) suggestion for you is to go with a custom presented (or a modal) view which is also a correct approach in your case also.
Try this code
Check for ios 6 image
EDIT
For rotation problem use this code
I tried it here as well and it seems the style "UIAlertViewStylePlainTextInput" doesn't go well with 3 or more buttons in the UIAlertView.
your issue seems to be directly related to this:
iOS5: Has somebody managed to fix UIAlertView with three buttons and textfield (UIAlertViewStylePlainTextInput)?
It it won't be advisable to mess around with UIAlertView's view hierarchy (since some state App Store rejections)
refer: How to Move buttons down in UIAlertView
You can create your own custom alertView:
http://iosdevtricks.blogspot.in/2013/04/creating-custom-alert-view-for-iphone.html
or use a premade one, something like:
https://github.com/TomSwift/TSAlertView
if you still want to risk it, then go with what Kalpesh has suggested here (but i won't recommend it)