iPhone開發中為UINavigationBar設置背景圖片方法
作者:佚名
iPhone開發中為UINavigationBar設置背景圖片方法是本文要介紹的內容,在iPhone開發中, 有時候我們想給導航條添加背景圖片, 實現多樣化的導航條效果,具體內容來看本文。
iPhone開發中為UINavigationBar設置背景圖片方法是本文要介紹的內容,在iPhone開發中, 有時候我們想給導航條添加背景圖片, 實現多樣化的導航條效果, 用其他方法往往無法達到理想的效果, 經過網上搜索及多次實驗, 確定如下最佳實現方案。
為UINavigatonBar增加如下Category:
- @implementation UINavigationBar (CustomImage)
- - (void)drawRect:(CGRect)rect {
- UIImage *image = [UIImage imageNamed: @"NavigationBar.png"];
- [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
- }
- @end
例如, 在我的項目中, 添加如下代碼:
- /* input: The image and a tag to later identify the view */
- @implementation UINavigationBar (CustomImage)
- - (void)drawRect:(CGRect)rect {
- UIImage *image = [UIImage imageNamed: @"title_bg.png"];
- [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
- }
- @end
- @implementation FriendsPageViewController
- // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- - (void)viewDidLoad {
- self.navigationBar.tintColor = [UIColor purpleColor];
- [self initWithRootViewController:[[RegPageViewController alloc] init]];
- [super viewDidLoad];
- }
實現的效果如下圖:
小結:iPhone開發中為UINavigationBar設置背景圖片方法的內容介紹完了,希望通過本文的學習能對你有所幫助!
責任編輯:zhaolei
來源:
互聯網