【问题标题】:Create a custom uiView like UiActionSheet in ios在 ios 中创建像 UiActionSheet 这样的自定义 uiView
【发布时间】:2016-05-23 12:19:47
【问题描述】:

我想显示一个 ActionSheet 以在地图上显示一个创建帐户我可以通过使用 ShowFromRect 方法在 ipad 中实现这一点,但是 ShowFromRect 的行为没有为 Iphone 定义,或者它具有默认的行为,即它从视图底部弹出但是我想在用户单击地图的任何位置在地图上显示 ActionSheet。我该如何实施?还是我必须创建一个自定义 UIView,如 UIActionSheet,箭头指向用户在地图上选择的位置。如果是这样,我该如何为此目的创建自定义 UIView? 我附上了一张演示图片来展示我想要的样子。

【问题讨论】:

    标签: ios objective-c iphone uiview uiactionsheet


    【解决方案1】:

    这个解决方案可能对您有所帮助...我在某处读到此内容..您可以使用操作表来执行此操作。 首先在界面声明一个uiactionsheet的属性。在下面的示例中,我声明了一个名为 countryActionSheet 的属性。

    然后在 IBaction 中跟随代码;

     -(IBAction)popupView{//  declare another actionSheet //
    UIActionSheet *actionSheet =[[UIActionSheet alloc]initWithTitle:@"Select Country"       delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles: nil];
    
    countryActionsheet=actionSheet;//equate both the actionSheets//
    
    actionSheet.actionSheetStyle= UIActionSheetStyleBlackTranslucent;
    countryPicker.dataSource=self;
    countryPicker.delegate=self; 
    
    // Add your view with frame with respect to actionSheet//
    
    UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 400)];
    imageView.image=[UIImage imageNamed:@"black background.png"];
    
    UIButton *cancelBtn=[[UIButton alloc]initWithFrame:CGRectMake(200,20, 80, 30)];
    [cancelBtn setTitle:@"Cancel" forState:UIControlStateNormal];
    [cancelBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [cancelBtn addTarget:self action:@selector(cancelBtnPressed) forControlEvents:UIControlEventTouchUpInside];// create a method named cancelBtnPressed
    [cancelBtn setBackgroundImage:[UIImage imageNamed:@"Untitled 4.png"] forState:UIControlStateNormal];
    
    UIButton *okBtn =[[UIButton alloc]initWithFrame:CGRectMake(40, 20, 80, 30)];
    [okBtn setTitle:@"Done" forState:UIControlStateNormal];
    [okBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [okBtn addTarget:self action:@selector(okBtnPressed) forControlEvents:UIControlEventTouchUpInside];// create method named okBtnPressed
    [okBtn setBackgroundImage:[UIImage imageNamed:@"Untitled 4.png"] forState:UIControlStateNormal];
    
    
    [countryActionsheet addSubview:imageView];
    [countryActionsheet addSubview:cancelBtn];
    [countryActionsheet addSubview:okBtn];
    
    [countryActionsheet showInView:self.view];
    [countryActionsheet setBounds:CGRectMake(0, 0, 320, 400)];// frame of actionSheet
    }
    
    -(void)cancelbtnPressed{
         // write action
    }
    
    -(void)okBtnPressed{
         // write action
    }
    

    希望对你有所帮助;

    【讨论】:

    • 让我知道..你解决了你的问题吗..@Nikhil
    猜你喜欢
    • 2015-03-22
    • 2012-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多