简体   繁体   English

如何像iOS中的UITabBarItem一样设计UIButton?

[英]How to design UIButton Like UITabBarItem in iOS?

I have to place 6 buttons in the bottom of particular screens like UITabBar . 我必须在UITabBar等特定屏幕的底部放置6个按钮。 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. 我已将UIButton放置在图像和文本中,但是无法将图像移动到按钮顶部并且中心对齐,并将按钮文本放在图像下方,中心对齐。 It should be look like UITabBarItem . 它应该看起来像UITabBarItem

How can I achieve this in UIButton ? 我怎样才能在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. 提前致谢。

在此输入图像描述

在此输入图像描述

  1. your code work fine for me then what is problem ? 你的代码对我来说工作正常然后是什么问题?
  2. plz explein what you want with image and text of the button..? PLZ explein你想要的图像和按钮文本..?

you have to make 2 special image which contains symbol and text . 你必须制作2个包含symboltext特殊image one image is white image and second one is any color of image . 一个图像是白色图像,第二个图像是图像的任何color and when user press button set background image as your color image and set initial image as white color image . 当用户按下button设置background图片为您的color图像,并设置初始image为白色color image

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM