I see very complicated answers, all of them using code. However, if you are using Interface Builder, there is a very easy way to do this:
- Select the button and set a title and an image. Note that if you set the background instead of the image then the image will be resized if it is smaller than the button.
- Set the position of both items by changing the edge and insets. You could even control the alignment of both in the Control section.
You could even use the same approach by code, without creating UILabels and UIImages inside as other solutions proposed. Always Keep It Simple!
EDIT: Attached a small example having the 3 things set (title, image and background) with correct insets
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…