自定义Navigation按钮及Title

导航栏自带的按钮,时常不能满足要求,所以深深需要进行各种定制.

写一个UINavigationItem的category

// UINavigationItem+CB_ChangeButton.h


@interface UINavigationItem (CB_ChangeButton)

- (void) CB_SetRightButton:(UIButton *)button;

- (void) CB_SetLeftButton:(UIButton *)button;

- (void) CB_SetNavigationTitle:(NSString *)title;


@end

 

//  UINavigationItem+CB_ChangeButton.m


#import "UINavigationItem+CB_ChangeButton.h"

@implementation UINavigationItem (CB_ChangeButton)

- (void) CB_SetRightButton:(UIButton *)button {
    
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView: button];
    self.rightBarButtonItem = rightItem;
}

- (void) CB_SetLeftButton:(UIButton *)button {
    
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView: button];
    self.leftBarButtonItem = leftItem;
}

- (void) CB_SetNavigationTitle:(NSString *)title {
    
    UILabel *label = [[UILabel alloc] initWithFrame: CGRectMake( 0, 0, 320, 44)];
    label.text = title;
    label.textColor = [UIColor whiteColor];
    label.font = FONT;
    label.textAlignment = NSTextAlignmentCenter;
    self.titleView = label;
}

@end


转载于:https://www.cnblogs.com/jz319/p/3729283.html

以下是uniapp自定义左上角返回按钮的方法: 1.在App.vue中添加以下代码: ```vue <template> <view> <navigation-bar :title="title" :left-text="leftText" :background-color="backgroundColor" :fixed="fixed" @click-left="onClickLeft"></navigation-bar> <router-view></router-view> </view> </template> <script> export default { data() { return { title: 'uni-app', leftText: '返回', backgroundColor: '#ffffff', fixed: true } }, methods: { onClickLeft() { uni.navigateBack({ delta: 1 }) } } } </script> ``` 2.在需要使用自定义返回按钮的页面中,将navigationBarTitleText改为false,并在navigationBar中添加自定义返回按钮样式: ```vue <template> <view> <navigation-bar :title="title" :background-color="backgroundColor" :fixed="fixed" :back-text="backText" :delta="delta" @click-left="onClickLeft" left-icon="back"></navigation-bar> <text>这是一个需要自定义返回按钮的页面</text> </view> </template> <script> export default { data() { return { title: 'uni-app', backgroundColor: '#ffffff', fixed: true, backText: '', delta: 1 } }, methods: { onClickLeft() { uni.navigateBack({ delta: this.delta }) } } } </script> <style> /* 自定义返回按钮样式 */ .uni-icon.back:before { content: "\e6b4"; font-size: 24px; color: #000000; } </style> ``` 在这个例子中,我们使用了uni-app提供的navigationBar组件,并在App.vue中定义了默认的navigationBar样式和点击左侧按钮的方法。在需要自定义返回按钮的页面中,我们将navigationBarTitleText改为false,并在navigationBar中添加了自定义返回按钮样式。同时,我们还定义了点击左侧按钮的方法,使其返回上一页。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值