[英]Initial and place an UIButton in an UIActionSheet with an UIPickerView
我通过在操作表中添加UIPickerView和按钮来实现选择器-怎么做? 。 我试图用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];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.