UIAlertView、UIActionSheet兼容iOS8

一、前言

iOS8添加 UIAlertController代替UIAlertView、UIActionSheet的使用。

本文在不使用UIAlertController的狀況下,用最簡單的方法讓UIAlertView、UIActionSheet兼容iOS8.spa


二、UIAlertView

iOS8下,假設 UIAlertView初始化的時候title爲nil的話。iOS8如下彈框中message會變成粗體。並且過於靠近頂部。爲了保存跟iOS8以前的版本號一致,僅僅需要在初始化的時候將title置爲@""就可以了。代碼例如如下:
//title置爲@""兼容iOS8
    UIAlertView *delAlert = [[[UIAlertView alloc] initWithTitle:@"" message:@"刪除聯繫人?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"確認", nil] autorelease];
    [delAlert show];

三、UIActionSheet

iOS8下,假設 UIActionSheet初始化的時候title爲@""的話,iOS8如下ActionSheet表單上方會多出一行空白欄。爲了保存跟iOS8以前的版本號一致。僅僅需要在初始化的時候將title置爲nil就可以了。代碼例如如下:
UIActionSheet *actionSheet = [[[UIActionSheet alloc] initWithTitle:nil
                                                              delegate:self
                                                     cancelButtonTitle:NSLocalizedString(@"Cancel", nil)
                                                destructiveButtonTitle:[NSString stringWithFormat:NSLocalizedString(@"call", nil),self.phoneNumber]
                                                     otherButtonTitles:NSLocalizedString(@"add to contact", nil),nil]
                                  autorelease];
    actionSheet.tag = 1;
    [actionSheet showInView:self.view];


版權聲明:本文博客原創文章,博客,未經贊成,不得轉載。code

相關文章
相關標籤/搜索