iOS 自定义一对UI表现相反的按钮
假如有一对按钮【重置】【提交】,要让他们的默认UI和点击的UI表现刚好相反
【提交】按钮,默认橙色,点击边框是橙色,字体是橙色,背景变白色
【重置】按钮,默认白色橙色,边框是橙色,点击字体是白色,背景变橙色
@implementation SubmmitButton
- (instancetype)initWithFrame:(CGRect)frame withTitle:(NSString *)title {
self = [super initWithFrame:frame];
if (self) {
UIImage *image = [UIImage createImageWithColor:[UIColor orangeColor]];
// UIImage *selectedImage = [UIImage createImageWithColor:[UIColor whiteColor]];
self = [SubmmitButton new];
[self setTitle:title forState:UIControlStateNormal];
[self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[self setBackgroundImage:image forState:UIControlStateNormal];
[self.titleLabel setFont:[UIFont systemFontOfSize:16]];
[self.layer setMasksToBounds:YES];
[self.layer setCornerRadius:6];
}
return self;
}
- (void)setSelected:(BOOL)selected {
[super setSelected:selected];
}
- (void)setHighlighted:(BOOL)highlighted {
[super setHighlighted:highlighted];
UIImage *image = [UIImage createImageWithColor:[UIColor orangeColor]];
UIImage *selectedImage = [UIImage createImageWithColor:[UIColor whiteColor]];
if (highlighted) {
[self setBackgroundImage:selectedImage forState:UIControlStateHighlighted];
[self setTitleColor:[UIColor orangeColor] forState:UIControlStateHighlighted];
self.layer.borderWidth = 1;
self.layer.borderColor = [UIColor orangeColor].CGColor;
}else {
[self setBackgroundImage:image forState:UIControlStateNormal];
[self setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
}
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
@end
@implementation RestButton
- (instancetype)initWithFrame:(CGRect)frame withTitle:(NSString *)title {
self = [super initWithFrame:frame];
if (self) {
// UIImage *image = [UIImage createImageWithColor:[UIColor orangeColor]];
UIImage *selectedImage = [UIImage createImageWithColor:[UIColor whiteColor]];
self = [RestButton new];
[self setTitle:title forState:UIControlStateNormal];
[self setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
[self setBackgroundImage:selectedImage forState:UIControlStateNormal];
[self.titleLabel setFont:[UIFont systemFontOfSize:16]];
[self.layer setMasksToBounds:YES];
[self.layer setCornerRadius:6];
self.layer.borderWidth = 1;
self.layer.borderColor = [UIColor orangeColor].CGColor;
}
return self;
}
- (void)setSelected:(BOOL)selected {
[super setSelected:selected];
}
- (void)setHighlighted:(BOOL)highlighted {
[super setHighlighted:highlighted];
UIImage *image = [UIImage createImageWithColor:[UIColor orangeColor]];
UIImage *selectedImage = [UIImage createImageWithColor:[UIColor whiteColor]];
if (highlighted) {
[self setBackgroundImage:image forState:UIControlStateHighlighted];
[self setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
}else {
[self setBackgroundImage:selectedImage forState:UIControlStateNormal];
[self setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
self.layer.borderWidth = 1;
self.layer.borderColor = [UIColor orangeColor].CGColor;
}
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
@end
UIImage的一个分类方法
/**
根据颜色生图片
@param color 生成图片的颜色
@return 返回纯色图片
*/
+ (UIImage*)createImageWithColor:(UIColor*)color {
CGRect rect = CGRectMake(0.0f,0.0f,10.0f,10.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context=UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *theImage=UIGraphicsGetImageFromCurrentImageContext();UIGraphicsEndImageContext();
return theImage;
}
iOS 自定义一对UI表现相反的按钮的更多相关文章
- iOS 自定义图片和文字垂直显示按钮<上面是图片,文字显示下面>
#import <UIKit/UIKit.h> @interface VerticalButton : UIButton @end #import "VerticalButton ...
- iOS自定义的UISwitch按钮
UISwitch开关控件 开关代替了点选框.开关是到目前为止用起来最简单的控件,不过仍然可以作一定程度的定制化. 一.创建 UISwitch* mySwitch = [[ UISwitchalloc] ...
- iOS点击获取短信验证码按钮
概述 iOS点击获取短信验证码按钮, 由于 Demo整体测试运行效果 , 整个修改密码界面都已展现, 并附送正则表达式及修改密码逻辑. 详细 代码下载:http://www.demodashi.com ...
- React Native实战系列教程之自定义原生UI组件和VideoView视频播放器开发
React Native实战系列教程之自定义原生UI组件和VideoView视频播放器开发 2016/09/23 | React Native技术文章 | Sky丶清| 4 条评论 | 1 ...
- iOS自定义转场动画实战讲解
iOS自定义转场动画实战讲解 转场动画这事,说简单也简单,可以通过presentViewController:animated:completion:和dismissViewControllerA ...
- amazeui学习笔记--js插件(UI增强2)--按钮交互Button
amazeui学习笔记--js插件(UI增强2)--按钮交互Button 一.总结 1.按钮loading状态: <button type="button" class=&q ...
- iOS系列 基础篇 06 标签和按钮 (Label & Button)
iOS系列 基础篇 06 标签和按钮 (Label & Button) 目录: 标签控件 按钮控件 小结 标签和按钮是两个常用的控件,下面咱们逐一学习. 1. 标签控件 使用Single Vi ...
- 【iOS自定义键盘及键盘切换】详解
[iOS自定义键盘]详解 实现效果展示: 一.实现的协议方法代码 #import <UIKit/UIKit.h> //创建自定义键盘协议 @protocol XFG_KeyBoardDel ...
- 免费素材下载:iOS 8 矢量 UI 素材套件
小伙伴们,苹果终于在今天凌晨推送了 iOS 8 的正式版.虽然该系统并未与 iPhone6 发布会同时亮相,但对于已经提前体验尝鲜过测试版的同学来说并不陌生.iOS 8 几乎每个图标都进行了重新设计, ...
随机推荐
- SparkML之推荐算法ALS
参考: SparkML之推荐算法(一)ALS --有个比较详细的讲解,包含blocks使用. Spark ALS源码总结 //TODO 源码,集群尝试.研究blocks使用原理及作用. 官方解释:nu ...
- linux VMware 提供的网络连接有 5 种详细讲述
VMware 提供的网络连接有 5 种,分别是"桥接模式"."NAT 模式"."仅主机模式"."自定义"和"L ...
- CTP报单参数详解
交易所代码 产品类型 业务类型 价格类型 指令类型 价格类型 OrderPriceType 有效期类型 TimeCondition 成交量类型 VolumeCondition 备注 CZCE 郑商所 ...
- 剑指offer-6:数值整数次方
一.题目描述 给定一个double类型的浮点数base和int类型的整数exponent.求base的exponent次方. 二.解题思想 分类讨论,充分考虑每种可能. exponent :0,1,& ...
- vue 条件渲染 v-if v-show
1.要点 1.1 v-if 条件性地渲染一块内容 <h1 v-if="awesome">Vue is awesome!</h1> 附带 / v- ...
- python 单引号、双引号和三引号混用
单引号: 当单引号中存在单引号时,内部的单引号需要使用转义字符,要不然就会报错: 当单引号中存在双引号时,双引号可以不用加转义字符,默认双引号为普通的字符,反之亦然. 双引号: 当双引号中存在双引号时 ...
- Git入门指南九:远程仓库的使用【转】
转自:http://blog.csdn.net/wirelessqa/article/details/20152651 版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[-] 十三 ...
- jQuery+Ajax实现图片的预览和上传
jQuery+Ajax实现图片的预览和上传 1.配置Spring-web.xml <!-- springmvc上传图片 --> <bean id="multipartRes ...
- linux 下 SpiderMonkey 1.7.0 编译和安装
wget http://ftp.mozilla.org/pub/mozilla.org/js/js-1.7.0.tar.gz tar xf js-1.7.0.tar.gz cd js/src make ...
- SCC统计
Kosoraju SCC总数及记录SCC所需要的最少边情况 #include<cstdio> ; ; ][N], nxt[][N], v[][N], ed, q[N], t, vis[N] ...