自定义 UITabBar 的 UIKit 外观代理

发布于 2024-12-11 13:31:20 字数 89 浏览 0 评论 0原文

我想创建一个自定义 UITabBar 并且熟悉外观代理。我知道我可以将其背景图像设置为我想要的任何内容。如何更改每个选项卡的选定状态?本质上我想消除光泽/光泽效果。

I want to create a custom UITabBar and am familiar with the appearance proxy. I know I can set its background image to whatever I want. How can I change the selected state of each tab? Essentially I would like to remove the gloss/shine effect.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

固执像三岁 2024-12-18 13:31:20

您需要获取实际的 UITabBarItem

像这样的东西应该可以解决单个项目的问题

UITabBar *tabBar = tabBarViewController.tabBar;

for(UITabBarItem *tabItem in tabBar.items)
{
   //in reality you will probably change these images and grab from the array individually
   UIImage *selectedImage = [UIImage imageNamed:@"selected.png"];
   UIImage *unselectedImage = [UIImage imageNamed:@"unselected.png"];

   [tabItem setFinishedSelectedImage:selectedImage withFinishedUnselectedImage:unselectedImage];
}

,或者您可以使用代理来更改所有 UITabBarItems

[UITabBarItem appearance]

You need to grab the actual UITabBarItem

Something like this should do the trick for individual items

UITabBar *tabBar = tabBarViewController.tabBar;

for(UITabBarItem *tabItem in tabBar.items)
{
   //in reality you will probably change these images and grab from the array individually
   UIImage *selectedImage = [UIImage imageNamed:@"selected.png"];
   UIImage *unselectedImage = [UIImage imageNamed:@"unselected.png"];

   [tabItem setFinishedSelectedImage:selectedImage withFinishedUnselectedImage:unselectedImage];
}

alternatively you can just use the proxy to alter all UITabBarItems using

[UITabBarItem appearance]
神经大条 2024-12-18 13:31:20

您可以使用 UIBarItemUITabBarItem 的外观代理来完成此操作。

来自苹果的文档:

自定义外观

在 iOS v5.0 及更高版本中,您可以自定义
通过使用设置项目标签文本属性来显示选项卡栏
由 UIBarItem 声明的外观选择器。您还可以使用
“自定义外观”中列出的方法。您可以自定义
使用外观代理的所有分段控件的外观(例如
例如,[UITabBarItem外观]),或者只是单个选项卡栏。你
还可以使用以下命令提供完成的选定和未选定的图像
“管理完成的选定图像”中列出的方法;这些
但是,方法,因此不参与 UIAppearance 代理 API(请参阅
UI外观)。 UIKit 现在确实提供了任何自动处理
完成的图像。为了获得好的结果,您必须提供完成的选择
以及使用匹配对中未选择的图像
setFinishedSelectedImage:withFinishedUnselectedImage:.

You may use the appearance proxies for UIBarItem and UITabBarItem to accomplish this.

From Apple's documentation:

Customizing Appearance

In iOS v5.0 and later, you can customize the
appearance of tab bars by setting item label text attributes using
appearance selectors declared by UIBarItem. You can also use the
methods listed in “Customizing Appearance.” You can customize the
appearance of all segmented controls using the appearance proxy (for
example, [UITabBarItem appearance]), or just of a single tab bar. You
can also provide finished selected and unselected images using the
methods listed in “Managing the Finished Selected Image”; these
methods, though, so not participate in the UIAppearance proxy API (see
UIAppearance). UIKit does now provide any automatic treatment to
finished images. For good results, you must provide finished selected
and unselected images in matching pairs using
setFinishedSelectedImage:withFinishedUnselectedImage:.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文