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 几乎每个图标都进行了重新设计, ...
随机推荐
- 09: mysql基础面试题
1.uuid和id区别 1)uuid类型是varchar(36),而自增长Id则一般是bigInt类型. 2)相对于bigInt类型的自增长Id,varchar(36)类型的uuid消耗的物理空间更为 ...
- CS起源:实现狙击子弹加速
在前面的课程 FPS 游戏实现方框透视 中我们实现了对CS中游戏人物的透视效果,今天我们就来研究下狙击枪如何变成机关枪!原理很简单,直接去掉枪的上膛动画,配合无线子弹就完事了,这里只提供一种分析思路. ...
- form表单提交被拦截
最近做的一个项目,利用form表单(可以避免跨域问题)提交,在chrome可以正常进行跳转,但是在手机端,以及一些pc端浏览器却无法正常跳转.通过检查后台日志,没有正常跳转的都是因为后天直接没有收到该 ...
- redis远程连接配置
解决redis远程连接不上的问题 redis现在的版本开启redis-server后,redis-cli只能访问到127.0.0.1,因为在配置文件中固定了ip,因此需要修改redis.conf(有的 ...
- _proto_和prototype的区别
1. _proto_和prototype prototype属性是一个静态属性, _proto_属性是一个实例属性. prototype表示类的原型对象,_proto_表示原型对象中定义的内部属性[p ...
- markdown的日常使用
# POI前端接口 ``` 描述: 项目poi接口 作者: X-Wolf 时间: -- ``` ------ [TOC] ------ ##声明 ### 请求地址 ``` DOMAIN/strateg ...
- vue学习【二】vue结合axios动态引用echarts
大家好,我是一叶,本篇是vue学习的第二篇,本篇将要讲述vue结合axios动态引用echarts. 在vue中,异步刷新使用的是axios,类似于大家常用的ajax,其实axios已经是vue的第二 ...
- .关于oracle中varchar2的最大长度
关于 varchar2 的最大长度varchar2有两个最大长度:一个是在字段类型4000:一个是在PL/SQL中变量类型32767.这是一个比较容易出错的地方.因为在函数中可以声明长度超过4000的 ...
- joomla core注入漏洞
注入语句如下: payload1 = '/index.php?option=com_fields&view=fields&layout=modal&list[fullorder ...
- lnmp 环境搭建后,pathinfo 模式支持的配制。
ThinkPHP的四种URL模式:0(普通模式);1(PATHINFO模式);2(REWRITE模式);3(兼容模式) nginx需要PATHINFO模式,但需要更改nginx配置文件让其支持PATH ...