iOS:使用导航栏

要求使用ARC

//
//  main.m
//  Hello
//
//  Created by lishujun on 14-8-28.
//  Copyright (c) 2014年 lishujun. All rights reserved.
//

#import <UIKit/UIKit.h>

// --------------视图控制器对象--------------
@interface HelloWorldViewController : UIViewController
@end

@implementation HelloWorldViewController

-(void) loadView
{
    NSLog(@"load View");
    //创建视图对象
    UIView *contentView = [[UIView alloc]initWithFrame:[[UIScreen mainScreen] applicationFrame]];
    contentView.backgroundColor = [UIColor lightGrayColor];
    self.view = contentView;

    //设置导航栏按钮,被加载的到UINavigationController才可以使用这个属性?
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Next" style:UIBarButtonItemStylePlain target:self action:@selector(pushView:)];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Prev" style:UIBarButtonItemStylePlain target:self action:@selector(popView:)];
}

-(void) pushView:(id)sender
{
    NSLog(@"push view");
    [self.navigationController pushViewController:[[HelloWorldViewController alloc]init] animated:YES];
}

-(void) popView:(id)sender
{
    NSLog(@"pop view");
    [self.navigationController popViewControllerAnimated:YES];
}

@end

// ----------------委托对象--------------------
@interface HelloWorldAppDelegate : NSObject <UIApplicationDelegate>
{
    IBOutlet UIWindow *window;
}

@property (nonatomic, retain) UIWindow *window;
@property (nonatomic, retain) UINavigationController *nav;

@end

@implementation HelloWorldAppDelegate

@synthesize window;
@synthesize nav;

-(void) applicationDidFinishLaunching:(UIApplication *)application
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen]bounds]];
    HelloWorldViewController *viewController = [[HelloWorldViewController alloc]init];

    self.nav = [[UINavigationController alloc]initWithRootViewController: viewController];
    self.window.rootViewController = self.nav;
    [self.window makeKeyAndVisible];
}
@end

// ---------------程序入口---------------------
int main(int argc, char * argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, @"HelloWorldAppDelegate");
    }
}
时间: 2024-07-30 11:14:11

iOS:使用导航栏的相关文章

iOS 为导航栏自定义按钮图案Button Image 运行出来的颜色与原本颜色不一样 -解决方案

为相机制作闪光灯,在导航栏自定义了"闪光"图案,希望点击时变换图片,但是一直没有改变,原来是因为设置了Global Tint的颜色,所以系统会自动把图片的颜色改为Global Tint的颜色. 解决方案,设置图片时,添加:imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal 源码: - (void) setFlashOn:(BOOL)isOn { if (self.captureDevice.hasFlash) { UIIm

iOS 去掉导航栏的边界黑线&amp;去掉搜索框的边界黑线和其中文本输入框的阴影 - 解决方案

去掉导航栏的边界黑线 in viewDidload: [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault]; self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init]; 去掉搜索框的边界黑线 in viewDidload:

iOS开发导航栏控件的作用

一,在iOS开发过程中针对一些导航栏上需要自定义视图的情况,有时候需要用系统自带的处理,有些时候需要自定义一些视图并把视图添加上去,这时候主要是它们的位置有些许差别,下面简单写下demo: 1,用导航栏系统自带的视图处理: 1 //1 中间的图片 2 UIImageView *imageBarView = [[UIImageView alloc] initWithFrame:CGRectMake(kScreenWidth / 2.f - 40.f, 20.f, 80, 30)]; 3 image

IOS 自定义导航栏

我们自己新建一个View,来自定义导航栏,如下代码: #import <UIKit/UIKit.h> @interface CustomNavigation : UIView typedef enum { customEventClickLBtn1 ,//点击了最左边的按钮 customEventClickRBtn1 , //最右边的按钮 customEventClickLBtn2 ,//点击了左边第二个按钮 customEventClickRBtn2 //点击了右边最靠左的按钮 }Custo

【转】【iOS】导航栏那些事儿

原文网址:http://www.jianshu.com/p/f797793d683f 参考文章 navigationItem UINavigationItem UINavigationBar UIBarButtonItem UIButton iOS 7 教程:定制iOS 7中的导航栏和状态栏 前言 本文试图阐释清楚导航栏相关的概念和用法,比如UINavigationBar和UINavigationItem的区别和联系,UIBarButtonItem的用法以及在纯代码和storyboard中有什么

iOS项目导航栏返回按钮

最近iOS项目中要求导航栏的返回按钮只保留那个箭头,去掉后边的文字,在网上查了一些资料,最简单且没有副作用的方法就是 [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60) forBarMetrics:UIBarMetricsDefault]; 参考自这里:http://stackoverflow.com/questions/19078995/removing-the-titl

iOS navigationBar导航栏底部与self.view的分界线的隐藏

ios开发中经常碰到各种需求,比如要求导航栏的颜色和self.view的颜色一样,当我们直接设置navigationBar的颜色和view一样时,我们会发现navigationBar还会有一条分割线留下,本文就是介绍怎么隐藏导航栏底部的分割线的. 第一种方法:不会影响导航栏translucent 半透明的显示 首先在viewDidLoad 定义一个 UIImageView *navigationImageView 来存储底部分割线. UIImageView *navigationImageVie

IOS 自定义导航栏标题和返回按钮标题

IOS中自定义导航栏标题: UILabel *titleText = [[UILabel alloc] initWithFrame: CGRectMake(160, 0, 120, 50)]; titleText.backgroundColor = [UIColor clearColor]; titleText.textColor=[UIColor whiteColor]; [titleText setFont:[UIFont systemFontOfSize:17.0]]; [titleTex

ios 自定义导航栏,开启侧滑返回手势

自定义一个常用ListViewController .h文件 1 #import <UIKit/UIKit.h> 2 3 @interface ListViewController : UIViewController 4 5 -(void)diquButtonClick; 6 7 @end .m文件 1 // 2 // ListViewController.m 3 // OuLianWang 4 // 5 // Created by allenariel on 15/6/24. 6 // C

ios UINavigationController 导航栏

1.关于导航栏左右两边的按钮 1.隐藏导航栏上的返回字体 //Swift UIBarButtonItem.appearance().setBackButtonTitlePositionAdjustment(UIOffsetMake(0, -60), forBarMetrics: .Default) //OC [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60) forBarM