2012-09-18 20 views
8

Sto cercando di cambiare l'altezza di pickerViewUIPickerView Altezza non modificabile

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

registro Xcode mostra il seguente messaggio:

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

Come posso cambiare la sua altezza?

+0

non è possibile modificare l'altezza di UIPickerView. –

+0

Su iOS 9 tutto è cambiato! http://stackoverflow.com/a/35562894/8047 –

risposta

29

qui sono solo threevalidheights per UIPickerView(162.0, 180.0 and 216.0).

È possibile utilizzare le funzioni CGAffineTransformMakeTranslation e CGAffineTransformMakeScale per adattarsi correttamente al selettore.

Esempio:

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

Il codice sopra change la height di pickerview to half e re-position alla esatta (Left-x1, Top-y1) posizione.

Ulteriori informazioni here.

4

Ci sono solo tre altezze valide per UIPickerView (162.0, 180.0 and 216.0).

More detail.

1

Ci sono solo tre valori validi 162,0, 180,0 e 216,0 per l'altezza dell'UIPicker. anche se si imposta un'altezza diversa, si imposta l'altezza su una delle tre altezze più vicine alla propria altezza.

0

Provare così. Ho anche cercato su Google così tanti esempi e ho trovato questo.

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