工作中有一个点击button更新button上文案的需求,用自定义了button可以很简单的实现的这个需求

首先写个自定义的button

CustomButton.h

#import <UIKit/UIKit.h>typedef NS_ENUM(NSUInteger, CustomButtonStatus){CustomButtonStatusNormal = 0,CustomButtonStatusReverse = 1
};@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(200, 80, 86, 42)];[button addTarget:self action:@selector(customButtonClick:) forControlEvents:UIControlEventTouchUpInside];[button setBackgroundColor:[UIColor redColor]];[self.view addSubview:button];}-(void) customButtonClick: sender{button.buttonStatus = !button.buttonStatus;
}

转载于:https://www.cnblogs.com/wb145230/p/4520275.html

iOS 自定义UIButton相关推荐

  1. php使用自定义alert,IOS_iOS自定义alertView提示框实例分享,本文实例为大家分享iOS自定义a - phpStudy...

    iOS自定义alertView提示框实例分享 本文实例为大家分享iOS自定义alertView提示框,先上图,弹框的背景色,按钮背景色,提示的消息的字体颜色都可以改变 利用单例实现丰富的自定义接口 / ...

  2. iOS自定义tabBar

    iOS自定义tabBar 前段时间我们UI设计师设计了一个与系统自带样式的app的底部tabbar,它除了中间按钮要凸出来,整个tabbar的边部也是不贴边的.要做到这样的效果,就要对系统的babba ...

  3. 一劳永逸,iOS 自定义 ActionSheet 封装流程

    原文链接:http://www.jianshu.com/p/cfb87a7db7b1 本文为 iOS 自定义视图封装<一劳永逸>系列的第四期,旨在提供封装思路,结果固然重要,但理解过程才最 ...

  4. iOS自定义View 控件自动计算size能力

    iOS自定义View 控件自动计算size能力 背景 在使用 UILabel 和 UIImage 的时候,不用指定宽高约束,控件也不会报约束缺失,还可以根据内容自己确定适合的宽高,特别适合 Xib 和 ...

  5. ios 自定义字体_如何仅用几行代码在iOS应用中创建一致的自定义字体

    ios 自定义字体 by Yuichi Fujiki 藤木雄一 In this article, you'll learn how to create a unified custom look th ...

  6. iOS自定义组与组之间的距离以及视图

    iOS自定义组与组之间的距离以及视图 //头视图高度 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(N ...

  7. iOS 自定义转场动画浅谈

    代码地址如下: http://www.demodashi.com/demo/11612.html 路漫漫其修远兮,吾将上下而求索 前记 想研究自定义转场动画很久了,时间就像海绵,挤一挤还是有的,花了差 ...

  8. ios cell点击对勾_带图像和对勾的iOS自定义TableView

    ios cell点击对勾 In this tutorial, we'll be developing an iOS Application that contains a custom TableVi ...

  9. iOS 自定义无限循环滚动广告动画控件

    iOS  自定义无限循环广告动画控件 自定义循环滚动的广告控件,支持水平和竖直两个动画方向,页码标记是自定义的,可以随意控制大小位置和颜色等 效果图: 下载地址: https://github.com ...

最新文章

  1. mysql 快捷查询数据库各表占用空间,mysql查看索引占用空间,mysql查看数据占用空间
  2. Ubuntu Snap 简述
  3. cvtColor函数
  4. MyBatisPlus3.x中使用条件构造器查询某一天的记录数时的日期格式化注意
  5. java swing事件监听_Java swing(awt):事件监听机制的实现原理+简单示例
  6. ELK 6.2.4搭建
  7. oracle 11g数据库数据操作(亲测)
  8. 撤销 恢复快捷键 Linux,Linux Vim撤销和恢复撤销快捷键用法详解
  9. python list合并_python基础===两个list合并成一个dict的方法
  10. struts2基本介绍
  11. EMC Isilon存储数据恢复成功案例
  12. 翻译软件-好用的翻译软件-免费翻译软件大全
  13. 我说MySQL联合索引遵循最左前缀匹配原则,面试官让我回去等通知
  14. 为你的网站添加 htpps
  15. 安拆网分享:贝雷片贝雷架桁架的结构力学学问
  16. [轻量化语义分割] Rethinking BiSeNet For Real-time Semantic Segmentation(CVPR2021)
  17. 研究开发出 3D 打印 “食品墨水”
  18. 69节入门python_小渣渣学习笔记 python day69 【Django】
  19. 2020国赛C思路分析:中小微企业的信贷决策
  20. html网页设计阶段性测试题

热门文章

  1. 使用p2p发送GB28181流的设计
  2. 怎么看vray渲染进度_3dmax如何渲染光子,为什么会卡光子呢?
  3. 【Flink】kafka Response from server for which there are no in-flight requests NETWORK_EXCEPTION
  4. 【Elasticsearch】Lucene 8 新特性
  5. 【shell】shell-grep -v 排除多个输出结果
  6. 95-40-120-java.util.concurrent-线程-AbstractEventExecutor
  7. 【Clickhouse】Clickhouse PRIMARY KEY, CONSTRAINT, identifier, column declaration, INDEX
  8. 工具包:Safetype Config使用
  9. 95-270-019-源码-指标监测-常用监控指标
  10. namenode开启DEBUG