3

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

How I can do that?

Thanks in advance.

reinaldoluckman
  • 6,317
  • 8
  • 42
  • 50

3 Answers3

9

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)];
Mitul Nakum
  • 5,514
  • 5
  • 35
  • 41
reinaldoluckman
  • 6,317
  • 8
  • 42
  • 50
  • 1
    What are those values stand for? – Cemal Eker Mar 25 '13 at 11:24
  • Man, 4 years from my answer, but the numbers are related with my image size and title size. The idea was to show the methods. The numbers you have to try for yourself. I'm pretty sure that an generic method can be written using calcs from the runtime image/title size, but I don't have the time to do that now. Sorry. – reinaldoluckman Dec 09 '14 at 20:01
3

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.

jalopezsuarez
  • 414
  • 4
  • 13
  • What is the licence for this code? The code says it is copyrighted to you but doesn't say if it is licenced (under an open-source licence?) to use in my project. – Intrications Jan 22 '16 at 13:54
0

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.

Jeet
  • 1,030
  • 2
  • 10
  • 20