Suryakant Sharma
Suryakant Sharma

Reputation: 3960

How to Resize iOS UI component same as Interface Builder

I'm working on a iOS app where in a screen, user can have multiple UI component. Also, user can drag and reposition those component. Now, I want all UI component to be resized by user through finger touch(same as we can resize in Interface Builder with mouse).

EDIT: enter image description here

As above screen shot of IB, we can hold any tiny squares around button with mouse and resize the button.Same thing I need to implement in my App by finger gesture (probably by UIPanGestureRecognizer).

Upvotes: 0

Views: 187

Answers (3)

Suryakant Sharma
Suryakant Sharma

Reputation: 3960

Guys thanks to this Beautiful Example, I'm able to achieve what I wanted to. Now I am able to put editing handles & resize any UI component easily. After searching about a week I got this solution, so thought of sharing.

Upvotes: 0

Tomasz Bąk
Tomasz Bąk

Reputation: 6204

If you reject solution with pinch recognizer. I would suggest creating custom wrapper for UI components, that would create little squares in corners of the frame and in the middle of every side. Every square should have UIPanGestureRecognizer to control size of the object.

Upvotes: 0

Andrés Brun
Andrés Brun

Reputation: 185

I recommend you that you add a pinch gesture in those view to user can make zoom.

UIPinchGestureRecognizer *twoFingerPinch = 
  [[[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(scaleObject:)] autorelease];
[[self view] addGestureRecognizer:zoomGesture];

and the method:

- (void)scaleObject:(UIPinchGestureRecognizer *)recognizer 
{
  NSLog(@"Object scale: %f", recognizer.scale);
}

and change the object size with that scale. Moreover you can use other gestures like:

  • UITapGestureRecognizer
  • UIPinchGestureRecognizer
  • UIRotationGestureRecognizer
  • UISwipeGestureRecognizer
  • UIPanGestureRecognizer
  • UILongPressGestureRecognizer

Upvotes: 1

Related Questions