Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the size of UIStepper?

Is it possible to change the size of a UIStepper? When i try to set the size of a stepper it seems to get ignored.

UIStepper *stepper = [[UIStepper alloc] initWithFrame:CGRectMake(50,50,100,100)];
[self.view addSubview:stepper];
NSLog(@"%@",stepper);
CGRect r = CGRectMake(50,50,100,100);
stepper.frame = r;
NSLog(@"%@",stepper);

Log says the frame is (50 50; 94 27)

Is it possible to change the size from 94, 27?

like image 566
Jim Avatar asked Sep 21 '12 03:09

Jim


1 Answers

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 161
Brody Robertson Avatar answered Oct 17 '22 19:10

Brody Robertson