iOS开发基础控件 object-c

文本控件UIlabel

使用:

UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(20,100,280,100)];
label.text=@"Hello World2,Hello World2,Hello World2,Hello World2,Hello World2"; 
label.font=[UIFont systemFontOfSize:18];//设置字体和字号
按钮控件UIButton
UIButton *button1=[UIButton buttonWithType:UIButtonTypeSystem];
button1.frame=CGRectMake(40,100,240,30);
button1.backgroundColor=[UIColor blueColor];
[button1 setTitle:@"click me"forState:UIControlStateNormal];//按钮的初始状态为正常状态
[self.view addSubview:button1];

按钮的初始状态可设置为
UIControlStateNormal //正常状态
UIControlStateHighlighted //高亮状态
UIControlStateDisabled //不可用状态
UIControlStateSelected //选中状态 用于一些充当切换开关的按钮

文本输入框控件UItextField
//要遵守UItextFieldDelegate协议
UITextField* textField=[[UITextField alloc]initWithFrame:CGRectMake(20, 100, 280, 30)];
textField.borderStyle=UITextBorderStyleRoundedRect;
textField.delegate=self;
textField.placeholder=@"不超过11位的数字或字母";
textField.clearButtonMode=UITextFieldViewModeWhileEditing;//设置一键清除按钮

//给输入框增加左视图
UIImageView *imageView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"image"]];
textField.leftView=imageView;
textField.leftViewMode=UITextFieldViewModeWhileEditing;//编辑时显示
开关控制UISwitch
UISwitch *swi=[[UISwitch alloc]initWithFrame:CGRectMake(100, 400, 100, 40)];
 swi.onTintColor=[UIColor greenColor];
 swi.tintColor=[UIColor whiteColor];
 swi.thumbTintColor=[UIColor whiteColor];
  [self.view addSubview:swi];
  [swi addTarget:self action:@selector(changeColor:)forControlEvents:UIControlEventValueChanged];  //changeColor方法需要自己在下面实现
选择器控件 UIPickerView

通过代理和数据源的方法对其进行设置和数据源填充,代理模式的应用之一。例如选择时间、出生年月分
UIPickerView选中数据的回调处理
如下:

//显示当前所选择的位置
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
    NSLog(@"%lu%lu",row,component);
}
CALayer对视图进行修饰
//创建圆角控件
UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
btn.frame=CGRectMake(100, 600, 100, 100);
btn.backgroundColor=[UIColor blueColor];
btn.layer.masksToBounds=YES;//只有使用YES时对视图边界进行修饰的效果才会显示
btn.layer.cornerRadius=10;//设置圆角的半径
//创建带边框的
btn.layer.borderColor=[UIColor greenColor].CGColor;
btn.layer.borderWidth=5;
//添加阴影
btn.layer.shadowColor=[UIColor greenColor].CGColor;
btn.layer.shadowOffset=CGSizeMake(10, 10);//设置阴影位置与原件的相对偏移
btn.layer.shadowOpacity=1;//设置阴影透明度。不设置默认全透明,无效果
[self.view addSubview:btn];
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值