I made the UIPickerView and added to viewcontroller’view.
I adjusted pickerview’width manually.
As you look at the picture, not matches between component’s contents width and component width, and
pickerview’s width and components width.
Is there a method like UILabel’s 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;
}
}

try my solution..i have never set the width & height of each component…UIPickerview maintain itself…so i don’t have to worry about this….try this just Comment the whole method called “widthForComponent” and make sure you have used all these Picker methods propely..”numberOfComponentsInPickerView”,”numberOfRowsInComponent” and “titleForRow” then run the project again…let me know it will solved your problem or not
ok now see the following methods are required with uipickerview…you want some code then here it is