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 几乎每个图标都进行了重新设计, ...
随机推荐
- gitlab 安装、配置
gitlab 安装.配置 对于企业级的私有 git 仓库,gitlab 是个不错的选择. 今天就来说说 gitlab 的安装.配置. 系统配置建议:最低双核 4G 内存. 当前针对 gitlab 版本 ...
- wordpress后台编辑如何显示定义的`style.css`样式
wordpress后台编辑如何显示定义的style.css样式 由于公司官网采用wordpress进行搭建,但是却又自己设计页面,无奈主题只能自行构建了,直接修改wordpress自带的主题进行修改. ...
- traceback异常处理相关总结
traceback模块 作用 traceback模块被用来跟踪异常返回信息 可在控制台输出结果 可将结果传入文件中记录 常用方法 print_exc([limit[, file]]): 会自动处理当前 ...
- CSS 相对定位 绝对定位
css中的相对定位和绝对定位. 定位标签:position 包含属性:relative(相对) absolute(绝对) 1.position:relative; 如果对一个元素进行相对定位,首先它将 ...
- 如何将本地的一个新项目上传到GitHub上新建的仓库中去
1:我们需要先创建一个本地的版本库(其实也就是一个文件夹).直接右击新建文件夹,或者右击打开Git bash命令行窗口通过命令mkdir来创建(mkdir 文件名). 进入这个文件夹的根目录,选中目录 ...
- vue 列表渲染 v-for
1.数组列表 v-for 块中,我们拥有对父作用域属性的完全访问权限.v-for 还支持一个可选的第二个参数为当前项的索引 1.1 普通渲染 v-for="item ...
- Linux往log中写日志
void writelog(const char* log) { time_t tDate; struct tm* eventTime; time(&tDate);//得到系统当前时间 //将 ...
- python编码环境安装与基本语法
一.pycharm的基本使用 1.python以及pycharm的安装 python的版本选择:3.x版本就行 pycharm的版本选择:社区版就够用 pycharm只是一个编写工具,python才是 ...
- 我所了解的https
http大家多少都有些了解,毕竟要上网的话是肯定会接触到它的.http有个很明显的缺点,就是传输是明文的,很不安全.针对这个情况,就推出了https,也就是http+ssl/tls. 对于明文不安全的 ...
- 前后台入门系统搭建详解(springboot+angularjs)
1 . 搭建boot启动框架,这一步骤什么都不用添加,搭建完后框架如下: 2.因为是前后台项目,所以一般是需要有前台页面的,需要在后端maven依赖中加入web依赖包 spring-boot-star ...