独狼

导航

记录一些容易忘记的属性 -- UINavigationController

  //设置导航栏的风格
    self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
    //设置导航栏是否透明 NO不透明, YES 透明,默认为YES;

    //当导航栏的translucent属性设置为YES,则在当前视图控制器的坐标原点为屏幕左上角
    //当导航栏的translucent属性设置为NO,则在当前视图控制器的坐标原点在屏幕左上角(往Y轴方向距离导航栏的高度(44))
    self.navigationController.navigationBar.translucent =  NO;

    //设置导航栏上导航元素项的颜色
    self.navigationController.navigationBar.tintColor = [UIColor yellowColor];

    //设置导航栏的前景颜色
    self.navigationController.navigationBar.barTintColor = [UIColor cyanColor];

  //隐藏导航栏
    self.navigationController.navigationBarHidden = NO;
    
    //设置导航栏的背景图片
    //UIBarMetricsDefault 肖像画(正屏)
    //UIBarMetricsLandscapePhone 风景画(侧屏)
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navBarBG1"] forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navBarBG2"] forBarMetrics:UIBarMetricsLandscapePhone];

    //设置导航项的标题视图,这个优先级比下面的两种方式高
    UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
    titleView.backgroundColor = [UIColor purpleColor];
    self.navigationItem.titleView = titleView;
    
    //设置视图控制器的名称
    //这两方式设置的优先级一致,谁后设置,用谁的名字
  1  self.navigationItem.title = @"controllOne";
  2  self.title = @"控制器一";

 

    //所有的导航元素项放在视图控制器的navigationItem里
    //所有的视图控制器都有自己独立的导航元素项,但是公用一个导航栏

    //裁剪超出边界的部分
    self.navigationController.navigationBar.clipsToBounds = YES;

 

posted on 2014-09-24 19:48  独狼  阅读(191)  评论(0编辑  收藏  举报