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 8159027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:47:26+00:00 2026-06-06T17:47:26+00:00

I don’t have any idea how can I create a custom UIPickerView with an

  • 0

I don’t have any idea how can I create a custom UIPickerView with an image on the side of the text.

I’ve been searching for a method and I just found this:

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row
forComponent:(NSInteger)component reusingView:(UIView *)view

But I don’t know how I can use that.

These are my arrays:
All works perfectly, I just want to put a diferent image in each row, with 10 different colors.
The colors will be the same for the 3 components but different in each row.
like this image. LINK!!!

- (void)viewDidLoad
{
    [super viewDidLoad];

    Colores1 = [[NSMutableArray alloc] init];
    [Colores1 addObject:@"Negro"];
    [Colores1 addObject:@"Marrón"];
    [Colores1 addObject:@"Rojo"];
    [Colores1 addObject:@"Naranja"];
    [Colores1 addObject:@"Amarillo"];
    [Colores1 addObject:@"Verde"];
    [Colores1 addObject:@"Azul"];
    [Colores1 addObject:@"Violeta"];
    [Colores1 addObject:@"Gris"];
    [Colores1 addObject:@"Blanco"];

    Colores2 = [[NSMutableArray alloc] init];
    [Colores2 addObject:@"Negro"];
    [Colores2 addObject:@"Marrón"];
    [Colores2 addObject:@"Rojo"];
    [Colores2 addObject:@"Naranja"];
    [Colores2 addObject:@"Amarillo"];
    [Colores2 addObject:@"Verde"];
    [Colores2 addObject:@"Azul"];
    [Colores2 addObject:@"Violeta"];
    [Colores2 addObject:@"Gris"];
    [Colores2 addObject:@"Blanco"];

    Colores3 = [[NSMutableArray alloc] init];
    [Colores3 addObject:@"Negro"];
    [Colores3 addObject:@"Marrón"];
    [Colores3 addObject:@"Rojo"];
    [Colores3 addObject:@"Naranja"];
    [Colores3 addObject:@"Amarillo"];
    [Colores3 addObject:@"Verde"];
    [Colores3 addObject:@"Azul"];
    [Colores3 addObject:@"Violeta"];
    [Colores3 addObject:@"Gris"];
    [Colores3 addObject:@"Blanco"];
}

this is my uipickerview:

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 3;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{

    if(component == Primbanda)
        return [Colores1 count];
    if(component == Segubanda)
        return [Colores2 count];
    if (component == tercbanda)
        return [Colores3 count];
    return 0;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    if(component == Primbanda)
        return [Colores1 objectAtIndex:row];
    if(component == Segubanda)
        return [Colores2 objectAtIndex:row];
    if (component == tercbanda) 
        return [Colores3 objectAtIndex:row];
    return 0;

}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    NSLog(@"Row is:%d Component is:%d",row,component);

    int a;//entero de componente 1
    int b;//entero de componente 2
    double c;//entero de componente 3
    double resultado;
    int d; //valor de componente 1 y 2
    NSString *a1; //cadena de a y b!

    a = [pickerView selectedRowInComponent:0]; //asigno a las variables segun el numero!! 
    b = [pickerView selectedRowInComponent:1];

    switch ([pickerView selectedRowInComponent:2]) { //asi se le asignan valores propios!
        case 0:
            c=1;
            break;
        case 1:
            c=10;
            break;
        case 2:
            c=100;
            break;
        case 3:
            c=1000;
            break;
        case 4:
            c=10000;
            break;
        case 5:
            c=100000;
            break;
        case 6:
            c=1000000;
            break;
        case 7:
            c=10000000;
            break;
        case 8:
            c=100000000;
            break;
        case 9:
            c=1000000000;
            break;
        default:
            break;
    }
    NSLog(@"El valor de la tercera es ;%f",c);
    a1 = [[NSString alloc]initWithFormat:@"%d%d",a,b]; //junto las variables a y b
    d= [a1 intValue];    //guardo en la variable
    NSLog(@"el valor de C multiplicado es %f",c);

    resultado = d*c; //multiplica ab por el valor de c

    NSLog(@"valor de resistencia es %.0f Ohms",resultado); //awebo! me salio! :D

    labelresultado.text = [[NSString alloc]initWithFormat:@"%.0f",resultado];

}
  • 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-06T17:47:28+00:00Added an answer on June 6, 2026 at 5:47 pm

    From the UIPickerViewDelegate docs

    pickerView:viewForRow:forComponent:reusingView:
    
    Called by the picker view when it needs the view to use for a given row in a given component.
    - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
    Parameters
    
    pickerView
    
        An object representing the picker view requesting the data.
    row
    
        A zero-indexed number identifying a row of component. Rows are numbered top-to-bottom.
    component
    
        A zero-indexed number identifying a component of pickerView. Components are numbered left-to-right.
    view
    
        A view object that was previously used for this row, but is now hidden and cached by the picker view.
    

    The important thing here is the view that is returned, which is the view that is used to display the contents for that row on the picker view, and is where you want to add any images you want.

    First you have to implement the delegate method, and declare it in your .h like this:

    MyClass <UIPickerViewDelegate>
    

    in your .m

    myUIPickerObject.delegate = self;
    

    then implement the method like this:

    - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
    {
        UIView *myColorView = [UIView new]; //Set desired frame
        myColorView.backgroundColor = [UIColor redColor]; //Set desired color or add a UIImageView if you want...
        UIImageView *myImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:"myImage.png"]];
        [view addSubview:myImageView];
        [view addSubview:myColorView];
    
        //Add subview retains view, so OK to release now
        [myImageView release];
        [myColorView release];
    
        return view;
    }
    

    Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't know if this has been answered before. Have custom routes to users. If
Don't have much to say, just can get into the event handler. XAML: <Grid>
I don't have any experience in updating a Rails app and when I google
Don't ask me why but i can't use this method because I need to
Don't know why but I can't find a solution to this. I have 3
(Don't know if this is strictly on-topic, but I don't see any better Stack
Don't know if this has been asked before, so point me to another question
Don't know if anyone can help me with this or if it's even possible.
Don't be afraid to use any technical jargon or low-level explanations for things, please.
Don't they both have to convert to machine code at some point to execute

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.