Custom UIalertView in iOS5

醉酒当歌 提交于 2020-01-05 08:42:31

问题


Do anywho know a custom UIAlertView class what is working in iOS5 ? I'm looking for a class like TSAlertView, with that I will able to put 2 buttons stacked into alert. ( http://cocoacontrols.com/platforms/ios/controls/tsalertview )

Thanx for help.


回答1:


UIAlertView in iOS 5 has UIAlertViewStyles

UIAlertViewStyleDefault
UIAlertViewStyleSecureTextInput
UIAlertViewStylePlainTextInput
UIAlertViewStyleLoginAndPasswordInput

EDIT Sorry for misunderstanding your problem. The alert view shown in the linked page is extremely easy to reproduce. Here's what I came up with:

I implemented this with a category for convenience but you could easily just implement it elsewhere. Basically what you do is add a cancel button and then hide it. That way there are three buttons as far as the alert view is concerned and it does not place the two visible buttons side by side. The category implementation is as follows:

-(void)showWithCutCancelButton{
    // Make sure alert view will look right
    if (self.cancelButtonIndex == -1 || self.numberOfButtons < 3) return;
    self.clipsToBounds = YES; // or else cancel button will still be visible
    [self show];
    // Shrink height to leave cancel button outside
    self.bounds = CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height - 64);
} 

Then you show this by calling:

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Hello" message:@"Message here" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Option1", @"Option2", nil];
[alert showWithCutCancelButton];


来源:https://stackoverflow.com/questions/8272065/custom-uialertview-in-ios5

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!