2015-11-02 21 views
1

我有一個應用程序使用UIPickerView設置圖形系列(線寬,顏色和線條樣式)的線條樣式的各種參數。此選取器用於表格視圖行。我爲拾取器定義了框架,以便其寬度填充單元格的contentView成員的寬度。直到iOS 9,這似乎工作。在iOS 9中,UIPickerView的寬度似乎有某種最大上限。有沒有人遇到類似這樣的事情?iOS中的UIPickerView最大寬度9

拾取器視圖正在創建這樣的:

self.picker = [[[UIPickerView alloc] init] autorelease]; 
[self.contentView addSubview:self.picker]; 
self.picker.dataSource = self; 
self.picker.delegate = self; 
self.picker.backgroundColor = [UIColor grouped_table_view_background_colour]; 

小區被奠定列如下:

-(void) layoutSubviews 
{ 
    // we need to allow the base class to perform its layout. 
    static CGFloat left_margin = 40; 
    static CGFloat right_margin = 40; 
    CGSize my_size; 
    [super layoutSubviews]; 
    my_size = self.contentView.bounds.size; 
    my_size.width -= left_margin + right_margin; 

    // we now need to lay out the views. 
    CGRect picker_rect = CGRectMake(left_margin, 5, my_size.width, my_size.height); 
    self.picker.frame = picker_rect; 

    // we want to look at the bounds of the picker 
    CGRect picker_bounds = self.picker.bounds; 
    NSLog(@"picker bounds x=%g, y=%g, w=%g, h=%g", picker_bounds.origin.x, picker_bounds.origin.y, picker_bounds.size.width, picker_bounds.size.height); 
} 

我也重載widthForComponent方法如下:

-(CGFloat) pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component 
{ 
    // we want to look at the bounds of the picker 
    CGRect picker_bounds = self.picker.bounds; 
    NSLog(@"picker bounds x=%g, y=%g, w=%g, h=%g", picker_bounds.origin.x, picker_bounds.origin.y, picker_bounds.size.width, picker_bounds.size.height); 
    return picker_bounds.size.width/3; 
} 

我可以看到,視圖的邊界正確顯示在值都是記錄以及視圖的背景顏色。儘管如此,拾取器似乎填充的寬度還不到可用寬度的一半(我的iPad上有688個點)。

+0

我仍然不知道是什麼導致這種情況,但已經觸及使用三個選擇器視圖而不是三個組件的一個選擇器視圖的解決方法。 –

回答

1

[[UIPickerView alloc] init]之後拾取器的尺寸爲{320,216},此尺寸將用於pickerView:widthForComponent:。如果您之後只是調整選取器的大小,那麼函數pickerView:widthForComponent:將不會再被調用,所以組件會停留在它們的寬度上。

嘗試初始化選擇器具有正確大小如.. picker=[[UIDatePicker new] initWithFrame:CGRectMake(0.0, 0.0, CGRectGetWidth(self.view.bounds), 216.0)];

或致電[self.picker setNeedsLayout]更改拾取框強制pickerView:widthForComponent:再次調用之後。