UIButton按钮======================================================

  第一、UIButton的定义

  UIButton *button=[[UIButton buttonWithType:(UIButtonType);

  能够定义的button类型有以下6种,

  typedef enum {

  UIButtonTypeCustom = 0,  自定义风格

  UIButtonTypeRoundedRect,  圆角矩形

  UIButtonTypeDetailDisclosure,  蓝色小箭头按钮,主要做详细说明用

  UIButtonTypeInfoLight,  亮色感叹号

  UIButtonTypeInfoDark,  暗色感叹号

  UIButtonTypeContactAdd,  十字加号按钮

  } UIButtonType;

  第二、设置frame

  button1.frame = CGRectMake(20, 20, 280, 40);

  [button setFrame:CGRectMake(20,20,50,50)];

  第三、button背景色

  button1.backgroundColor = [UIColor clearColor];

  [button setBackgroundColor:[UIColor blueColor]];

  第四、state状态

  forState: 这个参数的作用是定义按钮的文字或图片在何种状态下才会显现

  enum {

  UIControlStateNormal = 0, 常规状态显现

  UIControlStateHighlighted = 1 << 0, 高亮状态显现

  UIControlStateDisabled = 1 << 1, 禁用的状态才会显现

  UIControlStateSelected = 1 << 2, 选中状态

  UIControlStateApplication = 0x00FF0000, 当应用程序标志时

  UIControlStateReserved = 0xFF000000 为内部框架预留,可以不管

  };

  @property(nonatomic,getter=isEnabled)BOOL enabled;   // default is YES. if NO, ignores touch events and subclasses may draw differently

  @property(nonatomic,getter=isSelected)BOOL selected;  // default is NO may be used by some subclasses or by application

  @property(nonatomic,getter=isHighlighted)BOOL highlighted;

  第五 、设置button填充图片和背景图片

  [buttonsetImage:[UIImageimageNamed:@"checkmarkControllerIcon"]forState:UIControlStateNormal];

  [buttonsetBackgroundImage:[UIImageimageNamed:@"checkmarkControllerIcon"]forState:UIControlStateNormal];

  第六、设置button标题和标题颜色

  [button1 setTitle: @"点击" forState:UIControlStateNormal];

  [buttonsetTitleColor:[UIColorredColor]forState:UIControlStateNormal];

  第七、设置按钮按下会发光

  button.showsTouchWhenHighlighted=NO;

  第八、添加或删除事件处理

  [button1 addTarget:self action: @selector(butClick:) forControlEvents:UIControlEventTouchUpInside];

  [btn removeTarget:nil action:nil forControlEvents:UIControlEventTouchUpInside];

  第九、 设置按钮内部图片间距和标题间距

  UIEdgeInsets insets; // 设置按钮内部图片间距

  insets.top = insets.bottom = insets.right = insets.left = 10;

  bt.contentEdgeInsets = insets;

  bt.titleEdgeInsets = insets; // 标题间距

第十、 其他

// 设置按钮为无效按钮,如果按钮无效了,按钮就不再响应用户了

btn.enabled = YES;

// 给按钮添加手势识别器

[btn addGestureRecognizer:tap];

// 添加一个按钮 ,示例

UIButton *calBtn = [[UIButton alloc]initWithFrame:CGRectMake(50, 200, 200, 40)];  // 按钮大小

calBtn.backgroundColor = [UIColor orangeColor];                  // 背景颜色

[calBtn setTitle:@"点我,我就计算" forState:UIControlStateNormal];            // 设置默认状态下的文字

 [calBtn setTitle:@"点我,我就计算" forState:UIControlStateHighlighted];    // 设置高亮状态下的文字   

[calBtn setBackgroundImage:[UIImage imageNamed:@"login_btn_n_Normal"] forState:UIControlStateNormal]; // 设置默认状态下的背景图片

[calBtn setBackgroundImage:[UIImage imageNamed:@"logoff_btn_n_Highlighted"] forState:UIControlStateHighlighted];   // 设置高亮状态下的背景图片

[self.view addSubview:calBtn];  // 最会一定要添加按钮

【注】图片的名称要提前修改好,最好在后面加上分辨是默认状态还是高亮状态的单词

十一.UIButton的常见设置*****************************************************************************************

- (void)setTitle:(NSString *)title forState:(UIControlState)state;

设置按钮的文字

- (void)setTitleColor:(UIColor *)color forState:(UIControlState)state;

设置按钮的文字颜色

- (void)setImage:(UIImage *)image forState:(UIControlState)state;

设置按钮内部的小图片

- (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state;

设置按钮的背景图片

btn.titleLabel.font = [UIFont systemFontOfSize:13];

设置按钮的文字字体(需要拿到按钮内部的label来设置)

- (NSString *)titleForState:(UIControlState)state;

获得按钮的文字

- (UIColor *)titleColorForState:(UIControlState)state;

获得按钮的文字颜色

- (UIImage *)imageForState:(UIControlState)state;

获得按钮内部的小图片

- (UIImage *)backgroundImageForState:(UIControlState)state;

获得按钮的背景图片

  UILabel标签============================================================================

UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(50, 100, 300, 160)];  // 大小

lbl.backgroundColor = [UIColor lightGrayColor]; // 背景颜色

lbl.textColor = [UIColor blueColor];     // 字体颜色

// lbl.shadowColor = [UIColor redColor];      // 阴影效果,不常用

// lbl.shadowOffset = CGSizeMake(4, -10);

lbl.text = @"宿舍的";    // 添加文字

// 标签内容对齐方式

lbl.textAlignment = NSTextAlignmentCenter;

// 设置标签的行数,如果设置为0,表示可以有任意多行

lbl.numberOfLines = 2;

// 当标签有多行时,设置换行方式 ,默认的是以单词为单位

lbl.lineBreakMode = NSLineBreakByTruncatingMiddle;  // 如果不能完全显示,中间会有三个小点

// 设置标签高亮状态

lbl.highlighted = YES;

// 设置标签高亮时字体颜色

lbl.highlightedTextColor = [UIColor purpleColor];

// 允许用户可以与标签进行交互

lbl.userInteractionEnabled = YES;       //允许用户交互

// 定义一个点击手势识别器对象

UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(lblClicked:)];

// 在标签上添加一个手势识别器

[lbl addGestureRecognizer:tap];

//  lbl.enabled = NO;

lbl.adjustsFontSizeToFitWidth = YES;

// lbl.baselineAdjustment = UIBaselineAdjustmentAlignCenters;

[self.view addSubview:lbl]; // 控件最后都需要添加

【小结】下面的大家可以试着用一下,

UI-UIButton、UILable、UITextField总结的更多相关文章

  1. UILable  /  UITextField  /   UIButton

    // 获取屏幕大小的view UIView *contentView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds]; // ...

  2. iOS 注册或登录页面(UILable,UITextField,UIButton)

    注册或登录页面 例如下面的附图 1,为了在这里展示UITextField文本框关联的键盘设置.在这里,"password"和"判定password"关联键盘被设 ...

  3. swift系统学习控件篇:UIbutton+UIlabel+UITextField+UISwitch+UISlider

    工作之余,学习下swift大法.把自己的学习过程分享一下.当中的布局很乱,就表在意这些细节了.直接上代码: UIButton+UILabel // // ViewController.swift // ...

  4. IOS开发-UI学习-UITextField的具体属性及用法

    直接上代码,里面有各种属性的用法注释,至于每个属性有多个可以设置的值,每个值的效果如何,可以通过查看这个函数参数的枚举量,并逐一测试. //制作登陆界面 #import "ViewContr ...

  5. UI UIBUTTON

    @import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...

  6. UI基础之UITextField相关

    UITextField *textF = [[UITextField alloc] init]; 1.字体相关 textF.text = @"文本框文字"; textF.textC ...

  7. UI第三节—— UITextField详解

    戏言:UITextField对于需要登陆注册的界面的作用还是相当明显,但是对于键盘过的遮挡问题,可是重点哦!这里就涉及到通知(NSNotificationCenter)的内容. //注册事件 [[NS ...

  8. UI基本之UITextField相关方法属性

    //初始化textfield并设置位置及大小 UITextField *text = [[UITextField alloc]initWithFrame:CGRectMake(, , , )]; // ...

  9. IOS开发-UI学习-UITextField的各种属性设置

    UITextField是IOS中非常常用的一个控件,用来接收用户输入信息,完成应用和用户的交互.它的主要属性设置如下: //初始化textfield并设置位置及大小 UITextField *text ...

  10. iOS UI基础 - 20 UITextField

    //找到已经创建好的UITextField UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(, , RFS ...

随机推荐

  1. Delphi 正则表达式语法(9): 临界匹配 - 也叫"预搜索"与"反向预搜索"

    Delphi 正则表达式语法(9): 临界匹配 - 也叫"预搜索"与"反向预搜索" //匹配右边 var   reg: TPerlRegEx; begin   ...

  2. Kotlin学习记录1

    参考我的博客:http://www.isedwardtang.com/2017/09/02/kotlin-primer-1/

  3. Hive2.2.1安装使用

    解压缩hive安装包tar zxvf apache-hive-2.1.1-bin.tar.gz 安装mysqlsudo yum install mysql-server 安装 mysql connec ...

  4. mount、umount、fuser命令使用小结

    mount -t cifs -o username=administrator,password=xxxxx //192.168.11.17/Data/ /mnt/databak/之后想卸载挂载目录, ...

  5. Entity FrameWork Code First 迁移命令详解

    1. Enable-Migrations 启动迁移 执行get-help Enable-Migrations –detailed 查看Enable-Migrations的详细用法. -ContextT ...

  6. 使用GoogleCode作SVN服务器的一些问题及解决办法

    1.首先最主要的一个问题,就是注册GoogleCode和安装SVN工具. 网上教程很多,不一一赘述.http://www.th7.cn/Program/net/201305/136059.shtml ...

  7. MySQL-5.7创建及查看数据库

    1.创建数据库语句 create database语句是在MySQL实例上创建一个指定名称的数据库. create schema语句的语义和create database是一样的. 2.语法解析 CR ...

  8. Tomcat 优化相关知识

    ---------(Tomcat Listener)----------- Tomcat 性能的因素是内存泄露.Server标签中可以配置多个Listener,其中 JreMemoryLeakPrev ...

  9. 做Webservice时报错java.util.List是接口, 而 JAXB 无法处理接口。

    Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExc ...

  10. SpringBoot 通用Error设计

    在项目中需要设计统一的错误消息,通常使用枚举类定义"错误码"与"错误消息": 并且也可以做错误消息自定义. 定义通过错误接口类:CommonError publ ...