2015-04-23 85 views
3

如何自定義UIPickerView的高度超過250。我也做了以下,但無法得到高度給出如何自定義UIPickerView高度

-(void)pickerview:(id)sender 
    { 
     pickerView=[[UIPickerView alloc] initWithFrame:CGRectMake(0,200,320,400)]; 
     pickerView.transform = CGAffineTransformMakeScale(0.75f, 0.75f); 
     pickerView.delegate = self; 
     pickerView.dataSource = self; 
     pickerView.showsSelectionIndicator = YES; 
     pickerView.backgroundColor = [UIColor lightGrayColor]; 
     [pickerView selectRow:1 inComponent:0 animated:YES]; 
     [self.view addSubview:pickerView]; 
     // [contentView addSubview:pickerView]; 

    } 

回答

7

這裏只有三個有效高度爲UIPickerView(162.0,180.0和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)); 

上面的代碼變化選擇器視圖的高度的一半,並將其重新定位到準確的(左-X1,頂-Y1)位置。

請參閱這裏。 How to change UIPickerView height