Search code examples
iosiphoneipaduibutton

UIButton Image + Text IOS


I need a UIButton with image & text. Image should be in the top & text comes under the image both should be clickable.


Solution

  • 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:

    1. 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.IB basic image and title
    2. Set the position of both items by changing the edge and insets. You could even control the alignment of both in the Control section.

    IB position set IB Control set

    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 Button preview