Make a small UIImageView easy to be tapped - ios

I have a UITableView with rows.
Each row has a small UIImageView aligned to the right (a "bookmark" icon)
The UIimageView has a UITapGestureRecognizer associated.
cell.favoritedImageView.userInteractionEnabled = true
cell.favoritedImageView.addGestureRecognizer(gestureRecognizer)
The problem is that to actually tap it with the finger (in a real device), you have to use the tip of the finger and be very accurate, because the image is small.
If you miss tapping the imageView, the cell is tapped (didSelectRowAtIndexPath) and you end up executing a show-segue to another view, so you have to go back and try again (not cool)
Question: what is the best way to solve this? I want it to be easy to be tapped.
I have some ideas:
Create a larger image with transparent surrounding (ie: crop out with transparent background) -- downside is that I also use this image in other views, in which is not tappable, so I'd have to create two versions of the image
Put the image inside a UIView and make the UIView big and tappable instead of the UIImageView
Add padding to the UIImageView (will this work? or the padding is not recognized in the UITapGestureRecognizer?)

Per your own suggestion, you should create a transparent view that is much larger and attach the UITapGestureRecognizer to the view and then nest your smaller image within the view. That way appearances are the same, but you handle a much larger area for the tap to be recognized with selecting the cell.

Related

Divide an Image to a clickable parts

I'm trying to divide one image to a more than one clickable part. for example, if the image is a body image, and I tapped the head, it should take me to a different the HeadViewController, but if I tapped on the left hand, it should take me to a different view controller
Any idea how to do that?
Easy method:
Add UIButtons on top of the image with clear background color. You can do this with AutoLayout and always get correct proportions to the areas when scaling up and down.
Hard method:
Add UITapGestureRecognizer to the UIImageView and calculate CGPoint depending on where it the touchPoint is received. This is complicated and must be calculated correctly.
For you, I suggest the first method suggested.
Attach a tap gesture recognizer to your image view. Set user interaction enabled to true.
In the handler for the tap gesture, fetch the coordinates of the user's tap and write custom code that figures out which "hot box" the user tapped in.
Alternately you could create a custom subclass of UIGestureRecognizer that has multiple tap regions.

Custom UISlider with pips ios

Wondering if the above can be created using UISlider? If not, what other ways can this be accomplished?
You can set components of a UISlider, such as the currentThumbImage ( see: "Appearance of Sliders"1).
However, it is almost certainly easier to just re-implement a slider for this much customization. Simply use background UIImageView with the scale image, and then add a separate UIView (or UIImageView) for the arrow. Finally, attach a UIPanGestureRecognizer to the arrow view to allow a user translate the view vertically.
You can change a lot in the appearance of a UISlider like setting the thumb to a red arrow. You can also replace the background image with the inches ruler and with different rulers for the different device types and display sizes.
The one thing that I don't see is that you turn the slider to work vertically. I know them only working left to right.
If I'm right, your only chance is to have a ruler as background image and a view that contains the arrow and a label with the actual value. That whole view can be pawned and tapped using Gesture Listener.

Enlarge button while reducing button's image?

I have a small image button which fits nicely in a certain area of my screen.
The image is a perfect size for viewing, but too small to tap.
Is there any way to make the button itself bigger (hence easier to tap), but make the image smaller, so it looks the right size?
You just use UIView as a touchView under the your small button.
Like this,
In this case, I put UIView under the small heart button. And, I implement tap action by UITapGesture.

annotate buttons onto uiimageview (like mkmapview without MapKit)

I have a UIImageView set on top of a scrollView. The image is a map, and I need to annotate buttons across the map to corresponding locations (very specific to the region). The buttons are visible, and they pan and scale accordingly when scrolled/zoomed, this works great. The issue is when the buttons are rendered on different screen sizes, the buttons are placed in different spots since auto-layout puts them the same distance from the edge of the screen, but the image has a different bounds property and is bigger/smaller depending on the device.
I've considered creating an MKMapView with a custom overlay of this image, but I was hoping to keep it super light-weight and avoid MapKit all together.
Any suggestions? Clarifications are fully encouraged :)
You should add buttons as subviews on imageview so that buttons transform in the same way as imageview does.

UITextView doesn't keep subviews visible

I'm implementing the a viewController to enter text and images (very similar to Facebook's "Status" entry) and I have most of it complete, however, the last piece isn't working correctly.
The user can select an image and key-in textual data. As more text are added, the images get pushed down. I implemented this by adding UIImageView as subview of UIView, then add UIView as subview of UITextView. They stack up like this:
Top: UIImageView
Middle: UIView
Bottom: UITextView
When I key-in long enough text that it pushes the images down, the images do not stay visible inside the UITextView. I can still see the images if I drag the screen-up, but as soon as I let go, the images bounces down and can't be seen. How do I fix this? Thanks.
You do the followings for this.
1- Have a UIimageView and set your image
2- Draw your UITextview on exact location of image. Means (x,y,w,h) equals
3-Set UItextView background color CLEAR.
and CHEERS

Resources