UITabBarItemのタイトル位置の位置を調整する方法についてウェブを検索したところ、私はこの同様の投稿に出くわしましたが、それでもそれを行う方法を考えていました。
タイトルの位置を下から少し上に調整することも可能ですか?(たとえば5px)カスタム画像があり、タイトルの位置が完全ではないため、これが必要です。
UITabBarItemのタイトル位置の位置を調整する方法についてウェブを検索したところ、私はこの同様の投稿に出くわしましたが、それでもそれを行う方法を考えていました。
タイトルの位置を下から少し上に調整することも可能ですか?(たとえば5px)カスタム画像があり、タイトルの位置が完全ではないため、これが必要です。
上に移動したい場合は、垂直オフセットを負の値に設定するだけです。
UITabBarItem* it = [[self.tabController.tabBar items] objectAtIndex:0];
it.titlePositionAdjustment = UIOffsetMake(0.0, -2.0);
ここで行われているように、プロキシを使用する必要はありません。UITabBarItemタイトルは、タイトルの下部ではなく中央にあります。アイテムごとのオフセットを定義できます。
それらすべてを更新したい場合:
tabBar.items?.forEach({ $0.titlePositionAdjustment = UIOffset(horizontal: 0.0, vertical: -2.0) })
Why don't you just have an empty title property for your view controller and add the title to your custom images for the tab?
You can do this (in iOS 5.0):
UIImage* iconSelected = [UIImage imageNamed:@"tabIconSelected.png"];
UIImage* iconNotSelected = [UIImage imageNamed:@"tabIconNotSelected.png"];
UITabBarItem *updatesListItem = [[UITabBarItem alloc] initWithTitle:@"" image:iconSelected tag:0];
[updatesListItem setFinishedSelectedImage:iconSelected withFinishedUnselectedImage:iconNotSelected];
[navigationController setTabBarItem:updatesListItem];
where tabIconSelected.png
and tabIconNotSelected.png
both contain the title text for the tab.
I have written a brief article "Add some colour to your UITabBar icons" which explains how to use custom images with tabs.
Hope this helps.