#pragma 视图类 -- UIView
//创建UIView
//创建对象 设置属性
UIView *oneView = [[UIView alloc] init];
//设置背景颜色
oneView.backgroundColor = [UIColor cyanColor];
//设置大小
oneView.frame = CGRectMake(100, 100, 100, 100);
//设置中心点
oneView.center = CGPointMake(100, 100);
//隐藏
oneView.hidden = NO;
//透明度
oneView.alpha = 0.2;
//tag值标记
//通过标记间接访问对应视图
oneView.tag = 1000;
//根据标记获取对象
UIView *tagView = [self.window viewWithTag:1000];
//重置颜色 取随机颜色
//arc4random() % 256 取0~255随机数
//RGB颜色数值为 0 ~ 255
//通过得到的 (随机数 / 255.0)
tagView.backgroundColor = [UIColor colorWithRed:arc4random() % 256 / 255.0 green:arc4random() % 256 / 255.0 blue:arc4random() % 256 / 255.0 alpha: 1];
//添加到父视图上
[self.window addSubview:oneView];
//内存管理
[oneView release];
//获取本视图的子视图
NSLog(@"subViews: %@", self.window.subviews);
//获取本视图的父视图
NSLog(@"superView: %@", oneView.superview);
//打印屏幕尺寸
NSLog(@"%@", NSStringFromCGRect(self.window.frame));
#pragma UIView 切圆角
//锐角度 -> 添加圆角
//正方形边长 / 2 -> 圆形
oneView.layer.cornerRadius = oneView.frame.size.width / 2;
//边框宽度
oneView.layer.borderWidth = 10;
//边框颜色
oneView.layer.borderColor = [UIColor redColor].CGColor;
#pragma mark - UILabel标签
//创建对象 设置frame
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
label.backgroundColor = [UIColor yellowColor];
[self.window addSubview:label];
[label release];
//设置文本
label.text = @"随便一个字符串";
//文本颜色
label.textColor = [UIColor redColor];
//文本对齐
label.textAlignment = NSTextAlignmentCenter;
//断行模式
//1.换行原则
//2.省略原则
label.lineBreakMode = NSLineBreakByTruncatingMiddle;
//行数
//默认为1行 0 表示不限制行数
label.numberOfLines = 0;
//字体
label.font = [UIFont systemFontOfSize:18];
//阴影颜色
label.shadowColor = [UIColor blackColor];
//阴影偏移量
label.shadowOffset = CGSizeMake(1, 1);
#pragma mark - UITextField输入框
//创建textfield
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
//设置背景颜色
textField.backgroundColor = [UIColor yellowColor];
//添加到父视图
[self.window addSubview:textField];
//内存管理
[textField release];
//属性
//文本
textField.text = @"panpan";
//占位字符串
textField.placeholder = @"请输入用户名";
//输入控制
//是否可用
textField.enabled = YES;
//安全文本
textField.secureTextEntry = YES;
//开始编辑时清空所有
textField.clearsOnBeginEditing = YES;
//键盘类型
textField.keyboardType = UIKeyboardTypeURL;
//返回按钮类型
textField.returnKeyType = UIReturnKeyJoin;
//输入视图(自定义键盘)
UIView *input = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
input.backgroundColor = [UIColor redColor];
textField.inputView = input;
//输入辅助视图
textField.inputAccessoryView = input;
[input release];
//外观控制
//边框样式
textField.borderStyle = UITextBorderStyleRoundedRect;
//清除按钮模式
textField.clearButtonMode = UITextFieldViewModeAlways;
#pragma mark - UIButton
//创建对象 button有自己的初始化(不需要release)
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
//设置属性
button.frame = CGRectMake(100, 100, 100, 100);
//设置背景颜色
button.backgroundColor = [UIColor yellowColor];
//添加点击事件
[button addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];
[self.window addSubview:button];
//button属性设置
//设置标题
[button setTitle:@"点我啊" forState:UIControlStateNormal];
//文本颜色
[button setTitleColor:[UIColor yellowColor] forState:UIControlStateNormal];
//设置高亮
[button setTitle:@"高亮" forState:UIControlStateHighlighted];
//设置选中
[button setTitle:@"选中" forState:UIControlStateSelected];
//选中属性
button.selected = YES;
//前景图片
//解决图片不显示的两种方案
//1.system -> custom
//2.改变UIImage读取模式
[button setImage:[[UIImage imageNamed:@"qiaoba"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
//背景图片
[button setBackgroundImage:[UIImage imageNamed:@"qiaoba"] forState:UIControlStateNormal];
#pragma mark - UIImageView(相框)
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
imgView.backgroundColor = [UIColor redColor];
[self.window addSubview:imgView];
[imgView release];
//设置居中
imgView.center = CGPointMake(self.window.center.x, 100);
//设置圆角
imgView.layer.cornerRadius = imgView.frame.size.width / 2;
imgView.clipsToBounds = YES;
//设置图片
//相对路径(效率低 图片过多时 加载缓慢)
imgView.image = [UIImage imageNamed:@"qiaoba"];
//绝对路径
imgView.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"qiaoba" ofType:@"png"]];
#pragma mark - 定时器
//定时器 NSTimer
//每隔固定时间间隔 让某个对象执行某个方法
//参数1.时间间隔
//参数2.某个对象
//参数3.某个方法
//参数5.是否重复
[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(repeat) userInfo:nil repeats:YES];
//定时器
- (void)repeat
{
NSLog(@"定时器");
}
//button点击
- (void)buttonClick
{
NSLog(@"哈哈");
}