IOS UIView基础

UILabel 字体 

 //设置label文字的大小,使用系统默认字体,大小为12

    label.font = [UIFont systemFontOfSize:18];

    //设置文字颜色

    label.textColor = [UIColor blackColor  ];

//设定阴影的颜色

    label.shadowColor = [UIColor grayColor];

    //数组阴影的偏移位置 x,  y

    label.shadowOffset = CGSizeMake(0, 50);

    //设置text 文字对齐模式,默认为靠左侧位置

    label.textAlignment = NSTextAlignmentCenter;

//如果这个值为0:IOS会对文字自动计算所需要的行数,按照需要的行数来显示

    label.numberOfLines = 0;

 

 

UIButton 按钮

 

 1 //圆角类型btn:UIButtonTypeRoundedRect
 2     //通过类方法创建buttonWithType:类名+方法名
 3 
 4     UIButton * btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
 5 
 6    btn.frame =CGRectMake(100, 100, 100, 40);
 7 
 8     //设置按钮的文字内容
 9 
10     //@parameter
11 
12     //P1:字符串类型,显示到按钮上的文字
13 
14     //P2:设置文字显示的状态类型:UIControlStateNormal 正常状态
15 
16     [btn setTitle:@"按钮01" forState:UIControlStateNormal];
17 
18 //P1:显示的文字
19 
20     //P2:显示文字的状态:UIControlStateHighlighted 按下状态
21 
22     [btn setTitle:@"按钮按下" forState:UIControlStateHighlighted];
23 
24   //设置文字显示文字
25 
26     //P1:颜色
27 
28     //P2:状态
29 
30    [btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
31 
32     //设置按下状态的颜色
33 
34     [btn setTitleColor:[UIColor orangeColor] forState:UIControlStateHighlighted];
35 
36     //设置按钮的风格颜色
37 
38     [btn setTintColor:[UIColor whiteColor]];
39 
40 
41 
42     //titleLabel:UILabel控件
43 
44     btn.titleLabel.font = [UIFont systemFontOfSize:18];

 

UITextField 

//    创建用户文本框
    UserName = [[UITextField alloc]initWithFrame:CGRectMake(150, 80, 150, 40)];
    UserName.font = [UIFont fontWithName:@"OriyaSangamMN-Bold" size:18.0f];
    //设置边框样式(圆角)
    [UserName setBorderStyle:UITextBorderStyleRoundedRect];
    //一键清除文本框内容
    UserName.clearButtonMode = UITextFieldViewModeAlways;
    //设置 确定按钮的类型
    UserName.returnKeyType=UIReturnKeyDone;
   //设置默认值
    UserName.placeholder=@"输入用户名";
    [self.view addSubview:UserName];

//    创建用户密码标签
    userpsw = [[UILabel alloc]initWithFrame:CGRectMake(40, 150, 100, 20)];
    userpsw.font = [UIFont fontWithName:@"OriyaSangamMN-Bold" size:18.0f];
    userpsw.text = @"password";
    [self.view addSubview:userpsw];
//    创建用户密码文本框
    UserPsw =[[UITextField alloc]initWithFrame:CGRectMake(150, 140, 150, 40)];
    UserPsw.font = [UIFont fontWithName:@"OriyaSangamMN-Bold" size:18.0f];
    //设置文本框样式(圆角)
    [UserPsw setBorderStyle:UITextBorderStyleRoundedRect];
    //一键清除文本框内容
    UserPsw.clearButtonMode = UITextFieldViewModeAlways;
    //设置键盘的类型(数字键盘)
    UserPsw.keyboardType = UIKeyboardTypeNumberPad;
    UserPsw.placeholder =@"输入密码";
    //设置文本内容变成*号
    UserPsw.secureTextEntry = YES;
//    UserName.placeholder =@"输入密码";
    [self.view addSubview:UserPsw];

 事件

//触摸屏幕触发方法
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    NSLog(@"触摸控制器开始");
    //点击空白回收键盘(取消第一响应者状态)
    [tf resignFirstResponder];
}
-(void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    NSLog(@"取消触摸");
}

-(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    NSLog(@"移动");
}

-(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    NSLog(@"触摸控制器结束");
}

//摇晃手机触发的方法
-(void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
    NSLog(@"摇晃开始");
}

-(void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
    NSLog(@"摇晃取消");
}
-(void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
    NSLog(@"摇晃结束");
}

 

posted on 2017-11-27 15:55  小林_小林  阅读(79)  评论(0)    收藏  举报

导航