我们应该建立自己的代码库,建立自己的工厂

苹果公司给我们提供了强大的利器

可是我们不应该以简简单单的实现基本功能就满足了

大牛的成长之路。都是自己慢慢深入研究

我们要有成长为大牛的目标

今天给大家写个自己定义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的更多相关文章

  1. Android自己定义button实现长按功能

    Android自己定义button实现长按功能 通过自己定义BUTTON,写一个LongTouchBtn类,在按下的时候运行onTouchEvent事件,通过这个事件使用回调函数来实现长按功能! XM ...

  2. Qt之模型/视图(自己定义button)

    简述 衍伸前面的章节,我们对QTableView实现了数据显示.自己定义排序.显示复选框.进度条等功能的实现.本节主要针对自己定义button进行解说.这节过后,也希望大家对自己定义有更深入的了解.在 ...

  3. 宏定义 button 方法 --备

    定义 #define BARBUTTON(TITLE, SELECTOR) [[[UIBarButtonItem alloc] initWithTitle:TITLE style:UIBarButto ...

  4. UITableView 自带编辑删除 自己定义button

    一:UITableView 自带编辑删除 1:实现两个方法就可以 #pragma mark   tableView自带的编辑功能 -(void)tableView:(UITableView *)tab ...

  5. iOS总结(自己定义button)

    1.首先新建一个类该类继承UIButton 2.实现几个方法 1).改动字体的一些属性 -(instancetype)initWithFrame:(CGRect)frame{ self = [supe ...

  6. 使用quick自己定义Button

    使用quick时自己封装的类存放于特定的文件夹.便于以后使用 以下是作者经经常使用到的一个按钮 local MyButton = class("MyButton") functio ...

  7. 解决ios7.0 以后自己定义导航栏左边button靠右的问题

    1.自己定义button //左button UIButton *leftBtn = [[UIButton , , , )]; [leftBtn addTarget:self action:@sele ...

  8. 如何让Button使用自定义icon

    1.在Buttton所在的html页面定义button要使用的icon的css样式,如 </style> <style> .dijitArrowIcon { backgroun ...

  9. Tkinter教程之Button篇(1)

    本文转载自:http://blog.csdn.net/jcodeer/article/details/1811298 #Tkinter教程之Button篇(1)#Button功能触发事件'''1.一个 ...

随机推荐

  1. javascript定义类或对象的方式

    本文介绍的几种定义类或对象的方式中,目前使用最广泛的是:混合的构造函数/原型方式.动态原型方式.不要单独使用经典的构造函数或原型方式. 工厂方式 构造器函数 原型方式 混合的构造函数/原型方式 动态原 ...

  2. C# 开放式并发冲突报错处理

    1.调用DataSet.GetChanges()获取数据源中改变的数据 var data = ViewData.GetChanges() as ReleaseData; 2.为新增的数据 data 加 ...

  3. C - Pocket Book(set)

    Problem description One day little Vasya found mom's pocket book. The book had n names of her friend ...

  4. Delete, drop table, truncate之间的区别

    Delete, drop table, truncate有什么区别? delete 删除表中数据,可以删除一条或多条记录,可以回滚,记录操作日记,是DML truncate table,一次性清空表中 ...

  5. C++批量加载动态库函数方法

    1.枚举定义enum  {    // 0 - GigE DLL (implicitly called)    Func_isVersionCompliantDLL,    Func_isDriver ...

  6. [hihocoder][Offer收割]编程练习赛44

    扫雷游戏 #pragma comment(linker, "/STACK:102400000,102400000") #include<stdio.h> #includ ...

  7. wordcloud + jieba 生成词云

    利用jieba库和wordcloud生成中文词云. jieba库:中文分词第三方库 分词原理: 利用中文词库,确定汉字之间的关联概率,关联概率大的生成词组 三种分词模式: 1.精确模式:把文本精确的切 ...

  8. Retrofit进行post提交json数据

    1:先看一看xutils3的提交代码 String account = editText1.getText().toString(); String password = editText2.getT ...

  9. android 自定义空间 组合控件中 TextView 不支持drawableLeft属性

    android 自定义空间 组合控件中 TextView 不支持drawableLeft属性.会报错Caused by: android.view.InflateException: Binary X ...

  10. 二.Windows I/O模型之异步选择(WSAAsyncSelect)模型

    1.基于windows消息为基础的网络事件io模型.因此我们必须要在窗口程序中使用该模型.该模型中的核心是调用WSAAsyncSelect函数实现异步I/O. 2.WSAAsyncSelect函数:注 ...