[英]Image position inside UITabBarItem
我正在使用代碼顯示帶有項目的UITabBar,我下載了一個示例,該示例顯示帶有“收藏夾”,“聯系人”的系統圖標的項目...
UITabBarItem *favorites = [[UITabBarItem alloc] initWithTitle:nil image:a1 tag:0];
UITabBarItem *topRated = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemTopRated tag:1];
UITabBarItem *featured = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFeatured tag:2];
UITabBarItem *recents = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemRecents tag:3];
我想使用自己的圖像,因此我更改了第一行(收藏夾),但是當我設置它時,圖像從中間開始,並且始終留在很小的標題位置,即使它是空的。
如何控制這些項目中的圖像位置? 並禁用空的標題位置?
這是一個相當老的問題,但即使是老問題也需要愛:)
因此,如果仍然遇到此問題,則可以使用UIViewController
的選項卡欄項目圖像插入: tabBarItem.imageInsets
。
您在視圖控制器上進行設置,並將其分配給選項卡欄控制器的viewControllers
屬性。
這是子類標簽欄控制器的快速版本,它將始終確保所有圖像對齊得更低。
override func setViewControllers(viewControllers: [AnyObject], animated: Bool) {
super.setViewControllers(viewControllers, animated: animated)
let array = viewControllers as! [UIViewController]
for controller in array {
controller.tabBarItem.imageInsets = UIEdgeInsetsMake(5, 0, -5, 0)
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.