【问题标题】:Initial and place an UIButton in an UIActionSheet with an UIPickerView使用 UIPickerView 在 UIActionSheet 中初始化和放置 UIButton
【发布时间】:2012-01-23 20:56:44
【问题描述】:

我正在通过Add UIPickerView & a Button in Action sheet - How? 实现选择器。我试图用 UIButton 替换 UISegmentedControl 但它不起作用。有人能提醒我为什么 UIButton 不能在这里显示吗?

谢谢。

- (IBAction) makeButtonPressed: (id) sender;
{
    UIActionSheet *actionSheet = [[UIActionSheet alloc] init];
    [actionSheet setTitle:@"Select Make"];
    [actionSheet setActionSheetStyle:UIActionSheetStyleBlackOpaque];

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

//  UISegmentedControl *doneButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Done"]];
//  doneButton.momentary = YES; 
//  doneButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f);
//  doneButton.segmentedControlStyle = UISegmentedControlStyleBar;
//  doneButton.tintColor = [UIColor blackColor];
//  [doneButton addTarget:self action:@selector(makeDone:) forControlEvents:UIControlEventValueChanged];
//  [actionSheet addSubview:doneButton];

    UIButton *doneButton = [[UIButton alloc] init];
    doneButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f);
    [doneButton addTarget:self action:@selector(makeDone:) forControlEvents:UIControlEventValueChanged];
    [actionSheet addSubview:doneButton];

    [actionSheet showInView:[[UIApplication sharedApplication] keyWindow]];

    [actionSheet setBounds:CGRectMake(0, 0, 320, 460)];
}

【问题讨论】:

    标签: ios uibutton uipickerview subclass uiactionsheet


    【解决方案1】:

    UIButton 的指定初始化程序是+buttonWithType:。您应该使用其中一种预定义样式创建按钮,或使用UIButtonTypeCustom

    UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeRoundRect];
    doneButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f);
    [doneButton addTarget:self action:@selector(makeDone:) forControlEvents:UIControlEventValueChanged];
    [actionSheet addSubview:doneButton];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-24
      • 1970-01-01
      相关资源
      最近更新 更多