iOS 自定义UIButton
工作中有一个点击button更新button上文案的需求,用自定义了button可以很简单的实现的这个需求
首先写个自定义的button
CustomButton.h
#import <UIKit/UIKit.h>
typedef NS_ENUM(NSUInteger, CustomButtonStatus){
CustomButtonStatusNormal = ,
CustomButtonStatusReverse =
};
@interface CustomButton : UIButton
@property(nonatomic) CustomButtonStatus buttonStatus;
@end
CustomButton.m
#import "CustomButton.h"
@implementation CustomButton
- (void)setButtonStatus:(CustomButtonStatus)buttonStatus{
NSString *title;
if (CustomButtonStatusNormal == buttonStatus) {
title = @"啊啊啊";
} else if(CustomButtonStatusReverse == buttonStatus){
title = @"哦哦哦";
}
[self setTitle:title forState:UIControlStateNormal];
_buttonStatus = buttonStatus;
}
@end
调用
#import "ViewControllerTest.h"
#import "CustomButton.h" @interface ViewControllerTest () {
CustomButton *button;
} @end @implementation ViewControllerTest - (void)viewDidLoad {
[super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; button = [CustomButton buttonWithType:UIButtonTypeCustom];
[button setButtonStatus:CustomButtonStatusNormal];
[button setFrame:CGRectMake(, , , )];
[button addTarget:self action:@selector(customButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[button setBackgroundColor:[UIColor redColor]];
[self.view addSubview:button]; } -(void) customButtonClick: sender{
button.buttonStatus = !button.buttonStatus;
}

iOS 自定义UIButton的更多相关文章
- iOS 自定义UIButton(图片和文字混合)
// UIApplicationDelegate .h文件 #import <UIKit/UIKit.h> @interface AppDelegate : UIResponder &l ...
- ios自定义UIButton内部空间Rect
- IOS实现UIButton图文混排、自定义按钮按下和正常状态下不同的背景颜色、根据文字长度自定义UIButton长度
在一些项目中,我们需要自定义自己的UIButton,使Button上面同时具有图片和文字描述,实现自定义UIButton的图文混排. 首先我们需要定义一个继承自UIButton的类,同时实现自己的in ...
- 【iOS自定义键盘及键盘切换】详解
[iOS自定义键盘]详解 实现效果展示: 一.实现的协议方法代码 #import <UIKit/UIKit.h> //创建自定义键盘协议 @protocol XFG_KeyBoardDel ...
- iOS自定义的UISwitch按钮
UISwitch开关控件 开关代替了点选框.开关是到目前为止用起来最简单的控件,不过仍然可以作一定程度的定制化. 一.创建 UISwitch* mySwitch = [[ UISwitchalloc] ...
- 如何实现 iOS 自定义状态栏
给大家介绍如何实现 iOS 自定义状态栏 Sample Code: 01 UIWindow * statusWindow = [[UIWindow alloc] initWithFrame:[UIAp ...
- iOS自定义组与组之间的距离以及视图
iOS自定义组与组之间的距离以及视图 //头视图高度 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(N ...
- iOS 自定义转场动画
代码地址如下:http://www.demodashi.com/demo/12955.html 一.总效果 本文记录分享下自定义转场动画的实现方法,具体到动画效果:新浪微博图集浏览转场效果.手势过渡动 ...
- iOS 自定义转场动画浅谈
代码地址如下:http://www.demodashi.com/demo/11612.html 路漫漫其修远兮,吾将上下而求索 前记 想研究自定义转场动画很久了,时间就像海绵,挤一挤还是有的,花了差不 ...
随机推荐
- html5-3 html5标签(热点地图如何实现)(边学边做)
html5-3 html5标签(热点地图如何实现)(边学边做) 一.总结 一句话总结:热点地图用绝对定位实现. 1.自定义列表怎么弄? dl 自定义列表dt 自定义标题dd 自定义列表内容 2. ...
- signed 与 unsigned 有符号和无符号数
unsigned int a = 0; unsigned int b = -1; // b 为 0xffffffff unsigned int c = a - 1; // c 为 0xffffffff
- 非常实用全面的 C++框架,库类等资源
这次的资源涉及到了标准库.Web应用框架.人工智能.数据库.图片处理.机器学习.日志.代码分析等,C++程序员学习必备! Jason frozen : C/C++的Jason解析生成器 Jansson ...
- JavaStuNote 4
装箱(inbox)和拆箱(outbox) 代表了类类型和基本类型之间的转换行为. 手动版本号: Integer b = new Integer(10); Int a = b.intValue; 自己主 ...
- APPCAN学习笔记002---app高速开发AppCan.cn平台特色
技术qq交流群:JavaDream:251572072 1.多窗体机制 常见应用仅仅支持单一窗体 2.原生UI与交互支持 大量原生UI与交互支持(如Action Sheet等) 3.第三方开放 ...
- PHP/HTML混写的四种方式总结
PHP/HTML混写的四种方式总结 一.总结 一句话总结: 注意点: 1.双引号里面解析变量:echo "$Content" 2.HEREDOC和NOWDOC的关系:类似于双引号包 ...
- Oracle数据库零散知识05 -- 表创建,修改
1.表的创建 Create table student02(sno number); 2.表的删除 Drop table student02; 3.表的重命名 Rename student02 to ...
- node服务器如何部署https证书
var http = require('http'); var https = require('https'); var path = require('path'); var fs = requi ...
- react中对象扩展运算符使用问题
看别人代码看到 render() { return <Modal {...this.props}> {this.props.children} </Modal> } 对其中的{ ...
- matlab 神经网络工具箱的实用
0. 其他处理 计时: tic net = train(net, X, y); toc 1. 一个简单的 demo(单层感知器) P = [1, 1, 1, 1, 0, 0, 0, 0; 0, 0, ...