MapMapM 2013-04-19 03:23 采纳率: 0%
浏览 2944
已采纳

actionSheet imageView的边界

需要在actionsheet修改imageView的边界属性:

<!-- language: lang-c -->

        #pragma UIActionSheetDelegate Methods
        - (void)willPresentActionSheet:(UIActionSheet *)actionSheet {
           /*[[[actionSheet valueForKey:@"_buttons"] objectAtIndex:0] imageView].frame = CGRectMake(0, 0, 25.0f, 25.0f);*/

           [[[actionSheet valueForKey:@"_buttons"] objectAtIndex:0] imageView].bounds = CGRectMake(0, 0, 25.0f, 25.0f);

           /*UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 25.0f, 25.0f)];
           imgView.image = [UIImage imageNamed:@"symbol-pin.png"];
           [[actionSheet superview] addSubview:imgView];*/ 
    }

然后在编码之后什么也出现:

[[[actionSheet valueForKey:@"_buttons"] objectAtIndex:0] imageView].bounds = CGRectMake(0, 0, 25.0f, 25.0f);

创建actionsheet的代码:

<!-- language: lang-c -->

    - (IBAction)showModeOptions:(id)sender {
       if (!modeOptions) {
         modeOptions = [[UIActionSheet alloc]initWithTitle:@"" delegate:self cancelButtonTitle:@"Abbrechen" destructiveButtonTitle:nil otherButtonTitles:@"Pin",@"Linie", @"Polygon", nil];

          [[[modeOptions valueForKey:@"_buttons"] objectAtIndex:0] setImage:[UIImage imageNamed:@"symbol-pin.png"] forState:UIControlStateNormal];

          [[[modeOptions valueForKey:@"_buttons"] objectAtIndex:1] setImage:[UIImage imageNamed:@"symbol-line.png"] forState:UIControlStateNormal];

          [[[modeOptions valueForKey:@"_buttons"] objectAtIndex:2] setImage:[UIImage imageNamed:@"symbol-polygon.png"] forState:UIControlStateNormal];

          modeOptions.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
      }
      [modeOptions showFromTabBar:self.tabBarController.tabBar]; 
}

图片是88*88px的,我需要图片像imageView是25*25px的边框。不知道应该怎么实现?

  • 写回答

1条回答 默认 最新

  • vikeyToy 2013-04-19 05:40
    关注
    -(void)actionSheetClicked
    {
    
    if(!self.modeOptions)
        {
            UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Dummy",nil]; //Here I add dummy button for getting cancel button style.
            self.modeOptions = actionSheet;
            [actionSheet release];
        }
        self.modeOptions.actionSheetStyle = UIActionSheetStyleBlackOpaque;
    
    
        [self.modeOptions showFromTabBar:self.tabBarController.tabBar];//Here i show from tab bar, you can showfromview also
    //    [self.modeOptions setBounds:CGRectMake(0, 0, 320, 300)];
        UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
        if (orientation == UIInterfaceOrientationPortrait ||
            orientation == UIInterfaceOrientationPortraitUpsideDown)//frame size for action sheet in both modes
        {
            [self.modeOptions setBounds:CGRectMake(0, 0, 320, 300)];
    
        }
        else
        {
            [self.modeOptions setBounds:CGRectMake(0, 0, 480,250)];
        }
        UIButton *buttonDum = (UIButton *)[[self.modeOptions subviews] objectAtIndex:0];
    
        [buttonDum setHidden:YES];//hide dummy button..
    
        UIButton *cancelButton = (UIButton *)[[self.modeOptions subviews] objectAtIndex:1];
    
        if( !self.button1)
        {
    
            UIButton *Btn = [[UIButton alloc]initWithFrame:CGRectMake(80, 40, 70, 70)];//**Here I use 70 X 70 px image , you can edit it**
            self.button1 = Btn;
            [self.button1 addTarget:self action:@selector(invokeFirstBtn) forControlEvents:UIControlEventTouchUpInside];
            [self.button1 setImage:[UIImage imageNamed:@"btn1Image.png"] forState:UIControlStateNormal];
            [self.modeOptions addSubview:self.button1];
            [Btn release];
        }
        if( !self.button2)
        {
            UIButton *Btn = [[UIButton alloc]initWithFrame:CGRectMake(180, 40, 70, 70)];//**Here I use 70 X 70 px image , you can edit it**
            self.button2 = sharBtn;
            [self.button2 addTarget:self action:@selector(invokeButton2) forControlEvents:UIControlEventTouchUpInside];
            [self.button2 setImage:[UIImage imageNamed:@"btn2Image.png"] forState:UIControlStateNormal];
            [self.modeOptions addSubview:self.button2];
            [Btn release];
        }
        if (orientation == UIInterfaceOrientationPortrait ||
            orientation == UIInterfaceOrientationPortraitUpsideDown)//frame size for action sheet in both modes
        {
            cancelButton.frame = CGRectMake(50, 140, 220, 40);
            self.button1.frame = CGRectMake(65, 40, 70, 70);
            self.button2.frame = CGRectMake(175, 40, 70, 70);
        }
        else
        {
            cancelButton.frame = CGRectMake(135, 140, 220, 40);
            self.button1.frame = CGRectMake(155, 40, 70, 70);
            self.button2.frame = CGRectMake(260, 40, 70, 70);
        }
    }
    

    用这段代码,可以随意修改框架尺寸,还可以创建不带虚拟按钮的actionsheet。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 聚类分析或者python进行数据分析
  • ¥15 如何用visual studio code实现html页面
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?