Snail—UI学习之自定义导航栏NSNavigationController

首先新建一个RootViewController 再建一个FirstViewController

在RootViewController.m中写入

#import "WJJRootViewController.h"
#import "WJJFirstViewController.h"

@interface WJJRootViewController ()

@end

@implementation WJJRootViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor grayColor];
    [self createMyNavigationBar];
}

- (void)createMyNavigationBar{
    //手机最上面的状态栏20像素 系统导航栏高度为44 所以一共64像素
    UIView * navigationBar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 64)];
    navigationBar.backgroundColor = [UIColor redColor];
    [self.view addSubview:navigationBar];

    //定义一个按钮
    UIButton * pushButton = [UIButton buttonWithType:UIButtonTypeSystem];
    pushButton.frame = CGRectMake(self.view.frame.size.width- 10 - 50, 27, 50, 30);
    [pushButton setTitle:@"下一页" forState:UIControlStateNormal];
    [pushButton addTarget:self action:@selector(nextPage) forControlEvents:UIControlEventTouchUpInside];
    //把按钮放在自定义的导航栏上
    [navigationBar addSubview:pushButton];
}

- (void)nextPage{
    WJJFirstViewController * first = [[WJJFirstViewController alloc] init];
    [self.navigationController pushViewController:first animated:YES];
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    //因为后面的界面有可能使用系统导航栏 会把此属性设置为NO不隐藏 所以有必要在这设置一下 以防万一
    self.navigationController.navigationBarHidden = YES;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

然后 在firstViewController.m 中写入

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor blackColor];
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    //设置系统导航栏不隐藏  使用系统导航栏
    self.navigationController.navigationBarHidden = NO;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-08-29 08:30:40

Snail—UI学习之自定义导航栏NSNavigationController的相关文章

Snail—UI学习之自定义标签栏UITabBarController

这里的背景跟上面的差不多 不过这里要用到AppDelegate的单例进行传值 首先到AppDelegate.h文件中 <span style="color:#FF0000;">#import <UIKit/UIKit.h> @interface WJJRootViewController : UITabBarController //声明一UIButton属性 来记录当前按下的按钮 @property (nonatomic,strong) UIButton *

Snail—UI学习之自定义键盘及键盘收起(待完善)

在viewController.h中加入代理 #import <UIKit/UIKit.h> @interface WJJRootViewController : UIViewController <span style="color:#FF0000;"><UITextFieldDelegate></span> @end viewController.m中代码展示 #import "WJJRootViewController.h

Snail—UI学习之自定义通知NSNotification

背景是:一个界面跳转到第二个界面 然后 第一个界面发了一个通知  然后第二个界面收到这个通知后 把里面的数据取出来 在RootViewController.m中写入下面代码 #import "WJJRootViewController.h" #import "WJJFirstViewController.h" @interface WJJRootViewController (){ UITextField * _textField; } @end @implemen

React Native自定义导航栏

之前我们学习了可触摸组件和页面导航的使用的使用: 从零学React Native之09可触摸组件 - 从零学React Native之03页面导航 - 经过之前的学习, 我们可以完成一个自定义导航栏了, 效果如下: 我们需要创建一个 NaviBar.js 用来显示顶部的导航栏, 还需要四个界面(Page1.js,Page2.js,Page3.js,Page4.js). 当然还需要修改index.android.js或者index.ios.js 用来处理4个界面的切换. 导航栏NaviBar 实现

一些关于iOS系统导航栏与自定义导航栏的事情

关于系统导航栏是真的让人又爱又恨,爱的是苹果本身对这个控件的封装已经是很完美了,包括内存.美化.渐变动画等等,一般来说,基本上所有需求都可以满足的.但是你要知道什么东西到了中国,就会发生翻天覆地的变化,例如后台的数据并发.在国内奇葩的产品设计之下,导航栏也是面目全非,反正我看了比较著名的APP,发现他们的导航栏基本都是自定义,其中牵扯最大的问题就是导航栏自身的隐藏.颜色渐变. 其实通过APP运行时,你可以看到系统NavigationBar的分层.一个navigationBar是分很多层的,并非我

自定义导航栏标题按钮

自定义标题栏按钮 @implementation SNTitleButton - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { //图片居中 self.imageView.contentMode = UIViewContentModeCenter; //字体居右 self.titleLabel.textAlignment = NSTextAlignmentRight; //字体

ios7以上自定义导航栏标题的字体大小及颜色的方法

自定义导航栏的字体和颜色,只需要自定义一个lable,然后将lable添加到导航栏的titleview中就可以了 代码如下 UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0,0,0,0)];//这个frame是初设的,没关系,后面还会重新设置其size. [label setNumberOfLines:0]; UIFont *font = [UIFont fontWithName:@"Arial" size:17]

自定义导航栏返回按钮文字

自定义导航栏返回按钮文字 by 伍雪颖 navigationItem.backBarButtonItem = UIBarButtonItem(title: "返回", style: UIBarButtonItemStyle.Plain, target: nil, action: nil)

自定义导航栏

1.设置导航栏样式 [self.navigationBar setBackgroundImage:[UIImage imageNamed:@"navibarbackground"] forBarMetrics:UIBarMetricsDefault]; [self.navigationBar setTintColor:[UIColor whiteColor]];//BarItem颜色 NSShadow *shadow = [NSShadow new]; shadow.shadowCol