UINavigationBarの背景に画像を指定する方法を紹介します。
アプリに個性を出したい場合なんかにためしてみるといいかもしれません。
UINavigationBarにUIImageViewをinsertSubviewして実現します
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 |
//レイヤーを扱うので、<QuartzCore/QuartzCore.h> をインポートします
#import <QuartzCore/QuartzCore.h>
// navigationbarを取得します
UINavigationBar *navigationBar;
navigationBar = navigationController.navigationBar;
// imageViewを作ります
UIImageView *imageView;
UIImage *image;
image = [[UIImage imageNamed:@"back.png"]stretchableImageWithLeftCapWidth:0 topCapHeight:1];
imageView = [[UIImageView alloc] initWithImage:image];
[imageView autorelease];
imageView.frame = navigationBar.bounds;
imageView.autoresizingMask = ( UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
//imageViewが、常に一番後ろに表示されるように指定します。
imageView.layer.zPosition = -FLT_MAX;
//imageViewをnavigationBarのサブビューに追加します
[navigationBar insertSubview:imageView atIndex:0];
//NavigationBarのボタンの色を指定します。
UIColor *tintColor;
tintColor = [UIColor colorWithHue:0.274 saturation:0.521 brightness:0.618 alpha:1.000];
navigationBar.tintColor = tintColor; |
No related posts.