iOS之UIButton的各种使用
来源:互联网 发布:淘宝有卖烟的吗 编辑:程序博客网 时间:2024/05/16 15:03
//// ViewController.m// Day2ClassCode1//// Created by Leven on 15/7/21.// Copyright (c) 2015年 Leven. All rights reserved.//#import "ViewController.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. // 我们创建一个Button,给定一个坐标,以及大小 UIButton *btn=[[UIButton alloc]initWithFrame:CGRectMake(20, 100, 100, 50)]; // 给btn 添加一个背景颜色 btn.backgroundColor=[UIColor yellowColor]; // 普通模式是下边,我的按钮标题是"按钮" [btn setTitle:@"按钮" forState:UIControlStateNormal]; // 在普通模式下边,给按钮的字添加颜色 [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];// UIControlStateNormal 这表示Btn 是在通常模式下边// UIControlStateHighlighted 这个表示Btn是在高亮状态下// UIControlStateDisabled 这个是表示Btn 未选择状态// UIControlStateSelected 这个是表示Btn 在选择状态 // 给按钮添加一个事件 touchEvent [btn addTarget:self action:@selector(touchEvent:) forControlEvents:UIControlEventTouchUpInside]; // 给按钮添加一个touchDown方法,在Touch Down(按下)的时候触发, [btn addTarget:self action:@selector(touchDown:) forControlEvents:UIControlEventTouchDown]; // 给按钮添加一个touchDragOutSide方法,在按钮外拖动取消 [btn addTarget:self action:@selector(touchDragOutSide:) forControlEvents:UIControlEventTouchDragOutside]; // 给按钮添加一个事件,在按钮里边拖动的时候 [btn addTarget:self action:@selector(touchDragInSide:) forControlEvents:UIControlEventTouchDragInside]; [btn addTarget:self action:@selector(dragEnter:) forControlEvents:UIControlEventTouchDragEnter];// 1、addTarget 这个是表示对那个控制器添加一个事件,也可以理解为,按钮的事件在那里触发// 2、这个直接理解为我的btn 添加事件的方法名,如果后边带了冒号就表示需要带参数,这个参数就是我的btn 本身,如果不加冒号,就表示不带任何参数的// 3、// UIControlEventTouchDown 当按钮按下的时候,还未抬起 UIControlEventTouchDownRepeat 当按钮触控点不止一个的时候// UIControlEventTouchDragInside 在按钮里边拖动的时候// UIControlEventTouchDragOutside 当在按钮外边拖动的时候// UIControlEventTouchDragEnter 当// UIControlEventTouchDragExit 当按钮在外边想要退出事件的时候// UIControlEventTouchUpInside 当按钮抬起的时候// UIControlEventTouchUpOutside 当在按钮外边抬起的时候// UIControlEventTouchCancel 当在外边拖动直接取消掉,类似OutInside //设置按钮是否可被点击 btn.enabled = YES; //设置按钮点击(高亮)下字体颜色 [btn setTitleColor:[UIColor yellowColor] forState:UIControlStateHighlighted]; // 把刚创建的按钮加到界面上; [self.view addSubview:btn];}- (void)dragEnter:(UIButton *)Btn{ NSLog(@"dragEnter");}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}#pragma mark ---按钮事件- (void)touchDragInSide:(UIButton *)btn{// NSLog(@"在按钮里边拖动");}- (void)touchDragOutSide:(UIButton *)btn{// NSLog(@"我在按钮外面滑动"); }- (void)touchDown:(UIButton *)btn{// NSLog(@"我的按钮按下了"); }// 按钮触发的事件- (void)touchEvent:(UIButton *)btn{ // [btn setTitle:@"我点击了" forState:UIControlStateNormal];// NSLog(@"我点击了我的按钮");}@end
0 0
- iOS之UIButton的各种使用
- iOS 开发之UIButton的使用
- iOS 之UIButton 使用详解
- iOS开发之四:常用控件--UIButton的使用
- iOS开发UI系列之UIButton的基本使用
- iOS开发学习笔记之UIButton的使用
- iOS中UIButton的使用
- IOS--UI--UIButton的使用
- ios中UIButton的使用
- [IOS笔记]UIButton的各种属性自定义
- IOS的基本控件的使用-UIButton
- IOS 开发之设置UIButton的title
- IOS 开发之设置UIButton的title
- IOS 开发之设置UIButton的title
- IOS 开发之设置UIButton的title
- IOS 开发之设置UIButton的title
- iOS开发基础-UIButton的使用
- ios学习总结(2) -- UIButton的使用
- ubuntu下QQ下载和登陆(pidgin)
- 一个完整的C++类
- Java多线程通信-利用传统的线程通信wait(),notify()方法实现“生产者消费者模式”
- Geoserver+Openlayers3加载瓦片地图
- 【C】字符串的输入,求输入字符串中最长的单词
- iOS之UIButton的各种使用
- leetcode Merge Two Sorted Lists
- EXCEL学习笔记——小技巧
- 数据结构 表达式求值
- UIScrolView里自己滚动滑动 ,无限制那种
- Ubuntu14.04 安装Cuda
- 一个卓有成效的汇编优化范例--使用SSE2指令优化进制转化
- [NSNotificationCenter defaultCenter] addObserver 时 object的意义。
- leetcode 091 —— Decode Ways