0

I am using UIPicker in one of my project.

I have UIPickerView of size & position as

 58, 264, 204, 216
  x   y  width height

I am doing iOS 7 compatible app.

in iOS 7, I want to show of width 204 only, but in iOS 6 and earlier version, I want to show of width 300.

For this below is what I did.

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

    if (IS_DEVICE_RUNNING_IOS_7_AND_ABOVE()) {
    NSLog(@"changing font...");
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 204, 44)]; // your frame, so picker gets "colored"

        label.textColor = [UIColor blackColor];
        label.font = [UIFont fontWithName:localize(@"myFontName") size:14];
        label.textAlignment = NSTextAlignmentCenter;

        label.text = [arrayGender objectAtIndex:row];

        return label;
    } else {
        [pickerView setFrame: CGRectMake(10, 264, 300, 216)];
        pickerView.backgroundColor = [UIColor clearColor];
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(40, 0, 260, 44)];

        label.textColor = [UIColor blackColor];
        label.font = [UIFont fontWithName:@"HelveticaNeue-Bold" size:14];

        label.text = [NSString stringWithFormat:@"%@", [arrayGender objectAtIndex:row]];
        return label;
    }
}

This is is working perfectly.

The problem comes in highlighter that is there. The highlighter size is fixed to 204 (this is the size-width set in IB for UIPicker)

Any idea how to tackle this highlighter?

By highlighter, below is sample what I meant.

enter image description here

Below is the actual image of what I am talking about.

enter image description here

0

2 Answers 2

0

Looks like you should make own UIView as an custom Selection Indicator. Look here for details.

0
0

I solved it by reversing the stuff.

In IB I created UIPicker view of width 320 and in code I adjusted the width.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.