Question

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?

Was it helpful?

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

OTHER TIPS

I don't know why Apple turns it so hard to customize without images. What solved in my case was set the property cornerRadius from UIStepper object:

yourStepper.layer.cornerRadius = 5.f;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top