3

I have to place 6 buttons in the bottom of particular screens like UITabBar. I have placed UIButton with Image and Text but, am not able to move the image on top of the button with centre alignment and place the button text in below of the image with center alignment. It should be look like UITabBarItem.

How can I achieve this in UIButton? Anyone can please help me on this? Thanks.

I tried this code but, text not visible and image not properly aligned. Can you please help me?

[self.languageButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[self.languageButton setTitle:@"Language" forState:UIControlStateNormal];
[self.languageButton.titleLabel setFont:[UIFont boldSystemFontOfSize:10.0]];

UIImage *image = [UIImage imageNamed:@"lang_change_white"];

[self.languageButton setTitleEdgeInsets:UIEdgeInsetsMake(0.0, -image.size.width, -25.0, 0.0)];
[self.languageButton setImage:image forState:UIControlStateNormal];
[self.languageButton setImageEdgeInsets:UIEdgeInsetsMake(-15.0, 0.0, 0.0, -self.languageButton.titleLabel.bounds.size.width)];

Thanks in advance.

enter image description here

Yuvaraj.M
  • 9,741
  • 16
  • 71
  • 100

2 Answers2

1

enter image description here

  1. your code work fine for me then what is problem ?
  2. plz explein what you want with image and text of the button..?
Sanandiya Vipul
  • 764
  • 4
  • 16
  • Thank you for your answer. But, this not working like ur screen shot. I have designed the buttons in Storyboard and the size is "Dynamic width and Fixed height 50px". I have attached the screen shot. Can you pls help me? Thanks. – Yuvaraj.M Dec 21 '15 at 13:05
  • i check it in storyboard with "Dynamic width and Fixed height 50px" bt work fine for me. so plz check it out image size. if it is large then this type of problem create . thnks @Yuvaraj.M – Sanandiya Vipul Dec 21 '15 at 13:38
  • Thank you for reply. My image size is 32*32. What is yours? I try to resize the image in button. If you have any idea can you please suggest? Thanks. – Yuvaraj.M Dec 22 '15 at 02:17
0

you have to make 2 special image which contains symbol and text. one image is white image and second one is any color of image . and when user press button set background image as your color image and set initial image as white color image.

princ___y
  • 1,089
  • 1
  • 9
  • 27