IOS学习笔记(三)之UIButton
来源:互联网 发布:sql 数据库 培训 编辑:程序博客网 时间:2024/05/23 17:56
龟速前行中,UIButton主要花时间学习了代码方式创建使用。
UIButton创建方式分为两种:intWithFrame、buttonWithType
UIButtonType
- typedef enum {
- UIButtonTypeCustom = 0, // 自定义,无风格
- UIButtonTypeRoundedRect, / 白色圆角矩形,类似偏好设置表格单元或者地址簿卡片
- UIButtonTypeDetailDisclosure,//蓝色的披露按钮,可放在任何文字旁
- UIButtonTypeInfoLight,//微件(widget)使用的小圆圈信息按钮,可以放在任何文字旁
- UIButtonTypeInfoDark,//白色背景下使用的深色圆圈信息按钮
- UIButtonTypeContactAdd,//蓝色加号(+)按钮,可以放在任何文字旁
- } UIButtonType;
UIButton常用属性
//设置对应状态的标题内容default is nil. title is assumed to be single line
- (void)setTitle:(NSString *)title forState:(UIControlState)state;
//设置对应状态的标题颜色
- (void)setTitleColor:(UIColor *)color forState:(UIControlState)state;
//设置对应状态的标题阴影颜色
- (void)setTitleShadowColor:(UIColor *)color forState:(UIControlState)state;
//设置对应状态的按钮的图片
- (void)setImage:(UIImage *)image forState:(UIControlState)state;
//设置对应状态的按钮背景图片
- (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state;
UIButton添加事件:
[btn addTarget:<#(id)#> action:<#(SEL)#> forControlEvents:<#(UIControlEvents)#>]
例如:
UIButton *landBtn=[selfcreateButtonFrame:CGRectMake(10,190, self.view.frame.size.width-20,37) backImageName:niltitle:@"登录"titleColor:[UIColorwhiteColor] font:[UIFontsystemFontOfSize:19]target:selfaction:@selector(landClick)];
landBtn.backgroundColor=[UIColorcolorWithRed:248/255.0fgreen:144/255.0fblue:34/255.0falpha:1];
landBtn.layer.cornerRadius=5.0f;
-(UIButton *)createButtonFrame:(CGRect)frame backImageName:(NSString *)imageName title:(NSString *)title titleColor:(UIColor *)color font:(UIFont *)font target:(id)target action:(SEL)action
{
UIButton *btn=[UIButtonbuttonWithType:UIButtonTypeCustom];
btn.frame=frame; //设置button的在屏幕中的位置,大小
if (imageName)
{
[btn setBackgroundImage:[UIImageimageNamed:imageName] forState:UIControlStateNormal];
}
if (font)
{
btn.titleLabel.font=font;
}
if (title)
{
[btn setTitle:titleforState:UIControlStateNormal];
}
if (color)
{
[btn setTitleColor:colorforState:UIControlStateNormal];
}
if (target&&action)
{
[btn addTarget:targetaction:action forControlEvents:UIControlEventTouchUpInside];
}
return btn;
}
- IOS学习笔记(三)之UIButton
- IOS学习笔记---UIKit之UIButton
- IOS学习笔记UIButton
- IOS学习笔记(三)之UIView的标签(UILabel)与按钮(UIButton)
- IOS学习之UIButton
- IOS学习之UIButton
- IOS-基础笔记之UIButton
- iOS学习笔记(29) 爱不释手的ReactiveCocoa之UIButton
- 暑期留校之iOS学习笔记_ UiButton
- iOS开发学习笔记之UIButton的使用
- ios学习之 UIButton详解
- iOS之UIButton学习【转】
- iOS学习UI之UIButton
- iOS之UI学习-UIButton
- 学习ios控件之UIButton
- IOS开发学习笔记(2)-----UIButton 详解
- IOS开发学习笔记(2)-----UIButton 详解
- iOS学习笔记(3)UIButton
- linux centos 7 下安装express
- Polarr Photo Editor 3(照片编辑处理)
- CSDN离线博客功能之旅
- JAVAEE学习笔记
- SharedPreferences 保存序列化对象
- IOS学习笔记(三)之UIButton
- 决Win7&Win8 64位下Source Insight提示未完整安装的问题
- Hello World!
- RxJava-left
- JavaScript面向对象设计
- Android四大组件基本介绍及其生命周期
- Java CVS文件读写
- 3. Longest Substring Without Repeating Characters
- 2015年蓝桥杯C/C++组B组第三题:三羊献瑞