ISOUI控件--创建画板,UIView,UILable,UITextField,UIButton基本属性

1 创建画板

Xcode6相对于Xcode5有一些区别,第一个是在创建工程的时候取消了空工程选项,第二就是在创建的单实例工程中,在初始化方法中不再自动生成画板创建代码,需要手动填写。创建画板代码如下:

//创建UIwindow,就是画板
self.window = [[UIWindow alloc]
//获取屏幕大小
initWithFrame:[[UIScreen mainScreen] bounds]];
//给背景上颜色
self.window.backgroundColor = [UIColor whiteColor];
//设置画板可见
[self.window makeKeyAndVisible];
在MRC下,需要对self.window进行autorelease。

2 UIView

所有视图控件的父类。相当于Android下的View。他的所有属性在其各种子类中都包含。

初始化:

UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 200, 50)];
view1.backgroundColor = [UIColor orangeColor];
[self.window addSubview:view1];
[view1 release];

//获得相对于父控件的坐标数
NSLog(@"bounds: %f,%f",view1.bounds.origin.x,view1.bounds.origin.y);
//获得相对于控件的长与宽
NSLog(@"origin: %f,%f" ,view1.frame.origin.x,view1.frame.origin.y);

//获取现在的frame的值
CGRect tfram = view1.frame;
//修改后设置回去
tfram.origin.y = 20;
view1.frame = tfram;

//查看整个视图的中心点
NSLog(@"%.2f:%.2f",view1.center.x,view1.center.y);

3 UILable

UILable,人如其名,就是一个文字标签控件。显示一个文字,相当于Android里面的TextView。

基本属性:

//设置背景颜色
lable.backgroundColor = [UIColor blackColor];
//设置文字内容
lable.text = @"呆逗报到";
//设置文字颜色
lable.textColor = [UIColor greenColor];
//设置文本对齐方式
lable.textAlignment = NSTextAlignmentCenter;
//设置文本字体
lable.font = [UIFont fontWithName:@"Zapfino" size:20]; 
//设置显示行数
lable.numberOfLines = 3;


//获取系统支持的字体
NSArray *arr = [UIFont familyNames];


4 UITextField

文本输入框,相当于Android的EditView。

基本属性

UITextField *tf1 = [[UITextField alloc]initWithFrame:CGRectMake(50, 100, 200, 50)];
tf1.backgroundColor = [UIColor yellowColor];
//设置圆角可用
tf1.layer.masksToBounds = YES;
//设置圆角的值
tf1.layer.cornerRadius = 15;
//占位提示
tf1.placeholder = @"风吹雪";
[self.window addSubview:tf1];
//输入控制
//默认允许输入
tf1.enabled = YES;
//是否在要输入的时候清空输入框,默认为NO
tf1.clearsOnBeginEditing = YES;
//是否以密码样式显示输入的内容,在下次输入的时候,会自动把前面的清掉
tf1.secureTextEntry = YES;
//弹出的键盘类型,
//    tf1.keyboardType = UIKeyboardTypeNumberPad;
//回车键类型
tf1.returnKeyType = UIReturnKeyGo;
自定义显示

UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 1, 100)];
view.backgroundColor = [UIColor grayColor];
//自定义View替换键盘,例如信用卡客户端的密保随机键盘
//    tf1.inputView = view;
//在键盘上方显示的东西,可以作为输入辅助使用
tf1.inputAccessoryView = view;
[view release];

5 UIButton

要注意的是UIButton在MRC下不需要进行release或者Autorelease,UIButton的初始化也比较特别。

UIButton *bu = [UIButton buttonWithType:UIButtonTypeRoundedRect];
//button不需要release
bu.frame = CGRectMake(100, 100, 100, 100);

基本属性

//设置UIButton的监听事件
//如果方法没有实现,点击button会崩
[bu addTarget:self action:@selector(bu_tton:) forControlEvents:UIControlEventTouchUpInside];
[bu setTitle:@"" forState:UIControlStateNormal];
[bu setImage:[UIImage imageNamed:@"wangzi"] forState:UIControlStateNormal];
//获取指定状态下按钮的文字
NSString *str = [bu titleForState:UIControlStateNormal];
[self.window addSubview:bu];
[bu setBackgroundImage:[UIImage imageNamed:@"wangzi"] forState:UIControlStateNormal];
UIButton也可以设置圆角,方法和UIView的一样,先设置圆角可用,再设置圆角值即可。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值