【发布时间】:2015-11-02 22:15:13
【问题描述】:
我有一个应用程序,它使用 UIPickerView 设置与图形系列的线型有关的各种参数(线宽、颜色和线型)。此选择器用于表视图行。我已经为选择器定义了框架,以便它的宽度填充单元格的 contentView 成员的宽度。直到 iOS 9,这似乎工作。在 iOS 9 中,UIPickerView 的宽度似乎有某种最大上限。有没有人遇到过类似的情况?
选择器视图是这样创建的:
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 点)
【问题讨论】:
-
我仍然不知道是什么原因造成的,但我已经找到了使用三个选择器视图而不是一个包含三个组件的选择器视图的解决方法。
标签: ios uitableview ios9 uipickerview