2012-09-18 95 views
8

我試圖改變PickerView的高度UIPickerView高度不能改變

self.pickerView = [[UIPickerView alloc] init]; 
self.pickerView.frame = CGRectMake(0, 0, frame.size.width, frame.size.height); 

Xcode的日誌顯示以下信息:

-[UIPickerView setFrame:]: invalid height value 274.0 pinned to 216.0 

我怎樣才能改變其高度?

+0

你不能改變UIPickerView的高度。 –

+0

在iOS 9上,一切都變了! http://stackoverflow.com/a/35562894/8047 –

回答

29

這裏只threevalidheightsUIPickerView(162.0, 180.0 and 216.0)

您可以使用CGAffineTransformMakeTranslationCGAffineTransformMakeScale函數來正確適合選擇器以方便您。

實施例:

CGAffineTransform t0 = CGAffineTransformMakeTranslation (0, pickerview.bounds.size.height/2); 
CGAffineTransform s0 = CGAffineTransformMakeScale  (1.0, 0.5); 
CGAffineTransform t1 = CGAffineTransformMakeTranslation (0, -pickerview.bounds.size.height/2); 
pickerview.transform = CGAffineTransformConcat   (t0, CGAffineTransformConcat(s0, t1)); 

上面的代碼changepickerview to halfre-positionheight的確切位置(Left-x1, Top-y1)

查看更多here

1

UIPicker的高度只有三個有效值162.0,180.0和216.0。即使您設置了不同的高度,它也會將高度設置爲這三個高度中最接近您給定高度的高度。

0

試試這個。我也搜索了很多例子,並找到了這個例子。

pickerView = [[UIPickerView alloc]initWithFrame:CGRectMake(0,250,320,230)];//to change the height 
pickerView.delegate =self; 
pickerView.dataSource =self; 
pickerView.showsSelectionIndicator = YES; 
[self.view addSubview:pickerView];