请找到下面的代码,我试图添加工具栏到uipicker,但它不起作用
请让我知道
UIPickerView *pickerViewCountry = [[UIPickerView alloc] init];
pickerViewCountry.showsSelectionIndicator = YES;
pickerViewCountry.dataSource = self;
pickerViewCountry.delegate = self;
pickerViewCountry.autoresizingMask = (UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight);
[pickerViewCountry sizeToFit];
pickerViewCountry.frame = CGRectMake(0,210 , 320, 15);
[self.view addSubview:pickerViewCountry];
//[pickerViewCountry release];
UIToolbar *toolbar = [[UIToolbar alloc] init];
toolbar.frame = CGRectMake(10,200, 320, 44);
toolbar.barStyle = UIBarStyleBlackTranslucent;
[pickerViewCountry addSubview:toolbar];
[toolbar release];发布于 2011-12-24 13:44:51
当你调用时:
toolbar.frame = CGRectMake(10,200, 320, 44);CGRect是相对于选取器视图的(如果您通过addSubview连接到pickerViewCountry),因此位置不会与选取器视图的顶部对齐,而是在选取器视图之外的右下角的某个位置对齐,因此不会显示。
你想要达到什么目的?您可能不想向UIPickerView添加UIToolbar。相反,您可以尝试将UIToolbar添加到主视图中。
[self.view addSubview: toolbar];并保持toolbar.frame = CGRectMake(10,200, 320, 44);的原样。
发布于 2011-12-24 13:40:09
由于您要将工具栏作为子视图添加,因此我相信CGRectMake的X和Y坐标将相对于pickerViewCountry框架。尝试设置以下行:
toolbar.frame = CGRectMake(10,200, 320, 44);对于这一条:
toolbar.frame = CGRectMake(0,0, 320, 44);我还没有尝试过,所以我还不确定是否真的是这样。我会试一试,如果到那时还没有其他人响应,我会告诉你。
发布于 2011-12-24 13:57:18
你可以做不同的事情来解决这个问题。
toolbar.frame = CGRectMake(10,-44, 320, 44);https://stackoverflow.com/questions/8622923
复制相似问题