selectionIndicatorImage

selectionIndicatorImage

本文介绍了更改方向时如何更改UITabbar selectionIndicatorImage-Swift的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将图像用于我的标签栏selectionIndicatorImage.它在纵向方向上效果很好.但是,当我更改为横向"方向时,selectionIndicatorImage仍将图像用于人像".因此,图像的宽度不适合我在横向"中的Tab栏大小.

I uses an image for my tabbar selectionIndicatorImage. It works great in Portrait orientation. However, when I change to Landscape orientation, the selectionIndicatorImage is still using the image for Portrait. Therefore, the image's width doesn't fit my Tab bar size in Landscape.

如何解决此问题?谢谢.

How can I fixed this problem? Thank you.

推荐答案

我会根据方向从代码中更改图像.像这样:

I would change the image from code depending on the orientation.Like this:

// the function is called everytime bounds change
override func viewDidLayoutSubviews() {
    let orientation = UIDevice.currentDevice().orientation
    if orientation == .Portrait {
        // I asssume you get images from Images.xcassets
        self.tabBarController?.tabBar.selectionIndicatorImage = UIImage(named: "image1")
    } else if orientation == .LandscapeLeft || orientation == .LandscapeRight {
        self.tabBarController?.tabBar.selectionIndicatorImage = UIImage(named: "image2")
    }
}

这篇关于更改方向时如何更改UITabbar selectionIndicatorImage-Swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 13:35