5

I can't seem to change the size of UIStepper:

  1. In IB, the Width and Height boxes are grayed out.
  2. I used initWithFrame:

    UIStepper *stepper = [[UIStepper alloc] initWithFrame:CGRectMake(300, 638, 120, 80)];

    But it does not change the size. Several posts on SO seemed to implied it is changeable. Any suggestion?

vikingosegundo
  • 52,040
  • 14
  • 137
  • 178
user523234
  • 14,323
  • 10
  • 62
  • 102

7 Answers7

6
UIStepper* s = [UIStepper alloc] init];  
s.transform = CGAffineTransformMakeScale(0.75, 0.75);
gdm
  • 7,647
  • 3
  • 41
  • 71
5

You can properly update the UIStepper size without transformation.

Use the following method to set the background image and the stepper will draw itself using the background size:

- (void)setBackgroundImage:(UIImage*)image forState:(UIControlState)state

Example

    [self.stepper1 setIncrementImage:[UIImage imageNamed:@"plusIcon1.png"] forState:UIControlStateNormal];
    [self.stepper1 setDecrementImage:[UIImage imageNamed:@"minusIcon1.png"] forState:UIControlStateNormal];

    [self.stepper1 setBackgroundImage:[UIImage imageNamed:@"stepperBkg1.png"] forState:UIControlStateNormal];
    [self.stepper1 setBackgroundImage:[UIImage imageNamed:@"stepperBkgHighlighted1.png"] forState:UIControlStateHighlighted];
    [self.stepper1 setBackgroundImage:[UIImage imageNamed:@"stepperBkgDisabled1.png"] forState:UIControlStateDisabled];

This yields the following result on the left, compared to an unmodified stepper on the right: enter image description here

stepperBkg1@2x.png:

enter image description here

stepperBkgHighlighted1@2x.png:

enter image description here

Brody Robertson
  • 8,506
  • 2
  • 47
  • 42
  • 2
    The important bit here is that the background image is the one setting the size of the UIStepper. – Cla Nov 20 '15 at 10:37
3

I tried the transform on my stepper - it did change the appearance and did scale it, however, the images of the + and - were stretched (so you have to scale in proportion to the original stepper.

Also, be careful because the area of touch that actually increments and decrements, does change - so on the stretched image, the button would not decrement along the entire view - so this is probably not a good solution....

MplsRich
  • 137
  • 1
  • 13
2

from the doc:

The bounding rectangle for a stepper matches that of a UISwitch object.

Doesn't sound, like it is possible upfront.

Also in this blog post:

// Frame defines location, size values are ignored
UIStepper *stepper = [[UIStepper alloc] initWithFrame:CGRectMake(120, 20, 0, 0)]; 

But you can try to transform it's layer.

vikingosegundo
  • 52,040
  • 14
  • 137
  • 178
1

You can provably scale it:

stepper.transform = CGAffineTransformMakeScale(1.75, 1.0);
k20
  • 2,008
  • 1
  • 17
  • 23
0

I've made a small custom UIStepper class for it. No images needed, no transformation needed. Images generated automatically. https://github.com/alelipona/VZCustomSizeStepper enter image description here

-2

Yes, you can change size of stepper.

first, right click on storyboard --> select (open as)--> Select (Source Code)

then find stepper in the code--> find width=??? and change.

then click on storyboard again and select open as interface builder.

Farhad
  • 33
  • 9