2

How can we resize a UIbutton in IOS,i have a button with CGRectMake (30,50,120,200)when the application is running ,the user can taptohold or pinch gesture to make the button big or small according to his needs.lke the zooming function of scrollview ..How to do this.thanks in advance.

stackiphone
  • 1,245
  • 3
  • 19
  • 41

2 Answers2

3

Use the CGAffineTransformMakeScale like this

button.transform = CGAffineTransformMakeScale(1.2, 1.2)

scale it to normal

button.transform = CGAffineTransformMakeScale(1.0, 1.0)

If you want animation

[UIView animateWithDuration:0.3
                     animations:^{
                         button.transform = CGAffineTransformMakeScale(1.2, 1.2);
                     }
                     completion:NULL];
ultragtx
  • 957
  • 8
  • 24
2

Use an UIPinchGestureRecognizer on the button to detect the gesture. Then resize the frame, or use an AffineTransform. (button.transform = CGAffineTransformMakeScale(scaleFactor,scaleFactor)).

halfer
  • 19,824
  • 17
  • 99
  • 186
calimarkus
  • 9,955
  • 2
  • 28
  • 48