gpt4 book ai didi

ios - 初始化UIButton并将其放置在具有UIPickerView的UIActionSheet中

转载 作者:行者123 更新时间:2023-12-01 19:23:35 25 4
gpt4 key购买 nike

我正在通过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)];
}

最佳答案

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];

关于ios - 初始化UIButton并将其放置在具有UIPickerView的UIActionSheet中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8978436/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com