UIButtom及其常用的小控件
来源:互联网 发布:winhex数据恢复步骤 编辑:程序博客网 时间:2024/06/17 13:10
创建
UIButton *button = [UIButtonbuttonWithType:UIButtonTypeSystem];
指定button的位置和大小
button.frame =CGRectMake(100,100,150,70);
设置背景颜色
button.backgroundColor = [UIColoryellowColor];
[self.windowaddSubview:button];
注意:Button不用release
给Button设置标题
[buttonsetTitle:@"确认"forState:UIControlStateNormal];
设置字体大小
button.titleLabel.font = [UIFontsystemFontOfSize:50];
设置圆角
button.layer.cornerRadius =10;
设置边框
button.layer.borderWidth =1;
*点击方法最重要的部分
[buttonaddTarget:selfaction:@selector(click:)forControlEvents:UIControlEventTouchUpInside];
Button的小控件(点击按钮变换图片)*******
@interfaceAppDelegate ()
@property(nonatomic,assign)BOOL isClick;(在延展里声明一个BOOL类型)
(1).创建部分
UIButton *button1 = [UIButtonbuttonWithType:UIButtonTypeCustom];
button1.
实现功能,点击之后切换图片
= CGRectMake(200,100, 100,40);[self.windowaddSubview:button1];
(2).设置背景图(刚开始的图片状态)
[button1 setImage:[UIImageimageNamed:@"Btnoff.png"]forState:UIControlStateNormal];
注意:Btnoff.png是图片的名称
[button1 addTarget:self action:@selector(changeImage:) forControlEvents:UIControlEventTouchUpInside];
注意:如果setImage设置图片的话,button的类型要调整成custom,setImage方法不会把图片放大成按钮大小
(4).实现功能,点击之后切换图片
self.isClick =NO;(按钮的起始状态是关闭的 所以NO);
(5).变换图片的方法
- (void)changeImage:(UIButton *)button
{
if (self.isClick) {
[button setImage:[UIImageimageNamed:@"BtnOff.png"]forState:UIControlStateNormal];
} else {
[button setImage:[UIImageimageNamed:@"BtnOn.png"]forState:UIControlStateNormal];
}
self.isClick = !self.isClick;
}
Button的小控件(点击按钮变换文字和图片)*******例如确认加对号,变成取消加空
@property(nonatomic,assign)BOOL isSelected;(在延展里声明一个BOOL类型)
(1)创建部分
UIButton *button = [UIButtonbuttonWithType:UIButtonTypeSystem];
button.frame =CGRectMake(100,100, 100,40);
button.backgroundColor = [UIColoryellowColor];
[self.windowaddSubview:button];
(2).设置初始文本(例如:@"确认")
[buttonsetTitle:@"确认"forState:UIControlStateNormal];
(3).调用文字变换的方法
[buttonaddTarget:selfaction:@selector(click:)forControlEvents:UIControlEventTouchUpInside];
(4).设置初始图片
[buttonsetBackgroundImage:[UIImageimageNamed:@"checked.png"]forState:UIControlStateNormal];
(5)调用图片变化的方法
[buttonaddTarget:selfaction:@selector(changePic:)forControlEvents:UIControlEventTouchUpInside];
(6).实现功能
self.isSelected =YES;(刚开始为确认状态,所以YES)
(7).变换文字的方法
- (void)click:(UIButton *)button
{
if ([button.currentTitleisEqualToString:@"确认"]) {
[buttonsetTitle:@"取消"forState:UIControlStateNormal];
} else {
[buttonsetTitle:@"确认"forState:UIControlStateNormal];
}
NSLog(@"%ld", button.tag);
}
- UIButtom及其常用的小控件
- iOS UIButtom控件的使用方法
- 常用控件及其使用
- C#常用控件及其常用属性的介绍
- C#常用控件及其常用属性的介绍
- html5常用的小控件,收藏了
- ExtJs控件Panel面板的简单介绍及其小示例
- Android常用控件及其属性
- Form表单属性及其常用的INPUT控件
- C#中常用控件及其属性的用法
- Form表单属性及其常用的INPUT控件
- Form表单属性及其常用的INPUT控件
- iOS UIView及其子控件的常用设置
- iOS UIView及其子控件的常用设置
- 常用皮肤控件小列
- 常用皮肤控件小列
- 常用小控件基础使用
- 常用表单控件简介及其使用
- IOS中KVO模式的解析与应用
- http响应头上为什么没有Content-Encoding
- 【读书笔记】互联网广告综述之点击率特征工程
- Spring讲解----------集成框架
- MFC之设置Windows大小
- UIButtom及其常用的小控件
- 2015.7.30早安,各位。
- 机器学习和统计模型的差异
- Cocoa深入学习:NSOperationQueue、NSRunLoop和线程安全
- dojo事件驱动编程之事件绑定
- MFC之很重要的地方之输入焦点的传递
- RRDTool(三)--fetch,info
- ps aux 参数详解
- 1.1-对象、类的初步笔记