UILabel,UITextField 以及UIButton应用
</pre><pre name="code" class="cpp">一.UILabel 它是ioS开发使用的控件来显示文本,它是UIView子类,所以细节UIView部功能,仅仅只是比UIView多了文字显示的功能,
使用过程也是分四步:
1.创建对象
2.配置属性
3.加入到父视图
4.释放全部权
重点:不同的控件之间仅仅是配置的属性的不同,也就是差异所在,所以学习一个新的控件,仅仅有配置该控件独有的属性就可以
1.创建对象
UILabel *view = [[UILabel alloc] initWithFrame:CGRectMake(60 , 234, 200, 100)];
2.设置label上显示的文字
view.text = @"beauy:beauybeauybeauy";
3.设置label上文字的大小
//1.设置字体样式
//2.设置字号
//systemFontOfSize 默认使用系统默认字体,能够更改大小
view.font = [UIFont systemFontOfSize:25];
view.font = [UIFont fontWithName:@"Thonburi-Bold" size:25];
//[UIFont familyNames] 获取字体家族中名称
// NSLog(@"%@",[UIFont familyNames]);
// NSLog(@"%@",[UIFont fontNamesForFamilyName:@"Thonburi"]);
4.字体颜色
view.textColor = [UIColor yellowColor];
5.设置文本的对齐样式
view.textAlignment = NSTextAlignmentCenter;
6.设置文本换行
//假设不限制行数,将值设置为0
view.numberOfLines = 0;
7.换行的标准(文本的截取原则)
view.lineBreakMode = NSLineBreakByWordWrapping;
8.设置阴影的偏移量
view.shadowOffset = CGSizeMake(0, 0);
9. 阴影颜色
view.shadowColor = [UIColor redColor];
二.UITextField 是UIControl的子类,UIControl 又是UIView的子类,所以是一个视图,仅仅只是比UIView多了两个功能:文字显示和文本编辑
// UITextField 的使用步骤和UIView一样
1.创建对象:
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(40, 50, 240, 30)];
textField.backgroundColor = [UIColor yellowColor];
2.设置边框样式
textField.borderStyle =UITextBorderStyleRoundedRect;
3.设置默认显示(提示文字)文字,可是不作为文本内容一部分
textField.placeholder = @"手机号/邮箱";
4.设置開始显示文字
textField.text = @"手机号";
5.设置文本颜色
textField.textColor = [UIColor redColor];
6.设置文本对齐方式
textField.textAlignment = NSTextAlignmentCenter;
7.设置文本的字体
//textField.font = [UIFont fontWithName:@"Thonburi" size:35];
8.设置输入框是否可编辑
textField.enabled = YES;
9.设置当開始编辑时是否清除输入框内容
textField.clearsOnBeginEditing = YES;
10.设置password模式,输入框中的内容是否以点的形式显示
textField.secureTextEntry = YES;
11.设置弹出键盘的样式
textField.keyboardType = UIKeyboardTypeASCIICapable;
12.键盘右下角显示的样式
textField.returnKeyType = UIReturnKeyDefault;
13.代理
//代理的使用步骤:1.设置代理 2.服从协议 3.实现协议中的方法
textField.delegate = self;
14.自己定义输入视图(默认键盘)
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(20 , 50, 20, 50)];
textField.inputView = view; [_containView addSubview:textField];
[textField release];
}
//当点击右下角return时会触发
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
//回收键盘,取消第一响应者
[textField resignFirstResponder];
return YES;
} 三.UIButton
UIButton *button =[UIButton buttonWithType:UIButtonTypeSystem];
button.frame = CGRectMake(50, 400, 220, 40);
button.backgroundColor = [UIColor brownColor];
1.设置圆角
button.layer.cornerRadius = 5;
2.给button加入点击事件
//让target运行action方法,在controlEvents事件发生之后
//click: 后面的參数: 谁调用addTarger:action: 方法,參数就是谁,并且參数仅仅能有一个
[button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
3.给button设置文字
[button setTitle:@"确认" forState:UIControlStateNormal];
4.改变文字的颜色
[button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[_containView addSubview:button];
}
- (void)click:(UIButton *)button
{
NSLog(@"%@",button);
NSLog(@"雷杰聪贴上");
}
版权声明:本文博主原创文章,博客,未经同意不得转载。
UILabel,UITextField 以及UIButton应用的更多相关文章
- ##DAY2 UILabel、UITextField、UIButton、UIImageView、UISlider
##DAY2 UILabel.UITextField.UIButton.UIImageView.UISlider #pragma mark ———————UILabel——————————— UILa ...
- iOS学习21之UILabel, UITextField, UIButton, UIImageView
1.UILabel 1> 概述 UILabel (标签): 是显示文本的控件.在App中 UILabel 是出现频率最高的控件 UILabel 是 UIView 子类,作为子类一般是为了扩充父类 ...
- swift系统学习控件篇:UIbutton+UIlabel+UITextField+UISwitch+UISlider
工作之余,学习下swift大法.把自己的学习过程分享一下.当中的布局很乱,就表在意这些细节了.直接上代码: UIButton+UILabel // // ViewController.swift // ...
- UILabel,UITextField,UIButton三大基础控件总结
(一)UILabel空件 属性: 1.背景颜色 label.backgroundColor = [UIColor ***]; 2. 显示文字: label.text = @"******&q ...
- UI 经常用法总结之--- UILabel UITextField (不断更新中)
UILabel : UIView <NSCoding> 1.创建一个UILabel对象 UILabel *label = [[UILabel alloc]initWithFrame:CGR ...
- UIlabel - 富文本属性
1.NSKernAttributeName: @10 调整字句 kerning 字句调整 2.NSFontAttributeName : [UIFont systemFontOfSize:_fontS ...
- iOS自学-UILabel常见属性
#import "ViewController.h" #import <CoreText/CoreText.h> @interface ViewController ( ...
- (转)UILabel常用属性
Java代码 收藏代码 #import "ViewController.h" #import <CoreText/CoreText.h> @interface View ...
- iOS开发——UI基础-UIButton、UIImageView、UILabel的选择
1.UILabel - UILabel的常见属性 @property(nonatomic,copy) NSString *text; 显示的文字 @property(nonatomic,retain) ...
随机推荐
- hdu 5631 Rikka with Graph(图)
n个点最少要n-1条边才能连通,可以删除一条边,最多删除2条边,然后枚举删除的1条边或2条边,用并查集判断是否连通,时间复杂度为O(n^3) 这边犯了个错误, for(int i=0;i<N;i ...
- FMDB使用
FMDBManager.h #import <Foundation/Foundation.h> #import "FMDatabase.h" @interface FM ...
- 编程获取linux的CPU使用的内存使用情况
Linux可用下top.ps命令检查当前的cpu.mem用法.下面简单的例子: 一.采用ps查看资源消耗的过程 ps -aux 当您查看进程信息,第三列是CPU入住. [root@localhost ...
- Tomcat 的三种(bio,nio.apr) 高级 Connector 运行模式
tomcat的运行模式有3种.修改他们的运行模式.3种模式的运行是否成功,可以看他的启动控制台,或者启动日志.或者登录他们的默认页面http://localhost:8080/查看其中的服务器状态. ...
- 【HeadFirst 设计模式总结】2 观察者模式
作者:gnuhpc 出处:http://www.cnblogs.com/gnuhpc/ 1.我们需要理解报社.订阅系统和订报人之间的关系,订报人通过订阅系统订报,一旦报社有新的报纸,订阅系统就会派人送 ...
- ECShop2.7.2详细文件结构及模板结构目录名称
┣plugins目录┣templates目录┃ ┣backup目录┃ ┃ ┣index.htm┃ ┃ ┗ibrary目录┃ ┃ ┗index.htm┃ ┣cac ...
- (转)android多国语言适配
android多国语言文件夹 android多国语言文件夹文件汇总如下:(有些语言的书写顺序可能跟中文是相反的) 中文(中国):values-zh-rCN 中文(台湾):values-zh-rTW 中 ...
- jfreechart中文乱码问题解决方案(转)
参考网址:http://zhidao.baidu.com/link?url=y88rR1_aAHaFofonx9o_IaEu87MpkTQImsqDcy587eG55JkfQV6EzzzloIgXuQ ...
- SQL server 2008数据库的备份与还原、分离(转)
SQL server 2008数据库的备份与还原.分离(转) 一.SQL数据库的备份: 1.依次打开 开始菜单 → 程序 → Microsoft SQL Server 2008 → SQL Ser ...
- iOS9基础知识(OC)笔记
1月16日 Objective C(20世纪80年代初) 一.OC语言概述 1.1985年,Steve Jobs成立了NeXT公司 2.1996年,12月20日,苹果公司宣布收购了NeXT ...