#pragma mark 快速创建一个item
- (UIBarButtonItem *)itemWithNormal:(NSString *)normal highlighted:(NSString *)highlighted selector:(SEL)selector {
// 初始化按钮
UIButton *button = [[[UIButton alloc] init] autorelease];
button.title.font = [UIFont systemFontOfSize:10];
// 设置按钮背景图片
UIImage *normalImg = [UIImage imageNamed:normal];
UIImage *highlightedImg = [UIImage imageNamed:highlighted];
button.bounds = CGRectMake(, , normalImg.size.width, normalImg.size.height);
[button setBackgroundImage:normalImg forState:UIControlStateNormal];
[button setBackgroundImage:highlightedImg forState:UIControlStateHighlighted];
// 监听按钮点击
[button addTarget:self action:selector forControlEvents:UIControlEventTouchUpInside];
// 初始化item
return [[[UIBarButtonItem alloc] initWithCustomView:button] autorelease];
}
 // 设置左边
self.navigationItem.leftBarButtonItem = [self itemWithNormal:@"left.png"
highlighted:@"leftHigh.png" selector:@selector(send)]; // 设置右边
self.navigationItem.rightBarButtonItem = [self itemWithNormal:@"right.png"
highlighted:@"rightHigh.png" selector:@selector(refresh)];
 // 设置cell的背景色
UIView *bg = [[[UIView alloc] init] autorelease];
bg.backgroundColor = [UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:];
cell.backgroundView = bg;
 // 设置cell选中的背景
UIView *selectdBg = [[[UIView alloc] init] autorelease];
selectdBg.backgroundColor = [UIColor colorWithRed:0.85 green:0.85 blue:0.85 alpha:];
cell.selectedBackgroundView = selectdBg;
 //设置按钮的标题和颜色
[btn setNormalBg:@"normal.png" andHightlighted:@"highlight.png"];
[btn setTitle@"title" forState:UIControlStateNormal];
[btn setTitleColor:[UIColor balckColor] forState:UIControlStateNormal];
UIButton *button = [[[UIButton alloc] init] autorelease];
//字体大小
button.title.font = [UIFont systemFontOfSize:];
//自动对齐
button.title.textAlignment = NSTextAlignmentCenter;
//设置背景图片
[button setBackgroundImage:[UIImage resizeImage:@"image.png"] forState:UIControlStateNormal];
 UIButton *btn = [[UIButton alloc] init];
UIImage *imageNormal = [UIImage imageNamed:"@image.png"];
[btn setBackgroundImage:imageNormal forState:UIControlStateNormal];
UIImage *highLight = [UIImage imageNamed:"@high.png"];
[btn setBackgroundImage:imageNormal forState:UIControlStateHighlighted];
UIBarButtonItem *item = [[[UIBarButtonItem alloc] initWithCustomView:btn] autorelease];
viewController.navigationItem.rightBarButtonItem = item;
 
 
 
 
 
 
 
 
 
 

