UItabBarItem高亮状态图

发布于 2024-08-10 22:02:11 字数 281 浏览 2 评论 0原文

我希望能够在选择 UITabBarItem 时更改其上突出显示的状态图像?是否可以子类化并访问它?或者我需要滚动自己的导航代码吗?

->开始编辑 我之前没有明确说明我在寻找什么。我正在寻找设备添加到 UITabBar 的选定状态/图像的半透明白色覆盖参考。看图片! http://solomon71.com/images/UITabBarItem.png

I'd like to be able to change the highlighted state image on an UITabBarItem when it is selected? Is it possible to subclass and access this? or do I need to roll my own navigation code?

-> start edit
I didn't articulate what I was looking for earlier. I am looking for the semi-transparent white overlay reference that the device adds to the selected state/image of the UITabBar. See image! http://solomon71.com/images/UITabBarItem.png

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

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

发布评论

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

评论(2

静赏你的温柔 2024-08-17 22:02:11

没有记录或支持的方法来设置您自己的突出显示图像。话虽如此,在 2.2 中,您可以通过子类化 UITabBarItem 并实现 -[UIImage *)selectedImage 来做到这一点。

严格来说,您没有调用私有 API,因为 selectedImage 不是保留的方法名称(实际上是一个供某人自己使用的相当合理的名称)。话虽如此,我确信这不是有意的,并且它可能在未来的版本中随时中断。如果这在 3.x 中已经被破坏了,我也不会感到震惊(我从未发布过任何这样做的东西,只是为客户进行了实验)。

There is no documented or supported way to set your own highlighted image. Having said that, in 2.2 you could do it by subclassing UITabBarItem and implementing -[UIImage *)selectedImage.

Strictly speaking you are not calling private API, since selectedImage is not a reserved method name (and is actually a fairly reasonable name for someone to use themselves). Having said that, I am sure this is not intended and it could break at any time in a future release. It wouldn't shock me if this was already broken in 3.x (I never shipped anything that did this, just experimented with it for a client).

秋日私语 2024-08-17 22:02:11

试试这个。

我已经更改了选定的 tabbatitem 图像,例如 -

在选项卡控制器委托方法中,

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController

{
    if([tabBarController selectedIndex] == 0)
    {
        [viewController.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"selected.png"]withFinishedUnselectedImage:[UIImage imageNamed:@"unselect.png"]];
    }    
}

您可以通过此更改图像。

或者您可以直接在视图控制器 init(或 ViewWillAppear) 方法中使用,例如

        [viewController.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"selected.png"]withFinishedUnselectedImage:[UIImage imageNamed:@"unselect.png"]];

try this one.

I have change the selected tabbatitem image like -

in tabbar controller delegate method

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController

{
    if([tabBarController selectedIndex] == 0)
    {
        [viewController.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"selected.png"]withFinishedUnselectedImage:[UIImage imageNamed:@"unselect.png"]];
    }    
}

through this you can change your image.

Or you can use directly in your view controllers init(or ViewWillAppear) method, like

        [viewController.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"selected.png"]withFinishedUnselectedImage:[UIImage imageNamed:@"unselect.png"]];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文