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