iOS-基础控件的使用

UILabel的使用

   UILabel *labName = [[UILabel alloc] initWithFrame:CGRectMake(20, 70, 70, 40)]; // frame 控件的大小 
    labName.text = @"用户名:"; // 文本显示
    labName.font = [UIFont systemFontOfSize:14]; // 文本字体的大小
    labName.textAlignment = NSTextAlignmentRight; // 对齐方式
    labName.backgroundColor = [UIColor redColor]; // 文本的背景颜色
    labName.textColor = [UIColor whiteColor]; // 文字的颜色
    [self.view addSubview:labName];

UITextField的使用

UITextField *tfName = [[UITextField alloc] initWithFrame:CGRectMake(110, 70, self.view.frame.size.width-150, 40)];
tfName.placeholder = @" 请输入用户名 ";
tfName.layer.borderWidth = 1; // 边框宽度
tfName.layer.borderColor = [UIColor purpleColor].CGColor; // 边框颜色
tfName.layer.cornerRadius = 10; // 圆角度
tfName.clearButtonMode = UITextFieldViewModeAlways; // 清空
tfName.keyboardType = UIKeyboardTypePhonePad; // 设置键盘类型
tfName.returnKeyType = UIReturnKeyDone; // 设置键盘上返回键的类型 
[self.view addSubview:tfName];
delegate的使用,这个是关于键盘上右下角按钮键功能的操作。下面是点击done按钮键盘消失的操作。
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
}

UIButton的使用

 UIButton *btnTest = [UIButton new];
    [btnTest setTitle:@"登录按钮" forState:UIControlStateNormal];
    btnTest.frame = CGRectMake(30, 220, self.view.frame.size.width-60, 50);
    btnTest.backgroundColor = [UIColor lightGrayColor];
    //    [btnTest setImage:[UIImage imageNamed:@"btnSuccess"] forState:UIControlStateNormal];
    btnTest.layer.borderWidth = 2; // 边框宽度
    btnTest.layer.borderColor = [UIColor blackColor].CGColor; // 边框颜色
    btnTest.layer.cornerRadius = 20; // 圆角度
    [btnTest addTarget:self action:@selector(btnclickChange) forControlEvents:UIControlEventTouchUpInside];
    //    [btnTest setBackgroundImage:[UIImage imageNamed:@"btnSuccess"] forState:UIControlStateNormal];
    [self.view addSubview:btnTest];
按钮定义的点击事件
-(void)btnclickChange{
    MainVC *mainvc = [MainVC new];
    [self.navigationController pushViewController:mainvc animated:YES];
//    [self.navigationController presentViewController:mainvc animated:YES completion:nil];
}

UIImageView的使用

UIImageView *imgBg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
imgBg.image = [UIImage imageNamed:@"imgBg"];
// NSArray *array = @[[UIImage imageNamed:@"imgBg"],
//                   [UIImage imageNamed:@"imgBg2"]];
//    imgBg.animationImages = array;
//    imgBg.animationDuration = 3; // 动画时长
//    imgBg.animationRepeatCount = 0; // 循环次数
//    [imgBg startAnimating];
[self.view addSubview:imgBg];
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

努力成为包租婆

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值