• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

iphone - 将 UIPickerView 添加到 UIActionSheet(底部的按钮)

[复制链接]
菜鸟教程小白 发表于 2022-12-13 02:24:05 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我想要

  1. 显示选择器 View (向上滑动)
  2. 在可见时停用背景
  3. 在底部(而不是顶部)显示 (UIActionSheet) 按钮

起初在我看来这是一个简单的解决方案,因为您可以在网络上的任何地方找到将选择器 View 添加到操作表的代码,但所有解决方案都将按钮放在顶部,我需要将按钮放在操作表的底部(对齐?)

这可能吗?我想如果我看一下:Example

问候

杰文

已编辑(我的解决方案基于 coded dads 解决方案)

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil
                                                             delegate:nil
                                                    cancelButtonTitle:nil
                                               destructiveButtonTitle:nil
                                                    otherButtonTitles:nil];
    [actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];

    CGRect pickerFrame = CGRectMake(0, 0, 0, 0);
    UIPickerView *pickerView = [[UIPickerView alloc]initWithFrame:pickerFrame];
    pickerView.showsSelectionIndicator = YES;
    pickerView.dataSource = self;
    pickerView.delegate = self;

    UISegmentedControl *backButton =  [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects"Back", nil]] ;
    [backButton addTarget:self actionselector(someFunction forControlEvents:UIControlEventValueChanged];
    backButton.tintColor = [UIColor colorWithRed:0.10 green:0.20 blue:0.52 alpha:0.5];
    backButton.segmentedControlStyle = UISegmentedControlStyleBar;
    [backButton addTarget:self actionselector(btnActionCancelClicked forControlEvents:UIControlEventAllEvents];
    backButton.frame = CGRectMake(20.0, 220.0, 280.0, 40.0);

    UISegmentedControl *acceptButton =  [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects"Accept", nil]] ;
    [acceptButton addTarget:self actionselector(anotherFunction forControlEvents:UIControlEventValueChanged];
    acceptButton.tintColor = [UIColor colorWithRed:0.10 green:0.20 blue:0.52 alpha:0.5];
    acceptButton.segmentedControlStyle = UISegmentedControlStyleBar;
    acceptButton.frame = CGRectMake(20.0, 280.0, 280.0, 40.0);

    [actionSheet addSubview:pickerView];
    [actionSheet addSubview:backButton];
    [actionSheet addSubview:acceptButton];

    [actionSheet showInView:[[UIApplication sharedApplication] keyWindow]];
    [actionSheet setFrame:CGRectMake(0,150,320, 400)]; 

...然后只需应用 iPhone 5/iphone 4 相关 View 大小约束

编辑 2: 只是另一个提示!最初我想使用标准的 Actionsheet,但不想将pickerview 放在底部。我没有找到如何移动按钮的方法。显然它非常简单:Add UIView as subView on UIActionSheet很高兴知道;)



Best Answer-推荐答案


你有两种可能:

选项 1:大调整。

ActionSheet 以初始化期间定义的顺序显示按钮。所以在顶部放置一些虚拟按钮,取消将是唯一可见的,所有其他按钮将被选择器 View 隐藏。代码(otherButtonTitles 的警告调整):

UIActionSheet *menu = [[UIActionSheet alloc] initWithTitle"Actionsheet"
                                                  delegate:self
                                         cancelButtonTitle"Cancel"
                                    destructiveButtonTitle:nil
                                         otherButtonTitles"1", @"2", @"3", @"4", nil];

UIPickerView *pickerView = [[UIPickerView alloc] init];
pickerView.delegate = self;
pickerView.dataSource = self;

[menu addSubview:pickerView];
[menu showInView:self.view];
[menu setBounds:CGRectMake(0,0,320, 500)];

CGRect pickerRect = pickerView.bounds;
pickerRect.origin.y = 35;
pickerView.frame = pickerRect;

选项2:自制

menu = [[UIActionSheet alloc] initWithTitle"Actionsheet"
                                                  delegate:self
                                         cancelButtonTitle:nil
                                    destructiveButtonTitle:nil
                                         otherButtonTitles:nil];

UIPickerView *pickerView = [[UIPickerView alloc] init];
pickerView.delegate = self;
pickerView.dataSource = self;
CGRect pickerRect = pickerView.bounds;
pickerRect.origin.y = 35;
pickerView.frame = pickerRect;

UIButton *startbtn = [UIButton buttonWithType:UIButtonTypeCustom];
startbtn.frame = CGRectMake(80,230, 170, 73);
[startbtn setBackgroundImage:[UIImage imageNamed"yourbutton.png"] forState:UIControlStateNormal];
[startbtn addTarget:self action:@selector(pressedbuttonCancel forControlEvents:UIControlEventTouchUpInside];

[menu addSubview:pickerView];
[menu addSubview:startbtn];
[menu showInView:self.view];
[menu setFrame:CGRectMake(0,150,320, 350)];

检查选项 2 的按钮是否应该在操作表上,除非点击不会被分派(dispatch)到选择器方法。

关于iphone - 将 UIPickerView 添加到 UIActionSheet(底部的按钮),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16122487/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap