菜鸟启航:UIButton基本操作
来源:互联网 发布:js cookie存储时间 编辑:程序博客网 时间:2024/05/28 23:11
1.创建⼀一个button:buttonWithType:UIButton*button=[UIButton
buttonWithType:UIButtonTypeRoundedRect];//加方法创建,不需要release
//创建⼀一个什么样的button 用buttonWithType:
typedef enum{
UIButtonTypeCustom = 0,//自定义(常加载图片)no
button type
UIButtonTypeRoundedRect,//圆角按钮UIButtonTypeDetailDisclosure, //尖叫号按钮UIButtonTypeInfoLight,信息按钮(浅)UIButtonTypeInfoDark,信息按钮(深)UIButtonTypeContactAdd,加号按钮
} UIButtonType;
2.设置坐标和大小
button.frame= CGRectMake(10,30,300,30);
3.//设置按钮上的文字
//在按钮默认状态(正常状态)下显示:圆角按钮
[btn1 setTitle:@"圆角按钮"forState:UIControlStateNormal];
UIControlStateNormal =0,正常状态UIControlStateHighlighted =1<< 0,高亮状态(点击按钮时)UIControlStateDisabled按钮无效未激活时(enabled==NO)
//在按钮点住状态(高亮状态下)下显示:按钮被点击
[btn1 setTitle:@"按钮被点击"forState:UIControlStateHighlighted];3.//更改按钮文字大小
btn.titleLabel.font= [UIFontsystemFontOfSize:25] ;
4.//设置点住时按钮变化颜色(高亮状态)
[btn1 setTintColor:[UIColorredColor]];
//设置背景颜色后可以看出其实还是⼀一个矩形的View
[btn1 setBackgroundColor:[UIColororangeColor]];
5. //设置按钮的点击事件
/*
target:执行哪个对象中的方法
action:执行的方法controlEvents:触发的方式
*/
[btn1 addTarget:selfaction:@selector(btnClick:)forControlEvents:UIControlEventTouchUpInside];
UIControlEventTouchDown
鼠标左键按下触发
鼠标按下,在button内抬起鼠标按下,在button外抬起
UIControlEventTouchUpInside
触发
UIControlEventTouchUpOutside
触发
6.//生成⼀一个定时器,时间每隔0.02秒调用⼀一次updateTimer函数,函数声
明在self-本类内部repeats:Yes代表重复调用
第二个参数可以是任意类型的对象指针
[NSTimer scheduledTimerWithTimeInterval:0.02target:self selector:@selector(updateTimer) userInfo:nilrepeats:YES] ;
NSTimer * timer; if(!timer)
timer = [NSTimerscheduledTimerWithTimeInterval:0.02target:selfselector:@selector(setLabel)userInfo:nilrepeats:YES];
//启动⼀一个定时器,第⼀一个参数表示延迟时间,是浮点数,单位是秒.最后⼀一个参数表示是否重复,添NO表示这个事情只做⼀一次。
//启动新的线程0.02秒钟后,让self调用setLabel
//定时器不需要启动,从创建时就自动启动了,不需要释放,停下来时,
自动释放。
else{
[timer invalidate];//终止定时器,定时器会释放
timer = nil;}
7.tag标签:可以区分是哪⼀一个控件;
- 菜鸟启航:UIButton基本操作
- 菜鸟启航:UILabel基本操作
- 菜鸟启航:UITextField基本操作(一)
- 菜鸟启航:UITextField基本操作(二)
- 菜鸟飞飞开始启航!!
- Android菜鸟的启航
- UiButton操作
- 菜鸟的EL表达式的基本操作
- 基本操作命令(From菜鸟教程)
- 启航
- 启航
- 启航
- 启航
- 启航!
- 启航
- 启航
- 启航
- 启航
- 图片下载和保存
- 代码是大的工程
- ubuntu文件拷贝的问题
- C# 的@是可定义Unicode变量的
- 给敏捷软件开发的26条建议
- 菜鸟启航:UIButton基本操作
- C#的类类似于指针
- 点击链接第一次下载的不是想要的
- nfs服务所需要的的iptables设置
- UITable排序问题
- Delphi的字节对齐和简单string结构
- 创建基于固件库的stm32程序模板并实现流水灯
- PTA数据结构与算法题目集(中文) 函数题(2)
- DateTimeToStr 日期格式问题