UIButton with text on the left and image on the right
I want to put an image on the right side of a button and text on the left. But I want the text to be 20 points from the left edge of the button and the image 20 points from the right edge. How should I do it? I want to use my own image and shortcut in UIButton, I don't want to put anything on top of the button. Here's an example:
+4
source to share
3 answers
Very simple and easy solution: use a UIView containing UIButton and UIImage as shown in this snapshot.
- Set the right side of the image in the UIView and disable user interaction, so the user / tap action will be passed to the button.
- Add a button with the same size as UIView to UIView, with transparent background color and image coverage.
- Set content offset for the button as shown in this screenshot.
This will make it easier to control the action, properties, and adjust the position and size of the image to suit your requirements. Try it.
+4
source to share