Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8575413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:41:21+00:00 2026-06-11T19:41:21+00:00

I made the UIPickerView and added to viewcontroller’view. I adjusted pickerview’width manually. As you

  • 0

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

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T19:41:22+00:00Added an answer on June 11, 2026 at 7:41 pm

    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

    - (void)pickerView:(UIPickerView *)pV didSelectRow:(NSInteger)row inComponent:(NSInteger)component
    {
        // you're code for when user select any item from picker
    }
    
    - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
    {
        return 2;
    }
    
    - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
    { 
        if(component == 0)
            return [activities count];
        else if(component == 1)
            return [feelings count];
        
    }
    
    - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
    {
        if(component == 0)
            return [activities objectAtIndex:row];
        else if(component == 1)
            return [feelings objectAtIndex:row];
        else
               return @"";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made a Tab Bar app and have added a UIPickerView in the
i made an .xib file and added my buttons and labels. Then I created
I made a button above a pickerView to dismiss it. and I think I
Made a new project, added main.cpp and wrote the code at this URL: http://www.boost.org/doc/libs/1_43_0/doc/html/boost_asio/example/echo/async_tcp_echo_server.cpp
I am using a UIScrollView with a list of buttons made to look much
I made a custom viewgroup, and I need to use view animation to rotate
Made It! Look at bottom of the post!!! Smart people of the world... I'm
I made this regex: /\<+[a-zA-Z0-9\=\\s]+\>+.+\<\/+[a-zA-Z0-9]+\>/gi which matches a full html tag like: <p>this is
I made a view to abstract columns of different tables and pre-filter and pre-sort
I need assistance. I made a UIPickerView that has a UITableview subview. I iterate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.