iOS总结控件二(UIButton)
来源:互联网 发布:上海大众数据服务中心 编辑:程序博客网 时间:2024/05/25 08:15
2、UIButton:按钮控件:是一种常用控件,通过点击触发相应的功能
1).初始化创建(两种方法,第一种如果在不是自动释放缓存的情况下,我们要手动释放)
UIButton *button=[[UIButtonalloc]init];
UIButton *button1=[UIButton buttonWithType:UIButtonTypeCustom];
2).设置button这个按钮的一个位置,大小,frame来说就是一个框架,前两个参数控制button的起始位置,后两个控制大小
button.frame=CGRectMake(50,100,250,50);
3).设置按钮标题的几种状态
[button setTitle:@"按钮"forState:UIControlStateNormal];这里UIControlStateNormal为默认的,还有一个UIControlStateHighlighted为高亮。
UIControlStateSelected 当我们把选中状态设置成yes之后才能被触发
4).设置button的背景颜色
button.backgroundColor = [UIColorblackColor];
5).设置button里面的内容的颜色
[button setTitleColor:(UIColor *) forState:(UIControlState)];其中(UIColor *)是我们可以用来调整button里面内容颜色的属性.(UIControlState)这时我们在第三点写出的可以用来调整的几种状态属性,如:UIControlStateHighlighted高亮等:
6).设置button里面内容的字体
button.titleLabel.font = [UIFontboldSystemFontOfSize:值];这里的button是对象
7).初学label时也有设置label的形状,如设置为圆角,button也有相同的属性,设置边框的颜色粗细
button.layer.cornerRadius = 6.0f;(设置圆角)
button.layer.borderWidth = 2.1;(设置边框)
button.layer.borderColor = [UIColor redColor].CGColor;(设置边框颜色)
8).这个属性为按钮点击下之后,出现的按钮属性
[button setTitle:@"按钮已选" forState:UIControlStateSelected];
9).UIButton几种常用的事件:
<1>UIControlEventTouchUpInside 按钮按下并抬起事件
<2>UIControlEventTouchDown 按钮按下事件
<3>UIControlEventTouchDownRepeat按钮多次点击触发事件
还是作为初学者我第一次使用这玩意是在做点击时保证点击前后能够看到我们点击了事件,刚好TouchUpInside.TouchDown满足了这点,调用两个方法便实现了。
具体使用过程如下:
[button addTarget:selfaction:@selector(buttonTapped:)forControlEvents:UIControlEventTouchUpInside];
这里的self就是button。action里面是一个方法选择器引用了buttonTapped在点击button后便调用了该方法,最后的事件便是我们之前介绍的几种常用的事件。
10).获取button中的内容
NSString *str = button.titleLabel.text;
staticlabelFour.text = str;
11).把创建的按钮加上去
[self.windowaddSubview:button];
- iOS总结控件二(UIButton)
- IOS 控件 UIButton button
- IOS UI控件 - UIButton
- iOS控件之UIButton
- iOS基本常用控件总结(UIView,UILabel,UIButton,UIImageView)
- IOS总结_实现UIButton的图文混排(二)
- IOS总结_实现UIButton的图文混排(二)
- iOS - UIButton 开发总结
- UIButton按钮控件-iOS开发
- iOS开发基础控件--UIButton
- iOS控件之UIButton篇
- ios基本控件之UIButton
- iOS巧用UIButton自定义控件
- iOS UI控件之----UIButton
- 学习ios控件之UIButton
- UIButton 个人学习总结 (二)
- IOS UIButton的属性总结
- iOS控件属性总结(二)
- OC语言第二课 面向对象、类、对象、方法二——ios学习连载七
- ini_set的用法介绍
- Local declaration of 'XXX' hides instance variable
- iOS开发之-猜数游戏的简单改进
- PHP+jquery实时显示网站在线人数的方法
- iOS总结控件二(UIButton)
- 汇编中以bit为单位的比较
- python lockfile no moudle named LockFile issue
- 杭电 2089 不要62
- poj 2752 Seek the Name, Seek the Fame (KMP纯模版)
- 暑假集训第二周——递推 X - 毛毛虫走路
- 开源 java CMS - FreeCMS2.3会员我的评论
- html页面的各种标签的id不能相同
- 程序员保值的4个秘密