UI_基本控件 (17-8-3)

2017-08-15  本文已影响8人  Miss_差不多

UIWindow
UIWindow类是UIView的子类,可以看作是特殊的UIView(UIView之后介绍)。
一般应用程序只有一个UIWindow对象。

// 创建UIWindow对象
// [UIScreen mainScreen].bounds是屏幕大小
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    // 给window设置背景颜色(白色)
    self.window.backgroundColor = [UIColor whiteColor];
    // 使window显示
    [self.window makeKeyAndVisible];
// 创建一个视图控制器
    UIViewController *VC = [[UIViewController alloc] init];
    // 给Window指定根视图控制器
    self.window.rootViewController = VC;

UIView

// 开辟空间创建UIView对象
   // 设置frame确定UIView对象的位置以及大小
   UIView *view = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
   // 设置UIView对象的属性:设置背景颜色
   view.backgroundColor = [UIColor redColor];
   // 将创建好的UIView对象添加到Window上显示
   [self.window addSubview:view];
屏幕快照 2017-08-15 下午6.48.42.png

UIlable

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(40, 60, 100, 40)];
    label.backgroundColor = [UIColor orangeColor];
    //要显示的文本内容
    label.text = @"用户";
    //文本内容的颜色
    label.textColor = [UIColor whiteColor];
    //文本的对齐方式(水平方向)
    label.textAlignment = NSTextAlignmentCenter;
    //文本字体
    //label.font = [UIFont fontWithName:@"Helvetica-Bold" size:26];
    label.font =[UIFont systemFontOfSize:20];
    //行数
    label.numberOfLines = 2;
    //断行模式
    label.lineBreakMode = NSLineBreakByWordWrapping;
    //阴影颜色
    label.shadowColor = [UIColor grayColor];
    //阴影大小
    label.shadowOffset = CGSizeMake(3, 1);
    [self.view addSubview:label];

UITextField

UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(40, 120, 100, 100)];
    //占位文本
    textField.placeholder = @"哈哈";
    //边框风格
    textField.borderStyle = UITextBorderStyleRoundedRect;
    textField.text = @"hehe";
    //是否开始输入的时候清空输入框内容
    textField.clearsOnBeginEditing = YES;
    //是否文字以圆点格式显示
    textField.secureTextEntry = YES;
    //弹出键盘的类型(枚举值)
    //textField.keyboardType = UIKeyboardTypeNumberPad;
    [self.view addSubview:textField];
    
//    UIView *aview = [[UIView alloc] initWithFrame:CGRectMake(100, 0, self.view.frame.size.width, 200)];
//    aview.backgroundColor = [UIColor cyanColor];
//    //自定义键盘
//    textField.inputView = aview;
    
    
    UIView *inputAccessoryView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 50)];
    inputAccessoryView.backgroundColor = [UIColor purpleColor];
    //输入视图上方的辅助视图(默认nil)
    textField.inputAccessoryView = inputAccessoryView;
    //清除按钮模式(枚举值)
    textField.clearButtonMode =UITextFieldViewModeWhileEditing;
    
    UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
    leftView.backgroundColor = [UIColor grayColor];
    textField.leftView = leftView;
    textField.leftViewMode =  UITextFieldViewModeAlways;
    textField.delegate = self;
    
    //1.目标(事件发生是,谁去干什么,动作的执行者)   2.方法动作 (事件发生是,干什么事)  3.控制事件(发生的事)
    [textField addTarget:self action:@selector(textChang:) forControlEvents:UIControlEventEditingChanged];

关于textField的一些方法

//action的方法可以将触发的事件的对象作为参数传递过来(addTarget方法的调用者)
-(void)textChang:(UITextField *)textField{
    NSLog(@"%@",textField.text);
    NSLog(@"值改变了");

}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    NSLog(@"将要开始编辑");
    return YES;
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    NSLog(@"return");
    //回收键盘到二种方法
    //[textField resignFirstResponder];
    [textField endEditing:YES];
    NSLog(@"%@",textField.text);
    return YES;
}
- (void)textFieldDidBeginEditing:(UITextField *)textField{
    NSLog( @"已经编辑");

}
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{
    NSLog(@"将要完成编辑");
    return YES;
    }
-(void)textFieldDidEndEditing:(UITextField *)textField{

    NSLog(@"ok");
    }

UIImageView

UIImageView *zombieImageView = [[UIImageView alloc] initWithImage:[imageArray firstObject]];
    zombieImageView.frame = CGRectMake(300, 60, 120, 100);
    [self.view addSubview:zombieImageView];
    //设置要播放的一组图片
    zombieImageView.animationImages = imageArray;
    //设置播放总时间
    zombieImageView.animationDuration  = 2;
    //设置播放一组图片的循环次数(0为无线循环)
    zombieImageView.animationRepeatCount = 0;
    //开始播放
    [zombieImageView startAnimating];
上一篇下一篇

猜你喜欢

热点阅读