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

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];
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 1,Search Bar 怎样去掉背景的颜色(storyboard里只能设置background颜色,可是发现cl...
    以德扶人阅读 2,867评论 2 50
  • *7月8日上午 N:Block :跟一个函数块差不多,会对里面所有的内容的引用计数+1,想要解决就用__block...
    炙冰阅读 2,711评论 1 14
  • 学习UI两天后基本掌握了一些UI的基本控件用法。先说明一下,我学的是iOS 不是IOS,不是ios,也不是IoS等...
    燃烧的木头阅读 445评论 0 3
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 14,899评论 4 61
  • 一块青绿色的小石头, 静静地躺在山坳里。 每天注视着冉冉升起的太阳, 等待暖暖的阳光流趟在它的身体。 还有那色彩斑...
    轻天阅读 342评论 0 3

友情链接更多精彩内容