`
sb122k
  • 浏览: 65893 次
  • 性别: Icon_minigender_1
  • 来自: 长沙
社区版块
存档分类
最新评论

定制 UIBarButtonItem:

    博客分类:
  • ios
阅读更多

 


 navigationController 内部有一个栈的实现,管理所有的view , 栈的底部是 根视图, 栈的顶部是当前显示的视图。
A navigation controller object manages the currently displayed screens using the navigation stack. At the bottom of this stack is the root view controller and at the top of the stack is the view controller currently being displayed.

如果要显示新的视图:[self.navigationController pushViewController:viewController animated:YES];

所有继承自 UIViewController 的类,都有 navigationController 和 navigationItem 的属性,如果该类被加入到一个navigationController  的栈中,它的属性就指向 这个navigationController 。

navigationBar 一般有 左右两个按钮:
左侧按钮是 回退 或 取消:

The bar button item on the left side of the navigation bar allows for navigation back to the previous view controller on the navigation stack. The navigation controller updates the left side of the navigation bar as follows:

  • If the new top-level view controller has a custom left bar button item, that item is displayed. To specify a custom left bar button item, set the leftBarButtonItem property of the view controller’s navigation item.

  • If the top-level view controller does not have a custom left bar button item, but the navigation item of the previous view controller has a valid item in its backBarButtonItem property, the navigation bar displays that item.

  • If a custom bar button item is not specified by either of the view controllers, a default back button is used and its title is set to the value of the title property of the previous view controller—that is, the view controller one level down on the stack. (If there is only one view controller on the navigation stack, no back button is displayed.)

    如果 当前的navigationItem 手动设置了  leftBarButtonItem  参数,那么显示这个 buttonItem
    否则, 如果上一个视图手动设置了  backBarButtonItem 参数,那么显示这个buttonItem,
    如果没有手动设置,那么显示默认的回退按钮,title 就是上个视图的title , 指向上个视图,就是栈的下一级。

    如果当前视图是 rootView ,可能需要设置 取消 按钮。


    navigationBar 右侧按钮一般是手动定制的。
    • If the new top-level view controller has a custom right bar button item, that item is displayed. To specify a custom right bar button item, set the rightBarButtonItem property of the view controller’s navigation item.

    • If no custom right bar button item is specified, the navigation bar displays nothing on the right side of the bar.

最后BarButtonItem  ios 5 有setBackButtonBackgroundImage:forState:barMetrics: 方法可指定背景,旧的版本只能通过 initWithCustomVIew 指定一个定制的UIButton 来实现。
http://stackoverflow.com/questions/7066874/customization-of-uinavigationbar-and-the-back-button  这里有完备的实例,通过category 方式封装的。

注意:
When this navigation item is immediately below the top item in the stack, the navigation controller derives the back button for the navigation bar from this navigation item. When this property is nil, the navigation item uses the value in its titleproperty to create an appropriate back button. If you want to specify a custom image or title for the back button, you can assign a custom bar button item (with your custom title or image) to this property instead. When configuring your bar button item, do not assign a custom view to it; the navigation item ignores custom views in the back bar button anyway.

如果用initWithCustomVIew  的方式定制的 BarButtonItem , 设置backBarButtonItem 是不起作用的


注意2:
定制 UIbuttion 可拉伸背景图片,ios 4.3 是 UIImage stretchableImageWithLeftCapWidth:topCapHeight,ios 5后是 UIImage resizableImageWithCapInsets
Return Value:A new image object with the specified cap insets.
他们返回的是一个新的 UIImage 对象,而不是改变现有的对象


0
0
分享到:
评论

相关推荐

    BSYItem:UIBarButtonItem 右或左

    总之,`UIBarButtonItem`在iOS开发中扮演着不可或缺的角色,它的灵活性和可定制性使得我们可以创建各种各样的界面交互。在BSY项目中,根据需求正确设置其方向和功能,能提升应用的用户体验。通过阅读和理解`BSYItem-...

    UIBarButtonItem Demo实例

    在Demo中,`UIBarButtonItemTest`可能包含了创建、定制和使用`UIBarButtonItem`的各种示例。这可能包括不同样式(如`.plain`、`.done`等)、不同事件处理(如点击事件)、以及如何动态改变按钮状态(如禁用、启用)...

    详解iOS应用中自定义UIBarButtonItem导航按钮的创建方法

    本篇文章将详细介绍如何在iOS应用中创建自定义的`UIBarButtonItem`,特别是通过使用图片来定制按钮。 首先,我们来看一下系统提供的四种创建`UIBarButtonItem`的方法: 1. 使用`UIBarButtonSystemItem`创建:这种...

    iOS如何改变UIBarButtonItem的大小详解

    因此,我们需要采取一些额外的步骤来定制按钮的大小。 以下是实现自定义UIBarButtonItem大小的三个关键步骤: 1. **创建自定义控件**: - 在这个例子中,我们选择使用UIButton作为自定义控件,因为它是可交互的,...

    返回按钮定制方法

    标题“返回按钮定制方法”所涉及的核心知识点是如何为导航栏或工具栏创建一个带有左箭头的Bar Button Item。下面我们将详细介绍三种可能的方法来实现这一目标。 **方法一:使用UIImage** 首先,你可以通过创建一个...

    IOS应用源码——伸缩导航按钮.rar

    1. 自定义UIBarButtonItem:系统默认的UIBarButtonItem可能无法满足所有需求,因此开发者通常需要创建自定义按钮,通过设置图像、标题、颜色等属性,甚至实现自定义的点击事件和动画效果。 2. Auto Layout:为了...

    NirSideMenu:通过左右UIBarButtonItem触发的侧滑菜单,并对左侧菜单进行了基本定制

    NirSideMenu是一个用Swift编写的开源库,专门用于创建通过左右`UIBarButtonItem`触发的侧滑菜单。本篇文章将深入探讨NirSideMenu的使用方法及其基本定制过程。 一、NirSideMenu简介 NirSideMenu的核心功能是提供一...

    定制某一个页面导航栏样式(页面加载前).zip

    在iOS开发中,定制页面导航栏样式是提升用户体验和应用个性化的重要手段。"定制某一个页面导航栏样式(页面加载前)"这个主题涉及到的核心知识点主要集中在Objective-C(OC)编程语言,以及UIKit框架中的...

    自定义导航栏返回按钮backBarButtonItem的标题对应的Demo

    如果你需要更高级的定制,比如改变返回按钮的图标或者使用自定义视图,你可以创建一个`UIBarButtonItem`实例,并使用`customView`属性。例如,设置一个带有自定义图片的按钮: ```swift let customView = ...

    第十二章Demo

    通过本章的Demo,你将实践以上知识点,亲手创建并定制工具栏,加深对iOS应用开发中界面元素的理解。记得多尝试,不断调整和优化,以提供最符合用户需求的交互体验。同时,不要忘记在实践中思考,理解每个API背后的...

    swift-PPBadgeView一个iOS自定义Badge组件

    这个组件提供了丰富的定制选项,以满足不同UI设计的需求。 一、Swift-PPBadgeView的特性与功能 1. **多类型支持**:Swift-PPBadgeView不仅支持基本的UIView,还能够方便地应用到UITabBarItem和UIBarButtonItem,...

    使用导航控制器的笔记

    如果需要对返回按钮进行定制,可以创建一个自定义的`UIBarButtonItem`对象,并将其设置为导航项的返回按钮。 ```objective-c // 创建自定义返回按钮 UIBarButtonItem *item = [[UIBarButtonItem alloc] ...

    封装导航栏item

    3. 自定义样式:如果需要自定义Item的外观,如颜色、字体、图片等,可以在封装方法中加入这些定制逻辑。 通过这样的封装,我们可以有效地管理和控制导航栏Item,使代码结构更加清晰,同时提高了开发效率。在实际...

    NavBar 的一个小例子

    这只是一个基础的示例,实际应用中,我们还可以对NavBar进行更复杂的定制,比如改变背景颜色、字体样式、按钮图标等,以满足不同应用场景的需求。 在压缩包文件"NavBar"中,可能包含了这个示例项目的源代码、资源...

    UINavigationController demo

    总的来说,`UINavigationController`是构建iOS应用中导航结构的关键组件,它简化了视图控制器间的切换,并允许我们在导航栏上自由定制功能按钮,以提供丰富的用户体验。通过实践这个“UINavigationController demo”...

    iOS日期选择器简单例子

    在iOS开发中,日期选择器(DatePicker)是一个常用的UI组件,允许用户选择日期或时间。本示例将探讨如何创建一个简单的iOS日期选择器...在实际应用中,还可以根据需求进行更多的定制,如调整日期格式、添加动画效果等。

    IOS 键盘添加工具条 退出 上一项 下一项 简单实现

    在iOS开发中,为用户提供一个方便的键盘工具条可以极大地提升应用的用户体验。"键盘工具条"(Keyboard Tool Bar)通常包含“退出”、“上...通过定制键盘工具条,开发者可以轻松地为应用增加导航功能,提升用户满意度。

    小小词典 ios源码

    源码中还可能涉及到对Bar Button Item的进一步定制,例如改变其颜色、大小或者在不同状态(如选中、不可用)下的表现。这些可以通过修改`UIBarButtonItem`的`tintColor`、`titleTextAttributes`等属性实现,或者使用...

    郑州鹏越教育iOS入门第十课:UINavigateViewController

    除了使用默认的行为,开发者还可以根据需求对UINavigationViewController进行深度定制,例如更改导航栏的外观、添加额外的工具栏等。 #### 自定义导航栏样式 可以修改导航栏的颜色、背景图像等属性来符合应用的...

Global site tag (gtag.js) - Google Analytics