UIViewAndUILableAndUITextField学习
2015-09-05 14:12
381 查看
- (void)dealloc
{
[_window release];//切记:不要使用self.window进行释放 self.属于get方法;
[super dealloc];// 调用父类的dealloc;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
/******************** UIView *********************/
#pragma mark UIWindow
// /**
// UI的窗口类用于显示界面,一般一个程序只有一个window
// iOS中的空间都是矩形, 决定一个空间位置及大小, 用结构体CGRect
// 一般情况下我们不在window界面进行操作
// */
//// 获取当前主机屏
// [UIScreen mainScreen];
//// 获得当前屏幕大小
// [[UIScreen mainScreen]bounds];
//
//#pragma mark UIView
//
////添加一个视图的步骤
//
//// 创建视图
// UIView *view = [[UIView alloc]initWithFrame:CGRectMake(10, 10, 50, 50)];
//// 背景颜色
// view.backgroundColor = [UIColor redColor];
//// 添加视图
// [self.window addSubview:view];
//// 从父视图中移除
// [view removeFromSuperview];
//// 一次性移除全部子类
// for (UIView *tempView in self.window.subviews) {
// [tempView removeFromSuperview];
// }
//// 释放内存
//// [view release];
//// 父视图
// NSLog(@"%@", view.superview);
//// 一个视图, 可以有多个子视图
//// 子视图数组
// NSLog(@"%@", view.subviews);
// //获取视图的位置和大小
// NSLog(@"%@", NSStringFromCGRect(self.window.frame));
//
//// 创建三个视图改变位置
// UIView *redView = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)];
// redView.backgroundColor = [UIColor redColor];
// [self.window addSubview:redView];
//
// UIView *greenView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
// greenView.backgroundColor = [UIColor greenColor];
// [self.window addSubview:greenView];
//
// UIView *blueView = [[UIView alloc] initWithFrame:CGRectMake(80, 80, 100, 100)];
// blueView.backgroundColor = [UIColor blueColor];
//// 把redView放到前面
// [self.window bringSubviewToFront:redView];
//// 把蓝色视图添加到某个位置
// [self.window insertSubview:blueView atIndex:1];
//// 把蓝色视图放到绿色视图上面
// [self.window insertSubview:blueView aboveSubview:greenView];
//// 把蓝色视图放到绿色视图下面
// [self.window insertSubview:blueView belowSubview:greenView];
//
// [redView release];
// [blueView release];
// [greenView release];
// /**
// * UIView的属性值
// */
// hidden 属性:控制视图的显隐 默认:NO
//// view.hidden = YES;
//// alpha 属性:控制视图的透明度(0~1) 默认为1;可以影响子视图
// view.alpha = 0.1;
//
// view.center = CGPointMake(self.window.frame.size.width / 2.0, self.window.frame.size.height / 2.0);
//1.frame修改, 会影响到center和bounds
//2.center修改, 会影响frame, bounds不发生变化
//3.bounds修改, 会影响到frame和center
#pragma mark UIColor
// UIView不设背景颜色 默认为clearColor
// 自定义颜色
UIColor *color = [UIColor colorWithRed:0.45646 green:0.4564 blue:0.75451 alpha:1.0];
// 创建随机颜色视图
// for (NSInteger i = 0; i < 12; i++) {
// UIView *tempView = [[UIView alloc] initWithFrame:CGRectMake(i*25, i*25, 100, 100)];
// UIColor *tempColor = [UIColor colorWithRed:arc4random() *256 / 255. green:arc4random() % 256 / 255. blue:arc4random() % 256 / 255. alpha:0.56];
// tempView.backgroundColor = tempColor;
// [self.window addSubview:tempView];
// [tempView release];
// }
// 全部移除
// for (UIView *tempView in self.window.subviews) {
// [tempView removeFromSuperview];
// }
/******************** UILabel *********************/
//// 标签视图, 主要用于显示文字
////UILabel继承于UIView
//// 创建一个label
// UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(50, 50, 100, 100)];
//// 设置背景颜色
// label.backgroundColor = [UIColor purpleColor];
//// UILabel的属性值
//// 1.设置文本
// label.text = @"蓝胖子";
//// 2.设置文本字样
// label.font = [UIFont fontWithName:@"" size:17];
//// 3.字体对齐方式
// label.textAlignment = NSTextAlignmentRight;
//// 4.字体阴影颜色
// label.shadowColor = [UIColor redColor];
//// 5.字体阴影偏移
// label.shadowOffset = CGSizeMake(10, 10);
//// 6.设置行数
// label.numberOfLines = 1;
//// 7.以什么格式换行
// label.lineBreakMode = NSLineBreakByCharWrapping;
//// 添加到父视图
// [self.window addSubview:label];
//// 释放内存
// [label release];
/******************** UITextField *********************/
//UITextFiled, 文本输入框, 用于输入和显示文字
//(1)创建
UITextField *userTextField = [[UITextField alloc] initWithFrame:CGRectMake(20, 80, 335, 150)];
//(2)设置属性
// userTextField.backgroundColor = [UIColor grayColor];
//设置输入框的文本
userTextField.text = @"请输入用户名";
//设置占位符
userTextField.placeholder = @"请输入用户名";
//设置文本颜色
userTextField.textColor = [UIColor redColor];
//设置文字样式
userTextField.font = [UIFont systemFontOfSize:20];
//设置对齐方式
userTextField.textAlignment = NSTextAlignmentCenter;
//设置输入框边框样式(和背景图无法同时存在)
userTextField.borderStyle = UITextBorderStyleRoundedRect;
//输入框背景图
userTextField.background = [UIImage imageNamed:@"F4A301D8-4F70-4464-B171-FA3282782CE0.png"];
//是否允许用户输入
userTextField.enabled = YES;
//开始编辑文本时, 清空内容(和清空按钮二选一)
userTextField.clearsOnBeginEditing = YES;
//设置清空按钮
userTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
//设置输入安全
userTextField.secureTextEntry = YES;
//设置弹出键盘样式
userTextField.keyboardType = UIKeyboardTypeDefault;
//设置return按钮样式
userTextField.returnKeyType = UIReturnKeyDone;
//设置代理
userTextField.delegate = self;
//自定义键盘
userTextField.keyboardType = UIKeyboardTypeAlphabet;
//设置leftView
UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 60, 30)];
leftView.backgroundColor = [UIColor redColor];
userTextField.leftView = leftView;
[leftView release];
//设置leftView显示模式
userTextField.leftViewMode = UITextFieldViewModeAlways;
//设置userTextField成为第一响应者
//1.设置代理
<UITextFieldDelegate>
//2.成为代理
userTextField.delagate = self;
[userTextField becameFirstResponder];
//3写代理方法
-(BOOL)textFieldShouldReturn:(UITextField:)textField{
//失去第一响应者(回收键盘)
[userTextField resignFirstResponder];
}
-
[self.window addSubview:userTextField];
[self.window makeKeyAndVisible];
return YES;
}
{
[_window release];//切记:不要使用self.window进行释放 self.属于get方法;
[super dealloc];// 调用父类的dealloc;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
/******************** UIView *********************/
#pragma mark UIWindow
// /**
// UI的窗口类用于显示界面,一般一个程序只有一个window
// iOS中的空间都是矩形, 决定一个空间位置及大小, 用结构体CGRect
// 一般情况下我们不在window界面进行操作
// */
//// 获取当前主机屏
// [UIScreen mainScreen];
//// 获得当前屏幕大小
// [[UIScreen mainScreen]bounds];
//
//#pragma mark UIView
//
////添加一个视图的步骤
//
//// 创建视图
// UIView *view = [[UIView alloc]initWithFrame:CGRectMake(10, 10, 50, 50)];
//// 背景颜色
// view.backgroundColor = [UIColor redColor];
//// 添加视图
// [self.window addSubview:view];
//// 从父视图中移除
// [view removeFromSuperview];
//// 一次性移除全部子类
// for (UIView *tempView in self.window.subviews) {
// [tempView removeFromSuperview];
// }
//// 释放内存
//// [view release];
//// 父视图
// NSLog(@"%@", view.superview);
//// 一个视图, 可以有多个子视图
//// 子视图数组
// NSLog(@"%@", view.subviews);
// //获取视图的位置和大小
// NSLog(@"%@", NSStringFromCGRect(self.window.frame));
//
//// 创建三个视图改变位置
// UIView *redView = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)];
// redView.backgroundColor = [UIColor redColor];
// [self.window addSubview:redView];
//
// UIView *greenView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
// greenView.backgroundColor = [UIColor greenColor];
// [self.window addSubview:greenView];
//
// UIView *blueView = [[UIView alloc] initWithFrame:CGRectMake(80, 80, 100, 100)];
// blueView.backgroundColor = [UIColor blueColor];
//// 把redView放到前面
// [self.window bringSubviewToFront:redView];
//// 把蓝色视图添加到某个位置
// [self.window insertSubview:blueView atIndex:1];
//// 把蓝色视图放到绿色视图上面
// [self.window insertSubview:blueView aboveSubview:greenView];
//// 把蓝色视图放到绿色视图下面
// [self.window insertSubview:blueView belowSubview:greenView];
//
// [redView release];
// [blueView release];
// [greenView release];
// /**
// * UIView的属性值
// */
// hidden 属性:控制视图的显隐 默认:NO
//// view.hidden = YES;
//// alpha 属性:控制视图的透明度(0~1) 默认为1;可以影响子视图
// view.alpha = 0.1;
//
// view.center = CGPointMake(self.window.frame.size.width / 2.0, self.window.frame.size.height / 2.0);
//1.frame修改, 会影响到center和bounds
//2.center修改, 会影响frame, bounds不发生变化
//3.bounds修改, 会影响到frame和center
#pragma mark UIColor
// UIView不设背景颜色 默认为clearColor
// 自定义颜色
UIColor *color = [UIColor colorWithRed:0.45646 green:0.4564 blue:0.75451 alpha:1.0];
// 创建随机颜色视图
// for (NSInteger i = 0; i < 12; i++) {
// UIView *tempView = [[UIView alloc] initWithFrame:CGRectMake(i*25, i*25, 100, 100)];
// UIColor *tempColor = [UIColor colorWithRed:arc4random() *256 / 255. green:arc4random() % 256 / 255. blue:arc4random() % 256 / 255. alpha:0.56];
// tempView.backgroundColor = tempColor;
// [self.window addSubview:tempView];
// [tempView release];
// }
// 全部移除
// for (UIView *tempView in self.window.subviews) {
// [tempView removeFromSuperview];
// }
/******************** UILabel *********************/
//// 标签视图, 主要用于显示文字
////UILabel继承于UIView
//// 创建一个label
// UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(50, 50, 100, 100)];
//// 设置背景颜色
// label.backgroundColor = [UIColor purpleColor];
//// UILabel的属性值
//// 1.设置文本
// label.text = @"蓝胖子";
//// 2.设置文本字样
// label.font = [UIFont fontWithName:@"" size:17];
//// 3.字体对齐方式
// label.textAlignment = NSTextAlignmentRight;
//// 4.字体阴影颜色
// label.shadowColor = [UIColor redColor];
//// 5.字体阴影偏移
// label.shadowOffset = CGSizeMake(10, 10);
//// 6.设置行数
// label.numberOfLines = 1;
//// 7.以什么格式换行
// label.lineBreakMode = NSLineBreakByCharWrapping;
//// 添加到父视图
// [self.window addSubview:label];
//// 释放内存
// [label release];
/******************** UITextField *********************/
//UITextFiled, 文本输入框, 用于输入和显示文字
//(1)创建
UITextField *userTextField = [[UITextField alloc] initWithFrame:CGRectMake(20, 80, 335, 150)];
//(2)设置属性
// userTextField.backgroundColor = [UIColor grayColor];
//设置输入框的文本
userTextField.text = @"请输入用户名";
//设置占位符
userTextField.placeholder = @"请输入用户名";
//设置文本颜色
userTextField.textColor = [UIColor redColor];
//设置文字样式
userTextField.font = [UIFont systemFontOfSize:20];
//设置对齐方式
userTextField.textAlignment = NSTextAlignmentCenter;
//设置输入框边框样式(和背景图无法同时存在)
userTextField.borderStyle = UITextBorderStyleRoundedRect;
//输入框背景图
userTextField.background = [UIImage imageNamed:@"F4A301D8-4F70-4464-B171-FA3282782CE0.png"];
//是否允许用户输入
userTextField.enabled = YES;
//开始编辑文本时, 清空内容(和清空按钮二选一)
userTextField.clearsOnBeginEditing = YES;
//设置清空按钮
userTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
//设置输入安全
userTextField.secureTextEntry = YES;
//设置弹出键盘样式
userTextField.keyboardType = UIKeyboardTypeDefault;
//设置return按钮样式
userTextField.returnKeyType = UIReturnKeyDone;
//设置代理
userTextField.delegate = self;
//自定义键盘
userTextField.keyboardType = UIKeyboardTypeAlphabet;
//设置leftView
UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 60, 30)];
leftView.backgroundColor = [UIColor redColor];
userTextField.leftView = leftView;
[leftView release];
//设置leftView显示模式
userTextField.leftViewMode = UITextFieldViewModeAlways;
//设置userTextField成为第一响应者
//1.设置代理
<UITextFieldDelegate>
//2.成为代理
userTextField.delagate = self;
[userTextField becameFirstResponder];
//3写代理方法
-(BOOL)textFieldShouldReturn:(UITextField:)textField{
//失去第一响应者(回收键盘)
[userTextField resignFirstResponder];
}
-
[self.window addSubview:userTextField];
[self.window makeKeyAndVisible];
return YES;
}
相关文章推荐
- 浅谈UIAlertView
- javaSE基础编程——GUI窗体设计之记事本(使用监听器)
- VIM编辑器:使用cscope老是出现一些E259: no matches found for csope query 问题;
- javaSE基础编程——GUI窗体
- EasyUi 合并单元格占列显示
- UE4的delegate
- 'sessionFactory' or 'hibernateTemplate' is required
- mac下使用QuickTime录屏及上传youku注意事项
- easyUI的高级查询
- Unique Paths
- IOS_UI_传值
- IOS_TextField,UIButton
- IOS_UI_Label
- mysql 插入中文时出现ERROR 1366 (HY000): Incorrect string value: '\xC0\xEE\xCB\xC4' for column 'usern ame' at row 1
- Android UI设计:ViewFlipper使图片循环滑动
- iOS 关于UICollectionView的cell重用问题
- GCC内建函数 __builtin_return_address实现
- hdu 1121 Complete the Sequence(插值差分)
- 关于divide and conquer的两道Leetcode
- HDU1711 Number Sequence(KMP模版题)