将自定义中心按钮添加到标签栏的最佳方法是什么? [英] What's the best way of adding a custom centre button to a tab bar?
本文介绍了将自定义中心按钮添加到标签栏的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
许多应用程序都有一个标准的标签栏,中间带有一个自定义按钮,可以执行一些特殊功能.可以在此处找到一些示例:
Many apps have a standard tab bar with a custom button in the centre which performs some special function. Some examples can be found here:
http://mobile-patterns.com/custom-tab-navigation
实现此目标的最佳方法是什么?
What's the best way of implementing this?
推荐答案
此处,您将看到如何实现该按钮.我要粘贴代码,使其永远保留在这里:
Here you can see how to implement that button. I am gonna paste the code so it stays here forever:
UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0.0, 0.0, buttonImage.size.width, buttonImage.size.height);
[button setBackgroundImage:buttonImage forState:UIControlStateNormal];
[button setBackgroundImage:highlightImage forState:UIControlStateHighlighted];
CGFloat heightDifference = buttonImage.size.height - self.tabBar.frame.size.height;
if (heightDifference < 0)
button.center = self.tabBar.center;
else
{
CGPoint center = self.tabBar.center;
center.y = center.y - heightDifference/2.0;
button.center = center;
}
[self.view addSubview:button];
希望有帮助
这篇关于将自定义中心按钮添加到标签栏的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文