码迷,mamicode.com
首页 > 其他好文 > 详细

iPad actionsjeet

时间:2017-04-28 10:23:30      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:uicolor   sage   delegate   over   get   uiview   start   style   按钮   

  • 在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,不是或

iPad actionsjeet

标签:uicolor   sage   delegate   over   get   uiview   start   style   按钮   

原文地址:http://www.cnblogs.com/lucky-star-star/p/6780142.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!