http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 2234|回复: 5

[新手开发之旅] iOS新手开发之旅-自定义设置导航栏按钮

[复制链接]
发表于 2018-12-7 18:16:26 | 显示全部楼层 |阅读模式
本帖最后由 竹林风 于 2018-12-7 18:22 编辑

  文章导航  

【iOS新手开发之旅】   http://www.sufeinet.com/thread-24000-1-1.html                     


ios导航栏rightBarButtonItems多个按钮自定义设置 的方式有多种:


1.带图片的按钮


[Objective-C] 纯文本查看 复制代码
#import "firstVC.h"


@interface firstVC (){
    
    UILabel *lbl;
}

@end

@implementation firstVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor yellowColor];
    self.title = @"Leader";
    
    //    带图片的按钮
    UIButton *informationCardBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [informationCardBtn addTarget:self action:@selector(mineButtonAction) forControlEvents:UIControlEventTouchUpInside];
    [informationCardBtn setImage:[UIImage imageNamed:@"mine"] forState:UIControlStateNormal];
    
    [informationCardBtn sizeToFit];
    UIBarButtonItem *informationCardItem = [[UIBarButtonItem alloc] initWithCustomView:informationCardBtn];
    
    
    UIBarButtonItem *fixedSpaceBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    fixedSpaceBarButtonItem.width = 22;
    
    
    UIButton *settingBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [settingBtn addTarget:self action:@selector(homeButtonAction) forControlEvents:UIControlEventTouchUpInside];
    [settingBtn setImage:[UIImage imageNamed:@"home"] forState:UIControlStateNormal];
    [settingBtn sizeToFit];
    UIBarButtonItem *settingBtnItem = [[UIBarButtonItem alloc] initWithCustomView:settingBtn];
    
    self.navigationItem.rightBarButtonItems  = @[informationCardItem,fixedSpaceBarButtonItem,settingBtnItem];
    
    lbl = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 180, 50)];
    lbl.textColor = [UIColor blueColor];
    [self.view addSubview:lbl];
    
}

-(void)mineButtonAction{
    
    lbl.text = @"点击了我的按钮";
}

-(void)homeButtonAction{
    
    lbl.text = @"点击了主页按钮";
}


看效果:

Untitled.gif

2.添加多个文字描述的按钮

[Objective-C] 纯文本查看 复制代码
UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"register", nil) style:UIBarButtonItemStylePlain target:self action:@selector(registerClick)];
    UIBarButtonItem *anotherButton2 = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"login", nil) style:UIBarButtonItemStylePlain target:self action:@selector(loginClick)];
    [self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects: anotherButton,anotherButton2,nil]];
    
    lbl = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 180, 50)];
    lbl.textColor = [UIColor blueColor];
    [self.view addSubview:lbl];


[Objective-C] 纯文本查看 复制代码
-(void)registerClick{
    
    lbl.text = @"点击了注册按钮";
}

-(void)loginClick{
    
    lbl.text = @"点击了登录按钮";
}


看效果:

2.gif


附件: Test-自定义UIBarButtonItem.zip (159.9 KB, 下载次数: 0)


1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2018-12-7 18:48:06 | 显示全部楼层
强烈支持楼主ing……
发表于 2018-12-7 18:52:08 | 显示全部楼层
看到这帖子真是高兴!
发表于 2018-12-7 19:05:21 | 显示全部楼层
我只是路过打酱油的。
发表于 2018-12-8 17:39:04 | 显示全部楼层
路过 酱油 不懂IOS
发表于 2018-12-8 18:23:13 | 显示全部楼层
强烈支持楼主ing……
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-4-25 18:24

© 2014-2021

快速回复 返回顶部 返回列表