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

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

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

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

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

今天给大家写个自己定义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. hdoj--1068--Girls and Boys(最大独立集)

    Girls and Boys Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  2. sublime-text 编译C

    sublime的优点多多. 先下好sublime-text 如果不会下载 在ubuntu 下输入sudo apt-cache search sublime 查找到合适的安装包后apt-get inst ...

  3. [ASP.Net] 转 > ASP.NET MVC 大牛之路

    URL: http://www.cnblogs.com/willick/ [ASP.NET MVC 大牛之路]01 - 开篇 [ASP.NET MVC 大牛之路]02 - C#高级知识点概要(1) - ...

  4. MYSQL工具之binlog2sql闪回操作

    文档结构: 在生产环境中如果遇到误删,改错数据的情况,利用mysql闪回工具binlog2sql,可以实现数据的快速回滚,从binlog中提取SQL,并能生成回滚SQL语句.Binlog以event作 ...

  5. php对文件/目录操作的基础知识(图解)

    具体的如下图所示:

  6. BZOJ 4771 主席树+倍增+set

    思路: 因为有深度的限制,并且我们是在线段树上维护权值,所以我们把点按照dep排序,然后一个一个修改...主席树的下标就是dfs序,子树的查询就是区间查询... 但是发现这样怎么去维护LCA呢...因 ...

  7. BZOJ1010: [HNOI2008]玩具装箱toy(dp+斜率优化)

    Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 12451  Solved: 5407[Submit][Status][Discuss] Descript ...

  8. html5和css3的笔记

    h5+c3 W3C盒子模型和ie盒子模型 文档<!DOCTYPE html>加上的话,所有浏览器都按照W3C的盒子模型,否则ie会按照ie的盒子模型,它的content包括了padding ...

  9. Android studio 隐藏toolbar上的app title

    getSupportActionBar().setDisplayShowTitleEnabled(false);

  10. 生成式模型:LDA

            原文链接:http://blog.sina.com.cn/s/blog_5033f3b40101flbj.html         文章图文并茂,我就不转载了!!! LSI-Laten ...