iphoneiosuistepper

How to set background color of an UIStepper instance?


When setting the background color property of an UIStepper object, I get a result as shown:

enter image description here

Just the corners get colored, not the expected, big background area. Is there a simple solution or does it come to iterating through the stepper's subviews?


Solution

  • A UIStepper contains 3 subviews: an UIImageView and 2 UIButtons. The plus and minus signs are set via the image property of the 2 buttons. So you have to change the images of buttons.

    UIStepper *stepper = [[UIStepper alloc] initWithFrame:CGRectMake(100, 100, 100, 50)];
    
        for (UIView *view in stepper.subviews) {
    
            if([view isKindOfClass:[UIButton class]]) {
    
                UIButton *button = (UIButton *)view;
                [button setBackgroundImage:[UIImage imageNamed:@"image.png"] forState:UIControlStateNormal];
                [button setBackgroundImage:[UIImage imageNamed:@"image1.png"] forState:UIControlStateHighlighted];
            }
        }
    
        [baseView addSubview:stepper];