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]];

 [titleText setText:@"XXX"];

 self.navigationItem.titleView=titleText;

 [titleText release];

IOS中自定义导航栏返回按钮:(放在pushViewController之前)

UIBarButtonItem *backItem=[[UIBarButtonItem alloc]init];

  backItem.title=@"后退";

  backItem.tintColor=[UIColor colorWithRed:129/255.0 green:129/255.0  blue:129/255.0 alpha:1.0];

  self.navigationItem.backBarButtonItem = backItem;

  [backItem release];

IOS中自定义导航栏右边按钮:

UIBarButtonItem * rightButton = [[UIBarButtonItem alloc]

                                                initWithTitle:@"回到首页"

                                                style:UIBarButtonItemStyleBordered

                                                target:self

                                                action:@selector(callModalList)];

rightButton.image=[UIImage imageNamed:@"right_button.png"];

rightButton.tintColor=[UIColor colorWithRed:74/255.0 green:74/255.0 blue:74/255.0 alpha:1.0];

self.navigationItem.rightBarButtonItem = rightButton;

[rightButton release];

或者

    //设置返回按钮

    UIButton* backButton = [UIButton buttonWithType:UIButtonTypeCustom];

    [backButton setBackgroundImage:[UIImage imageNamed:@"btn_public_back"] forState:UIControlStateNormal];

    backButton.frame = CGRectMake(0, 0, 35,35);

    [backButton addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];

    leftBarItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];

    self.navigationItem.leftBarButtonItem = leftBarItem;
时间: 2024-12-27 10:20:46

IOS 自定义导航栏标题和返回按钮标题的相关文章

iOS 自定义导航栏笔记

一.UINavigationBar的结构 导航栏几乎是每个页面都会碰到的问题,一般两种处理方式:1.隐藏掉不显示 2.自定义 1. 添加导航栏 TestViewController * mainVC = [[TestViewController alloc] init]; UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController:mainVC]; self.window.ro

ios 自定义导航栏和分割线

自定义导航栏: // CustomNaviBarView.h #import <UIKit/UIKit.h> @interface CustomNaviBarView : UIView { @private /** * 左侧按钮 */ UIButton* _leftButton; /** * 右侧按钮 */ UIButton* _rightButton; /** * 中部标签 */ UILabel* _navTitle; } @property(nonatomic,strong)UIButto

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 自定义导航栏

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

iOS 自定义导航栏的返回按钮

UIBarButtonItem * item  =    [UIBarButtonItem appearance]; UIImage* image = [UIImage imageNamed:@"back_icon"]; [item setBackButtonBackgroundImage:[image resizableImageWithCapInsets:UIEdgeInsetsMake(0, image.size.width, 0, 0)] forState:UIControlS

自定义导航栏之滑动返回

以前我们所有的滑动返回,只是系统自带的滑动返回,只能在屏幕的左侧滑动才能到达效果. 但是QQ,新浪微博之类的应用,有在屏幕中间滑动也能返回的效果. 下面我们来看具体的实现代码: 我需要创建一个类继承 UINavigationController OC语言实现: #import "BaseNavigationController.h" @interface BaseNavigationController () @end @implementation BaseNavigationCon

IOS 自定义导航栏背景

//- (void)setBackgroundImage:(UIImage *)backgroundImage forBarMetrics:(UIBarMetrics)barMetrics NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR; -(id)init { self=[super init]; if(self) { UINavigationBar *navBar=[self navigationBar]; if([navBar respondsTo

微信小程序自定义导航栏(wx_custom_navigation_bar) 自定义返回键、首页键,动态设置标题,响应式组件

微信小程序自定义导航栏 navigation bar 返回键 首页 github: https://github.com/chen-yt/wx_custom_navigation_bar https://github.com/Superman2113/wx_custom_navigation_bar 代码 navbar组件 navbar.wxml <view class="navbar" style="{{'height: ' + navigationBarHeight

ios开发之自定义默认生成的导航栏 标题 颜色 返回按钮

一 修改导航栏颜色    导航栏在哪个页面代码放在那里面 self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:(21.0/255.0) green:(153.0 / 255.0) blue:(224.0 / 255.0) alpha:1];                                                   //定义导航栏颜色 self.navigationItem.t