导航栏自定义一个UIBarButtonItem最快的方式

1 + (UIBarButtonItem *)itemWithIcon:(NSString *)icon highIcon:(NSString *)highIcon target:(id)target action:(SEL)action
2 {
3     UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
4     [button setBackgroundImage:[UIImage imageWithName:icon] forState:UIControlStateNormal];
5     [button setBackgroundImage:[UIImage imageWithName:highIcon] forState:UIControlStateHighlighted];
6     button.frame = (CGRect){CGPointZero, button.currentBackgroundImage.size};
7     [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
8     return [[UIBarButtonItem alloc] initWithCustomView:button];
9 }
时间: 2024-08-07 10:22:54

导航栏自定义一个UIBarButtonItem最快的方式的相关文章

iOS 为导航栏自定义按钮图案Button Image 运行出来的颜色与原本颜色不一样 -解决方案

为相机制作闪光灯,在导航栏自定义了"闪光"图案,希望点击时变换图片,但是一直没有改变,原来是因为设置了Global Tint的颜色,所以系统会自动把图片的颜色改为Global Tint的颜色. 解决方案,设置图片时,添加:imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal 源码: - (void) setFlashOn:(BOOL)isOn { if (self.captureDevice.hasFlash) { UIIm

iOS NavigationBar 导航栏自定义

1. 设置导航栏NavigationBar的背景颜色: a)  setBarTintColor : 设置NagivationBar的颜色 也可以用 : [[UINavigationBar appearance] setBarTintColor:[UIColor yellowColor]]; (在UINavigationController执行pushViewController的界面里再次setBarTintColor后颜色还会变,说明设置的是同一个UINavigationBar,) b)  在

ios 导航栏(自己定义和使用系统方式)

系统方式: //1.设置导航栏背景图片 [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault]; self.navigationController.navigationBar.shadowImage = [[UIImage alloc]init]; [[self navigationController] setNa

zabbix导航栏自定义Label、Zatree在新浏览器新标签页打开的方法

1.  vim $zabbix_PATH/include/menu.inc.php 284行增加以下内容 284         'zatree'=>array( 285         'label' => _('Zatree'), 286         'user_type'                             => USER_TYPE_ZABBIX_USER, 287         'default_page_id'       => 0, 288  

【转心理文章一篇】白岩松:毁掉一个孩子最快的方式

跌跌撞撞,有哭有笑,才是成长. 去年年底,看到这样一组数据: 全球五分之一的青少年受心理健康问题困扰. 媒体也曾报道,中国有20%的少年儿童出现抑郁症状,抑郁症成为孩子自杀的第二大原因. 这些数据瞬间扎心,想到了我曾经的同事阿梅. 阿梅的女儿,就在去年被确诊为中度抑郁. 那天,阿梅在朋友圈写下一句话:“比起健康快乐,优秀一文不值.” 发完这条之后,她就辞职了,朋友圈也停更了. 一年了,她一直陪着女儿对抗抑郁. 为了帮帮她,我也多次在网上搜索相关案例. 才发现,与抑郁相关的学生自杀和心理变态事件层

iOS 自定义导航栏笔记

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

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

ios 导航栏透明, 上下滑动 导航栏 颜色渐变

p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "PingFang SC"; color: #008400 } p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #3d1d81 } p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #008400 } p.p4 {

<iOS 导航栏>第一节:导航栏透明方法实现代码

说下导航栏的透明方法: 很多应用需要导航栏随着向上滑动,逐渐从透明变成不透明,很炫酷,大部分应用都在使用导航栏渐变效果,现附上代码然后直接将实现,一会讲下如何来实现,这一部分直接上代码. 先附上代码: 方法声明: #import <UIKit/UIKit.h> @interface IDSNavBarView : UIView - (instancetype)initWithFrame:(CGRect)frame titleImg:(UIImage *)aTitleImg; - (UILabe