我制作了 UIPickerView 并添加到 viewcontroller'view 中。
我手动调整了pickerview的宽度。
当您查看图片时,组件的内容宽度和组件宽度之间不匹配,并且
pickerview 的宽度和组件宽度。
有没有像 UILabel 的 sizeToFit 这样的方法?
expected code is :
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component {
switch(component) {
[pickerView.label sizeToFit];
}
}
================= Following is mycode ====================================================
- (void)viewDidLoad {
self.view.backgroundColor = [UIColor scrollViewTexturedBackgroundColor];
[super viewDidLoad];
UIPickerView *pickerView = [[[UIPickerView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)] autorelease];
pickerView.dataSource = self;
pickerView.delegate = self;
pickerView.showsSelectionIndicator = YES;
[self.view addSubview:pickerView];
activities = [[NSArray alloc] initWithObjects:@"sleeping", @"eating", @"working", @"studying", @"walking", @"thinking", @"considering", @"testing", @"talking", nil];
feelings = [[NSArray alloc] initWithObjects:@"awesome", @"sad", @"happy", nil];
}
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component {
switch(component) {
case 0: return 100;
case 1: return 200;
}
}