如何在更改方向时更改 UITabbar selectionIndicatorImage - Swift
How to make UITabbar selectionIndicatorImage change when changing orientation - Swift
我为我的标签栏 selectionIndicatorImage 使用了一张图片。它在纵向方向上效果很好。但是,当我更改为横向时,selectionIndicatorImage 仍在使用纵向图像。因此,图像的宽度不适合我在横向模式下的标签栏大小。
我该如何解决这个问题?谢谢。
我会根据方向更改代码中的图像。
像这样:
// 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")
}
}
我为我的标签栏 selectionIndicatorImage 使用了一张图片。它在纵向方向上效果很好。但是,当我更改为横向时,selectionIndicatorImage 仍在使用纵向图像。因此,图像的宽度不适合我在横向模式下的标签栏大小。
我该如何解决这个问题?谢谢。
我会根据方向更改代码中的图像。 像这样:
// 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")
}
}