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. PAT 1095 Cars on Campus

    1095 Cars on Campus (30 分) Zhejiang University has 8 campuses and a lot of gates. From each gate we ...

  2. Python(调用函数、定义函数)

    函数的返回值: return 值:只能返回一次,只要执行return函数就终止 返回值:没有类型限制,也没有个数限制 没有return:None 返回一个值 返回多个值:元组 先定义,后使用,定义阶段 ...

  3. zend studio设置utf8

    1. windows -> preference -> general -> workspace 2.项目右键 -> properities -> resource 3. ...

  4. Json日期格式 转化为 YYYY-MM-DD-hh-mm-ss

    function timeStamp2String(time) { var datetime = new Date(); datetime.setTime(time); var year = date ...

  5. ajax与一般处理程序 HTTP协议交互

    1,一般处理程序中 context.Response.ContentType = "text/plain", 则  ajax参数中 也是 text 类型. 2,一般处理程序中 转化 ...

  6. 20145235李涛《网络对抗》Exp9 Web安全基础实践

    基础问答 SQL注入攻击原理,如何防御? SQL注入攻击就是通过把SQL命令插入到Web表单递交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意SQL命令的目的. 对于SQL注入攻击的防范 ...

  7. 举例讲解Linux中tcpdump工具的应用

    先来看一个比较基本的用法: tcpdump -i eth0 其中,eth0为参数值,表示需要抓包的网口,这是个必需参数哦. tcpdump的具体参数及意义: -i:指定tcpdump监听的网络接口 - ...

  8. POJ 1442 优先队列

    题意:有一些ADD和GET操作.n次ADD操作,每次往序列中加入一个数,由ADD操作可知序列长度为1-n时序列的组成.GET操作输入一个序列长度,输出当前长度序列第i大的元素的值.i初始为0,每次GE ...

  9. pexpect的pxssh类实现远程操作

    #!/usr/bin/pythonimport pexpectfrom pexpect import pxssh import getpasstry: s=pxssh.pxssh() hostname ...

  10. Spring注解(环境)

    以数据库为例: 引入 c3p0数据源maven坐标 数据库驱动 @Configuration @PropertySource("classpath:/db.config.properties ...