自己定义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.一个 ...
随机推荐
- 升鲜宝V2.0_杭州生鲜配送行业,升鲜宝供应链手机分拣系统使用说明_升鲜宝生鲜供应链管理系统_15382353715_余东升
1. 系统概述 升鲜宝供应链手机分拣系统(Android版)是升鲜宝供应链管理系统的配套分拣系统,本系统适用于农副产品生鲜配送供应链企业分拣过程,在线上数据管理和线下业务管理两大方面提供解决方案,该系 ...
- 第6章 服务模式 Service Interface(服务接口)
Service Interface(服务接口) 上下文 您正在设计企业应用程序,并且需要能够通过网络使用其部分功能.此功能需要能够被各类系统使用,因此互操作性是设计的重要方面.除互操作性之外,可能还需 ...
- mac安装python3 pandas tushare
1,升级pip python3 -m pip install --upgrade pip 2,安装依赖包 pip install --user numpy scipy jupyter pandas s ...
- css3 边框、背景、文本效果
浅玩CSS3 边框.背景.文本效果 一.边框 box-shadow box-shadow: h-shadow v-shadow blur spread color inset(ontset); //h ...
- Css问题 margin float 文档流 背景图底部充满
今天来整理一下做网页遇到的问题吧 1.插入背景图片并使图片居于div底部充满整个行. <style> background:url(xxx.jpg) no-repeat; backgrou ...
- python课程设计笔记(四)整数、浮点数与字符串 time库
整数类型(范围无限制) 十进制1 -1 二进制0b1 -0b1 八进制0o1 -0o1 十六进制0x1 -0x1 浮点类型(范围有限制但可忽略) 运算存在不确定尾数 :0.1+0.2!=0.3 原因: ...
- Java基础9一面向对象
继承 1.特点 a) 要有一定的层次结构,并且具备可传递性. b) 判断两者之间是否有继承关系通过is-a来判断. c) 子类继承了父类,那么子类就继承了父类中所有的属性和方法,但是父类中的私有属性和 ...
- 【Five-Minute Share】“请先了解所使用的工具 ,磨刀不误砍柴工”
数据是应用系统的血液,没有数据的系统应用价值是非常有限的.经过多年的观察发现,身边很多的程序开发人员在开发应用系统的时候,都是按照标准SQL语法及应用方法去进行数据库设计,并进行应用开发的,没有任何的 ...
- 一个openMP编程处理图像的示例
一个openMP编程处理图像的示例: 从硬盘读入两幅图像,对这两幅图像分别提取特征点,特征点匹配,最后将图像与匹配特征点画出来.理解该例子需要一些图像处理的基本知识,我不在此详细介绍.另外,编译该例需 ...
- SweetAlert详解
官方给出的SweetAlert介绍是:SweetAlert可以替代JavaScript原生的alert和confirm等函数呈现的弹出提示框,它将提示框进行了美化,并且允许自定义,支持设置提示框标题. ...