UIButton UIBarButtonItem用法的更多相关文章

  1. UIButton UIImage 用法分析

    一.UIButton和UIImageView的区别 1.显示图片 1> UIImageView只能显示一种图片(图片默认会填充整个UIImageView) image\setImage: 2&g ...

  2. swift - UIButton 的用法

    1,按钮的创建 (1)按钮有下面四种类型: contactAdd:前面带“+”图标按钮,默认文字颜色为蓝色,有触摸时的高亮效果 detailDisclosure:前面带“!”图标按钮,默认文字颜色为蓝 ...

  3. UIButton常见用法

    //UIButton是iOS中用来响应用户点击的控件,既可以显示文字,也可以显示图片,也可以处理用户交互 //UIButton的创建,一般采用类方法来创建,不需要释放 //UIButton 也是UIC ...

  4. Swift之贪婪的UIButton

    一.内容概要 按钮是所有UI体系中非常重要的组件,在iOS中按钮UIButton的使用也非常灵活,本文将从以下几点介绍UIButton的使用(基于Swift2.0): 1.UIButton基础 2.U ...

  5. iOS开发之四:常用控件--UIButton的使用

    在介绍UIButton的用法前,要先了解一下它的父类UIControl,UIControl是所有具有事件处理功能控件的父类. 而该类控件一般响应事件又有三种形式:基于触摸.基础值.基础编辑.控件的层次 ...

  6. 【Demo 0006】iOS常用控件

    本章学习要点       1.  了解iOS中控件继承关系:       2.  掌握UIControl基础知识;       3.  掌握UIButton基本用法:       4.  掌握UILa ...

  7. iOS - Xcode项目统计总代码行数

    最新公司需要把项目代码量统计一下,第一时间找到Xcode插件管理工具Alcatraz,查找插件ZLXCodeLine,这是一个快速统计Xcode工程项目代码量的插件,好像已经不支持Alcatraz安装 ...

  8. 第十篇、自定义UIBarButtonItem和UIButton block回调

    // 自定义导航栏左边按钮 self.navigationItem.leftBarButtonItem = [JQBlockedBarButtonItem blockedBarButtonItemWi ...

  9. 关于UIButton嵌入到UIView点击无反应问题的解决方法和delegate的简单用法示例(转载)

    做项目封装UIView的时候碰到的问题,没想到有个哥们儿还写成博客,特此收藏! 问题是这样的,几个界面用到同一个自定义返回按钮,于是就想着把这个按钮单独封装起来,添加一个UIView类,在里面自定义U ...

随机推荐

  1. 通过js动态创建button

    通过js动态创建button 一.实例描述 通过JS的DOM对象,实现元素的动态创建. 二.效果 三.代码 <!DOCTYPE html> <html lang="zh-c ...

  2. Python: PS 图像调整--对比度调整

    本文用 Python 实现 PS 里的图像调整–对比度调整.具体的算法原理如下: (1).nRGB = RGB + (RGB - Threshold) * Contrast / 255 公式中,nRG ...

  3. Impala储存与分区

    不多说,直接上干货! hive的元数据存储在/user/hadoop/warehouse Impala的内部表也在/user/hadoop/warehouse. 那两者怎么区分,看前面的第一列. 下面 ...

  4. tcpdump重要笔记

    无关痛痒的參数就不写了.仅仅说一些我觉得值得注意的. 1 tcpdump參数 -s 最早在公司旧机器上截包时发现总是不完整,于是知道了这个參数,之后就一直用-s0了.近期一次在家里,忘记输入-s发现包 ...

  5. Scala具体解释---------类

    Scala中的类 摘要: 在本篇中.你将会学习怎样用Scala实现类. 假设你了解Java或C++中的类,你不会认为这有多难.而且你会非常享受Scala更加精简的表示法带来的便利.本篇的要点包含: 1 ...

  6. LeetCode 136 Single Number(仅仅出现一次的数字)

    翻译 给定一个整型数组,除了某个元素外其余元素均出现两次. 找出这个仅仅出现一次的元素. 备注: 你的算法应该是一个线性时间复杂度. 你能够不用额外空间来实现它吗? 原文 Given an array ...

  7. The program yum-complete-transaction is found in the yum-utils package

    用yum安装的时候出现 The program yum-complete-transaction is found in the yum-utils package. 错误提示的解决方法:# 安装 y ...

  8. 从USB闪存驱动器启动 Hiren的BootCD --制作U盘启动盘

    从USB闪存驱动器启动 Hiren的BootCD 原文  http://www.hirensbootcd.org/usb-booting/ 本文基本上是翻译而来 要从USB闪存驱动器启动Hiren的B ...

  9. Linux shell command学习笔记(二)

    <cut> 作用:从输入文件或者命令的输出中析取出各种域 用法:cut –c{字符串范围} –d{字段间分割符} –f{字段索引编号} 举例: (1)查看在线用户:who | cut –c ...

  10. react radio onchange事件点击无效

    记: 项目需求:   页面中radio默认选中        第一次进去页面   点击radio的时候不管怎样点击    都是选中 连onChange事件都没触发 进入页面  点击刷新   点击rad ...