如何调整标签栏徽章位置? [英] How to adjust tab bar badge position?

查看:124
本文介绍了如何调整标签栏徽章位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在标签栏上显示徽章,但是当数字增加时,它会显示在标签栏项目中,如图所示

I'm displaying badge on tab bar but when number increase it goes out to tab bar item like shown in image

我想稍微向左移动徽章视图,使其适合选定的标签图片.i尝试这里,但没有运气。
那么有没有办法调整徽章视图位置?任何帮助都会受到赞赏。

I want to move the badge view slightly left so it fit on selected tab image.i tried as described here but no luck. So is there is any way to adjust badge view position?Any help would be appreciated.

推荐答案

我找到了Kateryna的回答是有用的让我走上正轨,但我不得不稍微更新一下:

I found Kateryna's answer to be useful in putting me on the right track, but I had to update it a little:

func repositionBadge(tab: Int){

    for badgeView in self.tabBarController!.tabBar.subviews[tab].subviews {

        if NSStringFromClass(badgeView.classForCoder) == "_UIBadgeView" {
            badgeView.layer.transform = CATransform3DIdentity
            badgeView.layer.transform = CATransform3DMakeTranslation(-17.0, 1.0, 1.0)
        }
    }

}

请注意,选项卡整数不是零索引,因此第一个选项卡将是数字1,即第二个数字2,等等。

Please note the tab integer is NOT zero-indexed, so the first tab will be number 1, the 2nd number 2, etc.

这篇关于如何调整标签栏徽章位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