How to zoom image without zooming subviews of an image? swift ios - ios

I added UIImageView which is subview of UIScrollView. Then I added UIButton is subview of UIImageView. When I zoom UIImageView then UIButton is also perform zooming. I want only zoom UIImageView not UIButton. How can I achieve this?

Since UIButton is subview of UIImageView, it will pan/zoom when you zoom/pan UIImageView. To solve your problem, make it subview of some other view, perhaps UIScrollView in your case.

Related

How to make UIButton overlapping UIScrollview

I have a scrollview and I need UIbutton/label overlapping it as in example ("Close")
I added UIButton to storyboard above my scrollView and make constraints to the top of the superView:
But the button is still invisible on simulator.

How to achieve label embededd in UIImageView in iOS Swift like shown in image?

I want to achieve label/Button embededd in UIImageView in iOS Swift like shown in image.Has anyone done that?
You just need to play with UIView, UILabel And UIImageView.
You view hierarchy will be like below...
- UIView (mainView)
- UIImageView (imageView)
- UILabel
You need to make mainView.clipsToBounds = true so that after giving corner radius to it, it's subview will not go beyond its superview's bounds.
For imageView, you can set its content mode to aspect fill/ aspect fit as per your requirement.
Have a square UIView with clipsToBounds property set to YES which contains UIImageView and UILabel. The image view should cover all the view frame. The label should be positioned at the bottom of the view over the image view. Then just set appropriate corner radius (half of the view's height) for the view's layer and set its masksToBounds property to YES. That's it

UIImage from UIView if UIView is outside window bounds

I have UIScrollView with many UIView views added to the content. I would like to convert UIView and its subviews to UIImage and I know how to do it if the UIView is currently visible on the device screen. Is it possible to convert UIView (subview in UIScrollView) into UIImage if UIView is not in UIScrollView visible rect?
Could you just iterate over all subviews taking a screenshot of each UIView inside the UIScrollView ?
The following class may help with taking screenshots:
http://ioscodesnippet.com/2011/08/25/rendering-any-uiviews-into-uiimage-in-one-line/
Hope you find a solution.
Thanks,
Michael

How to zoom on an UITextView inside a UIScrollView?

I have a UIScrollView which contains instances of an UIView subclass.
This UIView has a CAShapeLayer as a sublayer of its layer, and a UITextView as a subview.
With zooming enabled on the UIScrollView, the CAShapeLayer remains sharp when I zoom, but the UITextView doesn't.
Is there a way to have the UITextView redraw at the correct resolution?
you can use [yourTextView contentScaleFactor] or [yourTextView.layer contentsScale]. Set it to the current scalefactor.

UIScrollView or UIImageView?

I need to place a photo in the screen and it should be able to be scrolled or zoomed,
I know UIScrollView does these, so I alloced one, but how about my photo?
I guess I should not just set the photo as the backgroundColor of my UIScrollView, and I haven't found any property of UIScrollView, in the document, to hold an image, such as "imageView", "contentView", or something like that.
So, what should I do to make a picture in my screen and make it able to respond to finger touches?
Thanks a lot!
Add the UIImageView to the UIScrollView and set the min/max scale value to it.
Then implement the following UIScrollViewDelegate function.
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return yourImageView;
}
If you want to have multiple items scaled, add all the view into a UIView, and put that UIView inside the UIScrollView. Of course you have to change the return view to that UIView in the above function.
Just add your UIImageView as a subview of the UIScrollView. Also, set the scroll view's contentSize property to be equal to the size of the image view's frame.
THe scrollView is the first step.
Then you should add a UIImageView and load an image inside.
You need also to set the max e min zoomScale properties of the scrollview
And you must implement the scrollview delegate method – viewForZoomingInScrollView:

Resources