忍者ブログ
  • 2024.08
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 2024.10
[PR]
×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

【2024/09/19 11:53 】 |
UITabBarItemにぴったり背景画像をセットする
UITabBarControllerを使うとき、タブアイテムに画像をセットすることがよくある。
普通、この画像はアイコンだけで、背景はグラフィックに持たせないことが多い。

・端末によって画面サイズが違っていて、それに伴ってタブの縦横比も違っている。→分かりやすい解説ページ
・タブ数が変わると、1つのアイコンの横幅も変わる

…というのが理由である。(当たり前)


それでもアイコンに背景を付けたい、という人は

背景用画像をアイコン1つぶんの大きさにリサイズする。
で、[UITabBar appearance] の selectionIndicatorImage にセットする。


UIImage *originImage = [UIImage imageNamed:@"tab_bg.png"];
CGSize tabItemSize = CGSizeMake([self rotatingFooterView].frame.size.width / self.tabBar.items.count, [self rotatingFooterView].frame.size.height);

UIGraphicsBeginImageContext(tabItemSize);
[originImage drawInRect:CGRectMake(0, 0, tabItemSize.width, tabItemSize.height)];
UIImage *resizedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

[[UITabBar appearance] setSelectionIndicatorImage:resizedImage];



となる。

PR
【2014/11/19 22:58 】 | iPhone | 有り難いご意見(0)
<<UITabBarをタップしたときのdelegateメソッド | ホーム | cocos2.2 android>>
有り難いご意見
貴重なご意見の投稿














<<前ページ | ホーム | 次ページ>>