/*- - - - - - - - - - - - - - - - -UILabel - - - - - - - - - - - - - - - */
// 创建一个lable
UILabel *lable = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 200, 500)];
lable.backgroundColor = [UIColor cyanColor];
// 设置文本内容
lable.text = @"small tiger swzp[;'.]/edxfctgvybhujnikmol,p; dfghjkl;defrgthyjuikl;cvbnm,.fghsdfghjksdfghjklqwertyuiop[,mnbvcxzdfm,x.jhgfdsartyuiol;mnbvcxvbnm,ghfdsyuiopyggggggggggggggggggggDNZSerhijww";
// 设置文本颜色
lable.textColor = [UIColor whiteColor];
// 文本对齐方式
lable.textAlignment = 1;
// 文本字体和大小
lable.font = [UIFont fontWithName:@"Helvetica-Bold" size:20];
// 只设置文本大小
lable.font = [UIFont systemFontOfSize:20];
// 设置显示行数(如果是0, 不限制行数)
lable.numberOfLines = 0;
// 文本断行方式
lable.lineBreakMode = NSLineBreakByTruncatingMiddle;
// 文本阴影颜色
lable.shadowColor = [UIColor blackColor];
// 文本阴影移动
lable.shadowOffset = CGSizeMake(10, 10);
// 自适应文本高度, 与numberOfLines配合使用
[lable sizeToFit];
[self.window addSubview:lable];
[lable release];
/*- - - - - - - - - - - - - - - - -UITextField - - - - - - - - - - - - - - - -*/
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(100, 100, 200, 50)];
textField.backgroundColor = [UIColor cyanColor];
textField.text = @"Small tiger";
// textField.textColor = [UIColor grayColor];
textField.textAlignment = 1;
textField.font = [UIFont fontWithName:@"Helvetica-Bold" size:20];
// 占位字符串
textField.placeholder = @"请输入密码: ";
// 是否允许输入
// textField.enabled = NO;
// 开始编辑是清楚内容
textField.clearsOnBeginEditing = YES;
// textField.backgroundColor = [UIColor grayColor];
// 密码模式
// textField.secureTextEntry = YES;
// 键盘类型
// textField.keyboardType = UIKeyboardTypeNumberPad;
// textField.returnKeyType = UIReturnKeySearch;
[self.window addSubview:textField];
[textField release];
UIView *inputView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
inputView.backgroundColor = [UIColor grayColor];
// 可以自定义键盘键
// textField.inputView = inputView;
// 做键盘扩展
// textField.inputAccessoryView = inputView;
// 边框样式
textField.borderStyle = UITextBorderStyleRoundedRect;
// 输入框的清除
textField.clearButtonMode = UITextFieldViewModeAlways;
// 左视图模式
textField.leftViewMode = UITextFieldViewModeAlways;
// 左视图
textField.leftView = inputView;
// [inputView release];
// 设置代理人
textField.delegate = self;
// 参数1: 目标
// 参数2: 动作(要执行的方法)
// 参数3: 让目标去执行动作的触发时机(触发事件)
// target-action设计模式
[textField addTarget:self action:@selector(changeEditing:) forControlEvents:UIControlEventEditingChanged];
/*- - - - - - - - - - - - - - - - -UIButton - - - - - - - - - - - - - - - -*/
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0, 100, 414, 200);
button.backgroundColor = [UIColor grayColor];
[button setTitle:@"button" forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonAction:)
forControlEvents:UIControlEventTouchUpInside];
[self.window addSubview:button];
[button setTitleColor:[UIColor cyanColor] forState:UIControlStateNormal];
// 长按改名
// [button setTitle:@"small tiger" forState:UIControlStateHighlighted];
[button setTitle:@"small tiger" forState:UIControlStateSelected];
// 设置前景图片
[button setImage:[UIImage imageNamed:@"login_btn_blue_nor.png"] forState:UIControlStateNormal];
// 获取指定状态下的图片
UIImage *image = [button imageForState:UIControlStateNormal];
NSLog(@"%@", image);
// 设置背景图片(常用)
[button setBackgroundImage:[UIImage imageNamed:@"美女
.jpg"] forState:UIControlStateNormal];
// 设置阴影颜色
// [button setTitleShadowColor:[UIColor blackColor] forState:UIControlStateNormal];
/*- - - - - - - - - - - - - - - -UIImageView- - - - - - - - - - - - - -- -*/
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1_160729154121_4.jpg"]];
imageView.frame = CGRectMake(100, 100, 200, 200);
[self.window addSubview:imageView];
[imageView release];
// 图片数组
NSMutableArray *imageArray = [NSMutableArray array];
for (int i = 0; i <= 21; i++) {
NSString *imageName = [NSString stringWithFormat:@"Zombie%d.tiff", i];
UIImage *image = [UIImage imageNamed:imageName];
[imageArray addObject:image];
}
imageView.animationImages = imageArray;
imageView.animationDuration = 0.1 * imageArray.count;
imageView.animationRepeatCount = 0;
[imageView startAnimating];
// imageView默认是不能交互(会影响子视图与用户交互, 需要手动开启交互)
imageView.userInteractionEnabled = YES;
return YES;
}
(void) buttonAction: (UIButton *)button {
button.selected = !button.selected;
NSLog(@"button点击了");
}(void)changeEditing: (UITextField *)textFiled {
NSLog(@"输入内容改变");
NSLog(@"%@", textFiled.text);
}
// 将要开始编辑
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
NSLog(@"begin");
return YES;// 能否开始编辑yes是能, no是不能
}
// 已经完成编译
- (void)textFieldDidBeginEditing:(UITextField *)textField {
NSLog(@"did begin");
}
// 将要完成编辑
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
NSLog(@"end");
return YES;
}
// 已经完成编译
- (void)textFieldDidEndEditing:(UITextField *)textField {
NSLog(@"did end");
}
// 点击return
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
NSLog(@"return");
NSLog(@"%@", textField.text);
// 回收键盘的两种方式
// 放弃第一响应者
// [textField resignFirstResponder];
// 结束编辑状态
[self.window endEditing:YES];
return YES;
}