自己定义button
我们应该建立自己的代码库,建立自己的工厂
苹果公司给我们提供了强大的利器
可是我们不应该以简简单单的实现基本功能就满足了
大牛的成长之路。都是自己慢慢深入研究
我们要有成长为大牛的目标
今天给大家写个自己定义button 对于刚開始学习的人来说非常重要
我们要理解苹果公司提供的类库
我们写的程序应该尽量贴近原生
这样我们的程序才会更易理解 效率等方便也会有所提高
上代码了:代码不长,可是是一种思想 要好好理解
//
// MyButton.h
// 自己定义Button #import <UIKit/UIKit.h> @interface MyButton : UIControl /**
* 自己定义的返回自己的类型
*
* @param title <#title description#>
* @param frame <#frame description#>
* @param target <#target description#>
* @param selector <#selector description#>
*
* @return <#return value description#>
*/ +(MyButton *)createButtonWithTitle:(NSString *)title andFrame:(CGRect)frame andTarget:(id)target andSelector:(SEL)selector; @end
//
// MyButton.m
// 自己定义Button
// #import "MyButton.h" @implementation MyButton +(MyButton *)createButtonWithTitle:(NSString *)title andFrame:(CGRect)frame andTarget:(id)target andSelector:(SEL)selector
{
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
//UIButton *btn = [[UIButton alloc]init];
btn.frame = frame; btn.layer.cornerRadius =10.0f; btn.layer.masksToBounds = YES; btn.layer.borderWidth = 2.0; btn.backgroundColor = [UIColor colorWithRed:0.18f green:0.64f blue:0.87f alpha:1.00f];
[btn setTitle:title forState:UIControlStateNormal]; [btn addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside]; return btn;
}
@end
//
// ViewController.h
// 自己定义Button #import <UIKit/UIKit.h> @interface ViewController : UIViewController @end
//
// ViewController.m
// 自己定义Button
// #import "ViewController.h"
#import "MyButton.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; MyButton *btn = [MyButton createButtonWithTitle:@"Happy" andFrame:CGRectMake(10, 30, 100, 50) andTarget:self andSelector:@selector(btnClick)]; self.view.backgroundColor = [UIColor orangeColor]; [self.view addSubview:btn];
// Do any additional setup after loading the view, typically from a nib.
} -(void)btnClick
{
NSLog(@"button被点击了!");
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
自己定义button的更多相关文章
- Android自己定义button实现长按功能
		
Android自己定义button实现长按功能 通过自己定义BUTTON,写一个LongTouchBtn类,在按下的时候运行onTouchEvent事件,通过这个事件使用回调函数来实现长按功能! XM ...
 - Qt之模型/视图(自己定义button)
		
简述 衍伸前面的章节,我们对QTableView实现了数据显示.自己定义排序.显示复选框.进度条等功能的实现.本节主要针对自己定义button进行解说.这节过后,也希望大家对自己定义有更深入的了解.在 ...
 - 宏定义 button  方法 --备
		
定义 #define BARBUTTON(TITLE, SELECTOR) [[[UIBarButtonItem alloc] initWithTitle:TITLE style:UIBarButto ...
 - UITableView 自带编辑删除 自己定义button
		
一:UITableView 自带编辑删除 1:实现两个方法就可以 #pragma mark tableView自带的编辑功能 -(void)tableView:(UITableView *)tab ...
 - iOS总结(自己定义button)
		
1.首先新建一个类该类继承UIButton 2.实现几个方法 1).改动字体的一些属性 -(instancetype)initWithFrame:(CGRect)frame{ self = [supe ...
 - 使用quick自己定义Button
		
使用quick时自己封装的类存放于特定的文件夹.便于以后使用 以下是作者经经常使用到的一个按钮 local MyButton = class("MyButton") functio ...
 - 解决ios7.0 以后自己定义导航栏左边button靠右的问题
		
1.自己定义button //左button UIButton *leftBtn = [[UIButton , , , )]; [leftBtn addTarget:self action:@sele ...
 - 如何让Button使用自定义icon
		
1.在Buttton所在的html页面定义button要使用的icon的css样式,如 </style> <style> .dijitArrowIcon { backgroun ...
 - Tkinter教程之Button篇(1)
		
本文转载自:http://blog.csdn.net/jcodeer/article/details/1811298 #Tkinter教程之Button篇(1)#Button功能触发事件'''1.一个 ...
 
随机推荐
- Battle City
			
Battle City Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7208 Accepted: 2427 Descr ...
 - The Unique MST--hdoj
			
The Unique MST Time Limit : 2000/1000ms (Java/Other) Memory Limit : 20000/10000K (Java/Other) Tota ...
 - JavaScript:目录
			
ylbtech-JavaScript:目录 1. https://www.javascript.com/ 2. 1.返回顶部 1. http://www.runoob.com/js/js-functi ...
 - Spring进行表单验证
			
转自:https://www.tianmaying.com/tutorial/spring-form-validation 开发环境 IDE+Java环境(JDK 1.7或以上版本) Maven 3. ...
 - php 写日志函数(原创)
			
function write_log($msg,$isEcho=false,$path=''){ $path?'':$path='logs'.DIRECTORY_SEPARATOR.'log'.dat ...
 - 前端分页功能实现(PC)
			
<!DOCTYPE html><html> <head> <meta charset="utf-8"> <title>加 ...
 - 深度讲解智能硬件手机APP开发流程
			
常州做APP开发公司紫竹云科技分析,智能硬件产品的软件开发,除了APP和后台之外还有一个固件端的开发,由于固件是要运行产品上的,不过此时的硬件也是刚开始进行研发,所以是无法提供硬件来运行固件的.因此在 ...
 - CorelDRAW X8超低价优惠啦,你却还在用CDR X4破解?!
			
最近大火的<都挺好> 已经完美收官 出于好奇,小编也正在追剧呢 同样出生在畸形的原生家庭 长大后 有钱就是苏明玉 没钱就是樊胜美 所以不要抱怨老天给了你怎样的资源 想要什么就要靠自己的双手 ...
 - Vue2:实例生命周期、js生命周期
			
1.vue2生命周期 每个 Vue 实例在被创建之前都要经过一系列的初始化过程.例如,实例需要配置数据观测(data observer).编译模版.挂载实例到 DOM ,然后在数据变化时更新 DOM ...
 - VS Code编写html(2)
			
<html> <head> <title>welcome to myspace</title> <meta charset="utf-8 ...