IOS--导航栏
来源:互联网 发布:php文件管理系统代码 编辑:程序博客网 时间:2024/06/10 03:52
#import <UIKit/UIKit.h>
#import "MyViewController.h"
@interface AppDelegate :UIResponder <UIApplicationDelegate>
@property (strong,nonatomic) UIWindow *window;
@property (strong,nonatomic) UINavigationController *navController;
@property (strong,nonatomic) UIViewController *viewController;
@end
#import "AppDelegate.h"
@implementation AppDelegate
@synthesize window =_window;
@synthesize navController;
@synthesize viewController;
- (void)dealloc
{
[_windowrelease];
[superdealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindowalloc] initWithFrame:[[UIScreenmainScreen] bounds]]autorelease];
self.window.backgroundColor = [UIColorwhiteColor];
self.viewController = [[[MyViewControlleralloc]init]autorelease];
self.navController = [[UINavigationControlleralloc] initWithRootViewController:self.viewController];
[self.windowaddSubview:navController.view];
[self.windowmakeKeyAndVisible];
return YES;
}
@end
#import <UIKit/UIKit.h>
@interface MyViewController :UIViewController
@end
#import "MyViewController.h"
@implementation MyViewController
- (void)viewDidLoad
{
[superviewDidLoad];
//设置导航栏背景图片
[self.navigationController.navigationBarsetBackgroundImage:[UIImageimageNamed:@"nav-bar.png"]forBarMetrics:UIBarMetricsDefault];
//导航栏正中央图片
UIImage * titleImage = [UIImageimageNamed:@"nav-logo.png"];
UIImageView * titleview = [[UIImageViewalloc]initWithImage:titleImage];
//加在导航栏中
self.navigationItem.titleView =titleview;
//绘制导航栏右侧的图片按钮
UIImage *rightButtonImage = [UIImageimageNamed:@"nav-bar-button.png"];
UIImage *rightbuttonNormal = [rightButtonImage
stretchableImageWithLeftCapWidth:10topCapHeight:10];
//设置按钮类型为自定义
UIButton *rightButton = [UIButtonbuttonWithType:UIButtonTypeCustom];
//设置按钮的显示区域
[rightButtonsetFrame: CGRectMake(0,0, 50, 40)];
//设置按钮的背景显示图
[rightButton setBackgroundImage:rightbuttonNormalforState:UIControlStateNormal];
//设置按钮的前景显示图
[rightButton setImage:[UIImageimageNamed:@"nav-friends-icon.png"]forState:UIControlStateNormal];
[rightButton setImage:[UIImageimageNamed:@"nav-friends-icon.png"]forState:UIControlStateHighlighted];
//监听点击事件
[rightButton addTarget:selfaction:@selector(RightDown)forControlEvents:UIControlEventTouchDown];
//加载导航栏中
self.navigationItem.rightBarButtonItem = [[UIBarButtonItemalloc]initWithCustomView:rightButton];
//含义和上面类似就不详解了
//绘制导航栏左侧的图片按钮
UIImage *leftButtonImage = [UIImageimageNamed:@"nav-bar-button.png"];
UIImage *leftbuttonNormal = [leftButtonImage
stretchableImageWithLeftCapWidth:10topCapHeight:10];
UIButton *leftButton = [UIButtonbuttonWithType:UIButtonTypeCustom];
[leftButtonsetFrame: CGRectMake(0,0, 50, 40)];
[leftButton setBackgroundImage:leftbuttonNormalforState:UIControlStateNormal];
[leftButton setImage:[UIImageimageNamed:@"nav-menu-icon.png"]forState:UIControlStateNormal];
[leftButton setImage:[UIImageimageNamed:@"nav-menu-icon.png"]forState:UIControlStateHighlighted];
[leftButton addTarget:selfaction:@selector(leftDown)forControlEvents:UIControlEventTouchDown];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItemalloc]initWithCustomView:leftButton];
}
-(void) leftDown
{
NSLog(@"左边按钮");
}
-(void) RightDown
{
NSLog(@"右边按钮");
}
@end
- IOS导航栏UINavigation
- ios 导航栏风格
- ios 导航栏显示
- IOS-导航栏风格
- ios 导航栏设置
- iOS 导航栏
- ios顶部导航栏
- 关于iOS导航栏
- iOS导航栏颜色
- iOS导航栏
- iOS导航栏遮盖
- IOS--导航栏
- iOS 导航栏设置
- iOS 隐藏导航栏
- iOS导航栏使用
- IOS ---设置导航栏
- iOS自定义导航栏
- iOS自定义导航栏
- 最短路径基础
- hihocoder 1142 : 三分·三分求极值
- 关于apache tomcat的几个版本
- const ||c
- Java堆栈详解
- IOS--导航栏
- 用C++实现“按任意键继续”
- hdu 4635 Strongly connected(强联通)
- Android RecyclerView之添加Item分割线
- js一些常用的效果
- 数据包 数据帧
- Spark修炼之道(高级篇)——Spark源码阅读:第八节 Task执行
- iphone 分辨率问题
- 贪心、递归、递推以及动态规划算法的分析与对比