UI基本控件-UILabel-UITextField-UIButton-UIAlertView

一.UILabel的使用


    // 父类是UIView
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 100, 280, 80)];
    
    // label的属性设置
    
    // 显示的文本信息
    label.text = @"王子洁和如花幸福在一起";
    
    // 文本颜色
    label.textColor = [UIColor redColor];
    
    // 文本的阴影颜色
    label.shadowColor = [UIColor grayColor];
    
    // 阴影的偏移量
    label.shadowOffset = CGSizeMake(2, 2);
    
    // 文本的对齐方式
    label.textAlignment = NSTextAlignmentCenter;//右对齐
    
    // 当文本过长时,label显示的断行方式
    label.lineBreakMode = NSLineBreakByTruncatingMiddle;// 省略掉中间,保留前和后
    label.lineBreakMode = NSLineBreakByTruncatingHead;// 省略掉前面的
    
    // 控制label显示的行数
    label.numberOfLines = 0;// 等于0时,能显示多少就显示多少
    
    
    // 系统默认字体大小:17
    label.font = [UIFont fontWithName:[[UIFont familyNames] objectAtIndex:22] size:15];
    label.font = [UIFont systemFontOfSize:15];
    
    label.backgroundColor = [UIColor yellowColor];
    [self.window addSubview:label];
    [label release];

二.UITextField的使用


    // 父类是UIControl
    UITextField *field = [[UITextField alloc] initWithFrame:CGRectMake(20, 200, 280, 50)];
    field.backgroundColor = [UIColor yellowColor];
    [self.window addSubview:field];
    [field release];
    
    // 默认的占位字符,一旦用户输入,自行隐藏。
    field.placeholder = @"请输入用户名";
    
    // 输入控制
    
    // 输入的文本全部转为黑点
    //field.secureTextEntry = YES;
    // 转变键盘类型
    //UIKeyboardTypeNumberPad 数字键盘
    //UIKeyboardTypeEmailAddress 带邮箱的键盘
    field.keyboardType = UIKeyboardTypeNumberPad;
    field.keyboardType = UIKeyboardTypeEmailAddress;
    field.keyboardType = UIKeyboardTypeDefault;
    
    field.keyboardType = UIKeyboardTypeNamePhonePad;
    
    // 外观控制
    // UITextBorderStyleNone,
    // UITextBorderStyleLine,  黑色边框
    // UITextBorderStyleBezel, 遮光边框
    // UITextBorderStyleRoundedRect  圆角矩形
    field.borderStyle = UITextBorderStyleBezel;
    
    // 清除按钮
    // UITextFieldViewModeNever,
    // UITextFieldViewModeWhileEditing,
    // UITextFieldViewModeUnlessEditing,
    // UITextFieldViewModeAlways
    field.clearButtonMode = UITextFieldViewModeAlways;
    
    // 给field设置tag值
    field.tag = 10000;

三.UIButton的使用


    // 父类UIControl
    //UIButton 按钮 处理点按
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];// 便器自带autorelease
    button.frame = CGRectMake(20, 20, 80, 40);
    
    // 设置按钮标题
    // 参数1,标题内容
    // 参数2,按钮的状态
    [button setTitle:@"suibian" forState:UIControlStateNormal];
    
    // 点击的时候设置button的高亮
    button.showsTouchWhenHighlighted = YES;
    
    // 给按钮绑定一个方法,点击的时候让某个特定的对象调用这个方法
    // 参数1,执行方法的对象
    // 参数2,要执行的方法(参数1的对象去执行)
    // 参数3,按钮让绑定的对象调用方法,需要触发的事件UIControlEventTouchUpInside
    [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    
    // 改字体颜色和大小
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:15];
    
    button.backgroundColor = [UIColor cyanColor];
    [self.window addSubview:button];

四.UIAlertView的使用


// 给按钮点击设定的方法
- (void)buttonClicked:(UIButton *)button
{
    NSLog(@"被点击了!");
    self.window.backgroundColor = [UIColor blackColor];
    
    //1,找到弹出键盘的field
    UITextField *textField = (UITextField *)[self.window viewWithTag:10000];
    
    //2,回收键盘
    [textField resignFirstResponder];
    
    
    //UIAlertView的使用--------------------------------------------------------------
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"王义凯" message:@"谁比较2" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"常宽", @"王子洁", nil];
    
    [alertView show];
    [alertView release];
    
}







  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值