Enlarge button while reducing button's image? - ios

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.

Related

UIbutton stretch when clicked unexpectively

I am trying to modify a frame work and have encountered the following problem.
I have replaced one of the button image in the framework's xib file with my own one. The image itself is approximately 20Wx20H but I have set the button size to be 40Wx40H so that the clickable area is larger than the actual image.
When the VC is displayed, I see the image to be normal 20x20 aspect ratio. However, when I clicked on the button, it stretches to 40x20 and goes back to default upon release. I was wondering if there is a UIButton parameter that I can disable which was enabled by the framework somewhere? I have done a search on the buttons in the code and could not find anything relating to stretching the button. So I am guessing somewhere in IB there is my solution?
Below are the images for the button when touch down or not touched down.
Have you tried the following?
button.imageView.contentMode = UIViewContentModeScaleAspectFit;
Also are you using autolayout? If yes, what are the constraints?

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.

UIButton with background image and title using auto layout

I currently face a problem when using UIButton. I have the background image designed by others like this:
background image
and I need to place the title for the button right after the white vertical bar in the background image. I tried to set left edge for the content but since I used auto layout, the frame will be different with different screen size(3.5", 4.7"...).
Is there a way to put text in the position related to background I want with auto layout.
Thanks
I personally would split the left side of the background image from the right side. This way you can have two UIButtons next to each other with horizontal space constraint of 0. The right side of the button will have to be placed inside a UIImageView so you can set the image as a property of the view rather that the button's background. You don't have to do this of course, but I prefer this solution as it is easier to manage across different screen sizes.
Here is a visual representation of what I explained above:
Separated Views for Single UIButton
You will then need to route the touch events of both buttons to run the same method or function, just so that both the right side and the left are clickable.
Note: I'm not sure exactly what you had in mind for the highlighting of the button, but this will have to be tested and adapted to get the desired effect.

Make a small UIImageView easy to be tapped

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.

Increase touch sensitivity of iPhone app programmatically

I am using too many number of images for buttons in my project. I found some issues while doing device test. App couldn't detecting the finger tapping sometimes. I need to increase the touch sensitivity programmatically to resolve this issue.
Like apple documentation says:
Make it easy for people to interact with content and controls by giving each interactive element ample spacing. Give tappable controls a hit target of about 44 x 44 points.
Make the button tappable size at least 44x44 pixels and it should work.
More informations here
https://developer.apple.com/library/ios/documentation/userexperience/conceptual/mobilehig/LayoutandAppearance.html
it's not possible, but you might have smaller action button which you could resize little more or you can have bigger transparent action button behind your smaller action button so you can get what you are looking for!
Add images to button like this -
here you can see the button border are larger that image size, so you can increase the touch area of button in this way.
For further image adjustment inside button, you can use image insets, which are also present in the same inspector in xib.

Resources