HomeiDevBlogADayiOS7 UIPickerView Customization

Comments

iOS7 UIPickerView Customization — 4 Comments

  1. Finally, the same information i was looking for from hours. Have a question, what if we want to move all the same from numbers to alphabets.

  2. Easy:

    -(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
    {
    return 26; // 26 letters in the alphabet
    }

    -(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
    {
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, pickerView.frame.size.width, 44)];
    label.backgroundColor = [UIColor clearColor];
    label.textColor = [UIColor blackColor];
    label.font = [UIFont fontWithName:@"HelveticaNeue-Bold" size:18];
    label.text = [NSString stringWithFormat:@" %c", 65+row]; // ASCII 65 is "A"
    return label;
    }

  3. Cool, thanks. This picker is tricky indeed. Also if you want to center the numbers, here’s the code:

    UILabel *label = [[UILabel alloc] init];
    [label setTextAlignment:NSTextAlignmentCenter];

Leave a Reply

Your email address will not be published. Required fields are marked *

HTML tags allowed in your comment: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>