#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. Kinect 开发 —— WaveHand

    基本注释都写了,就不废话了 <Window x:Class="KinectBasicHandTrackingFrameworkTest.MainWindow" xmlns=& ...

  2. Linux基础(vim)

    1.源文件到可执行文件经历了什么? gcc -E main.c -o(输出) main.i 第一阶段:预处理:加载了include文件 gcc -S main.i -o main.s 第二阶段:编译( ...

  3. css--两行显示省略号兼容火狐浏览器

    css--两行显示省略号兼容火狐浏览器 正常写法: .ellipse1{overflow: hidden;white-space: nowrap;text-overflow: ellipsis;} . ...

  4. windows查看硬件信息系统信息

    rem 查看cpu wmic cpu list briefrem 查看物理内存wmic memphysical list briefrem 查看逻辑内存wmic memlogical list bri ...

  5. 一个一线城市的IT白领的生活成本:3万/年

    自从大学毕业,经济独立,就开始全面统计各种生活开支.仔细的去统计下,发现开销还是挺大的. 定理:开销越大,就意味着你每个月的收入必须越高. 三族鼎立节余族: 收入-开支 > 0月光族:收入-开支 ...

  6. Spring3 整合MyBatis3 配置多数据源 动态选择SqlSessionFactory(转)

    1. Spring整合MyBatis切换SqlSessionFactory有两种方法,第一. 继承SqlSessionDaoSupport,重写获取SqlSessionFactory的方法.第二.继承 ...

  7. 推断字符串string是数字、json结构、xml结构

    import org.json.JSONException; import org.json.JSONObject; import org.dom4j.DocumentException; impor ...

  8. MDL--元数据锁的锁请求与锁等待+元数据锁类对象

    1 元数据锁的锁请求与锁等待     元数据锁在MySQL Server层,依照锁的状态被细分为两种.一种是已经施加的锁.一种是等待施加的锁即锁请求,这样被区分的原因,如MySQL对"cla ...

  9. android 弹幕评论效果

    纯粹依照自己的想法仿照b站的弹幕写的一个demo,不知道正确的姿势怎么样的. demo下载地址 首先.一条弹幕就是一个textview public abstract class Danmu exte ...

  10. mysql 批量删除数据

    批量删除2000w数据 使用delete from table太慢 //DELIMITER DROP PROCEDURE if EXISTS deleteManyTable; create PROCE ...