reinaldoluckman
reinaldoluckman

Reputation: 6348

How to put an image and a bottom text together in a UIButton?

I want to put an centered image and a bottom centered text in a UIButton.

How I can do that?

Thanks in advance.

Upvotes: 3

Views: 5989

Answers (3)

Jeet
Jeet

Reputation: 1040

Try this

[btn setTitleEdgeInsets:UIEdgeInsetsMake(btn.frame.size.height - 20, 1, 1, 1)];

arguments: top, left, bottom, right

Set the frame first. Also reduce the font size to fit in.

Upvotes: 0

reinaldoluckman
reinaldoluckman

Reputation: 6348

Ok, figure out how. Using the methods:

    [button1 setTitleEdgeInsets:UIEdgeInsetsMake(30.0, 0.0, 0.0, 0.0)];
    [button1 setImageEdgeInsets:UIEdgeInsetsMake(-10.0, 29.0, 0.0, 0.0)];

Upvotes: 9

jalopezsuarez
jalopezsuarez

Reputation: 434

If you what a specific solution, with a UIButton with an Image and a Text below. I made a Extended Class from UIButton to make it easier:

https://gist.github.com/jalopezsuarez/2c8f430636d89a58099b

You only need to use UIButtonBox in Interface Builder and it will layout automatically the text bellow the image.

Upvotes: 3

Related Questions