iPad actionsjeet

  • 在iphone和ipad上使用UIActionShee控件t的效果會不同,在蘋果的官方文檔中有相關說明:

在ipad上使用UIActionSheet控件改控件再也不從底部彈出,而是從屏幕中間彈出與UIAlertView警告框彈出有點相似。效果如圖所示,cancelButton按鈕文字顯示不出來,destructiveButtonTitle按鈕文字爲紅色加粗字體。微信

  • iOS 8.3之後再也不使用actionsheet,而是統一用UIAlertController,因此若是有iOS7的用戶,須要適配:
        //初始化actionsheet,適配 iOS 8.3 如下

        if([[UIDevice currentDevice].systemVersion floatValue] > 8.3){//iOS 8.3以上,廢棄舊版actionsheet
            UIAlertController* actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
            UIAlertAction *sendAction = [UIAlertAction actionWithTitle:@"發送Log文件給微信好友" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { [self SendLogToWechatFriends]; }]; [actionSheet addAction:sendAction]; actionSheet.popoverPresentationController.sourceView = _logoImgView; actionSheet.popoverPresentationController.sourceRect = _logoImgView.bounds; [actionSheet.popoverPresentationController setPermittedArrowDirections:UIPopoverArrowDirectionUp]; [self presentViewController:actionSheet animated:YES completion:nil]; }else{//iOS 8.3如下使用舊版actionsheet UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:@"發送Log文件給微信好友",nil]; actionSheet.actionSheetStyle = UIBarStyleDefault; actionSheet.delegate = self; [actionSheet showFromRect:[_logoImgView frame] inView:self.view animated:YES]; }
  • 爲了不適配,使用自定義的popovercontrolller,而後嵌入一個包着button的viewcontroller:
        UIViewController* actionSheet = [[UIViewController alloc]init];
        actionSheet.view.backgroundColor = [UIColor clearColor]; // UILabel* label = [[UILabel alloc]initWithFrame:CGRectMake((self.view.bounds.size.width-50)/4, 0, self.view.bounds.size.width-50, 50)]; // label.text = @"發送Log文件給微信好友"; // label.textColor = MttColorNamed(@"browser_startpage_news_category_color"); // [actionSheet.view addSubview:label];  UIButton* btn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width-50, 50)]; btn.backgroundColor =[UIColor clearColor]; [btn setTitle:@"發送Log文件給微信好友" forState:UIControlStateNormal]; btn.titleLabel.textAlignment = NSTextAlignmentCenter; [btn setTitleColor:MttColorNamed(@"browser_startpage_news_category_color") forState:UIControlStateNormal]; [btn addTarget:self action:@selector(SendLogToWechatFriends) forControlEvents:UIControlEventTouchUpInside]; [actionSheet.view addSubview:btn]; MttPopoverController *popController = [[MttPopoverController alloc] initWithContentViewController:actionSheet]; popController.popoverContentSize = CGSizeMake(self.view.bounds.size.width-50, 50); //popController.delegate = self;  [popController presentPopoverFromRect:_logoImgView.frame inView:self.view permittedArrowDirections:WYPopoverArrowDirectionUp animated:YES]; self.popoverController = popController;
  • button在設置title顏色的時候,注意狀態,「|」的意思是and,不是或

更多關於actionsheet,參考http://www.jianshu.com/p/4d1ca0d9a6f1iphone

相關文章
相關標籤/搜索