zoukankan      html  css  js  c++  java
  • IOS UI 自定义navigationBar布局

    • navigationBar背景设置
        //1. 配置navigationBar背景图片
        [self.navigationController.navigationBar setBackgroundImage:[UIImage
        imageNamed:@"header_bg.png" ] 
        forBarMetrics:UIBarMetricsDefault];
    • 设置中间标题图片
        //2.配置中间标题为图片
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 60, 35)];
        imageView.image = [UIImage imageNamed:@"logo_title.png"];
        self.navigationItem.titleView=imageView;
    • 设置navigationBar左右按钮
      navigationBar按钮常见样式有三种,分别为文本样式、系统样式、自定义样式

    1.文本样式

        UIBarButtonItem *textItem = [[UIBarButtonItem alloc] initWithTitle:@"分类" 
        style:UIBarButtonItemStylePlain target:self 
        action:@selector(dealConfig:)];

    2.系统样式

    UIBarButtonItem *systemItem = [[UIBarButtonItem alloc] 
    initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self 
    action:@selector(dealConfig:)];
    

    3.自定义样式

    UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    
    leftButton.frame = CGRectMake(0, 0, 45, 30); 
    
     [leftButton setBackgroundImage:[UIImage imageNamed:@"photo_left_nav.png"] forState:UIControlStateNormal];
    
    [leftButton addTarget:self action:@selector(dealConfig:) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
    

    4.添加到界面上

    self.navigationItem.leftBarButtonItem = leftItem;
    self.navigationItem.rightBarButtonItem = rightItem;

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

  • 相关阅读:
    python学习之计算机基础详解
    python学习笔记-day03
    名称空间与作用域
    函数参数的应用
    day14
    day13
    函数的基本使用
    day12
    day 09
    文件操作
  • 原文地址:https://www.cnblogs.com/yuqingzhude/p/4836546.html
Copyright © 2011-2022 走看看