0

コードを使用して 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];

私は自分の画像を使いたいので、最初の行(お気に入り)を変更しましたが、設定すると画像が途中から始まり、空の場合でも常にタイトルの小さな場所にとどまります。

これらのアイテム内の画像の位置を制御するにはどうすればよいですか? 空のタイトルの場所を無効にしますか?

4

1 に答える 1

1

それはかなり古い質問ですが、古い質問でさえ愛が必要です:)

したがって、まだこの問題が発生している場合は、UIViewControllers tab bar item image insets:を使用できます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)
    }
}
于 2015-09-16T08:30:54.270 に答える