Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the size of UIStepper

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?

like image 419
user523234 Avatar asked Dec 09 '22 21:12

user523234


2 Answers

UIStepper* s = [UIStepper alloc] init];  
s.transform = CGAffineTransformMakeScale(0.75, 0.75);
like image 113
gdm Avatar answered Dec 30 '22 07:12

gdm


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

[email protected]:

enter image description here

[email protected]:

enter image description here

like image 34
Brody Robertson Avatar answered Dec 30 '22 07:12

Brody Robertson