美文网首页
UI_基本控件 (17-8-3)

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

作者: Miss_差不多 | 来源:发表于2017-08-15 18:49 被阅读8次

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];

相关文章

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

    UIWindowUIWindow类是UIView的子类,可以看作是特殊的UIView(UIView之后介绍)。一般...

  • 初学 UI_基础控件

    一、UILabel · UILabel (即标签) 是APP中出现率最高的控件,用于显示文本. 创建一个label...

  • 基本控件

    隐藏和显示导航 第一种做法 -注意这里一定要用动画的方式隐藏导航栏,这样在使用滑动返回手势的时候效果最好,和上面动...

  • 基本控件

    EditText 文本编辑框 inputType属性number:只能输入数字类型phone:只能输入电话键盘的按...

  • 基本控件

    隐藏和显示导航 第一种做法注意这里一定要用动画的方式隐藏导航栏,这样在使用滑动返回手势的时候效果最好,和上面动图一...

  • 基本控件

    Android 中基本控件的用法:一般用法:加id,长宽,加各自需要的属性目录 1,View2,textview-...

  • [Android] 列表控件(RecycleView,GridV

    [TOC]列表控件也算是很常见的控件了,现在基本都切换到RecycleView了,这边记录下列表控件的基本的使用以...

  • iOS - 基本控件

    1,iOS之UILabel详解计算lable的size 2,iOS-UIButton 全面解析 3,iOS-UII...

  • 基本控件拓展

    1,TextView Span的用法 spanSpannableStringBuilder ssb = new S...

  • UGUI基本控件

    UGUI的创建 注意:新建UI时会自动生成Canvas建的控件都是Canvas的子物体 点击GaneObject列...

网友评论

      本文标题:UI_基本控件 (17-8-3)

      本文链接:https://www.haomeiwen.com/subject/awmvrxtx.html