C++自定义UINavgationBar二
2010-10-19 08:30:04 来源:WEB开发网核心提示:// Created by suruiqiang on 8/3/10.// Copyright 2010 __MyCompanyName__. All rights reserved.//#pragma once#import <UIKit/UIKit.h>@interface UINavigation
// Created by suruiqiang on 8/3/10. // Copyright 2010 __MyCompanyName__. All rights reserved. // #pragma once #import <UIKit/UIKit.h> @interface UINavigationBar (UINavigationBarCategory) UIImageView *bg; -(UINavigationBar*)setBackgroundImage:(UIImage*)image; - (void)insertSubview:(UIView *)view atIndex:(NSInteger)index; @end
CustomNavController.m
#import "CustomerNavBarController.h" @implementation UINavigationBar (UINavigationBarCategory) -(UINavigationBar*)setBackgroundImage:(UIImage*)image { UINavigationBar *NavBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)]; if(image == nil) return NavBar; bg = [[UIImageView alloc]initWithImage:image]; bg.frame = CGRectMake(0.f, 0.f, self.frame.size.width, self.frame.size.height); [NavBar addSubview:bg]; [NavBar sendSubviewToBack:bg]; [bg release]; return NavBar; } - (void)insertSubview:(UIView *)view atIndex:(NSInteger)index { [super insertSubview:view atIndex:index]; [self sendSubviewToBack:bg]; } @end
在需要调用的地方添加如下代码:
- (void)viewDidLoad { [super viewDidLoad]; [[self.navigationController navigationBar] setBackgroundImage:[UIImage imageNamed:@"NavigationBarBackground.png"]]; //在下面添加你自己的功能代码 *********** }
Tags:自定义 UINavgationBar
编辑录入:爽爽 [复制链接] [打 印][]
赞助商链接