您的位置:首页 > 产品设计 > UI/UE

UI课程02 UILabel,UITextField,UIButton

2015-09-06 19:30 337 查看
1.快捷键



2.第二天知识导图





3.添加快捷代码的方法

Xcode的右下角





将要加为快速代码的代码段选中拖入右下角





在下面填写代码段名:





点击done 然后再程序中编写代码时,写代码段的名字即可快速添加想要写得代码。

4.UILabel 标签

UILabel*label = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 200,30)];

label.backgroundColor = [UIColor cyanColor];

label.tag =101;

[self.windowaddSubview:label];

label.text =@"shuang a shuang shua"; // 设置文字内容

label.textAlignment = NSTextAlignmentCenter; // 对齐方式

label.textColor = [UIColor blueColor]; //字体颜色

label.font =[UIFont fontWithName:@"Zapfino" size:17]; // 设置字体

label.numberOfLines = 0;// 设置行数为0,自动换行

label.tag =100;

5.UITextField 编辑框

//文本框的输入提示信息

textField.placeholder = @"姓名或者手机号";

//初始化文本框内容

textField.text = @"john";

//在开始输入内容时是否清空已有内容

textField.clearsOnBeginEditing = YES;

//文本框的边框样式

textField.borderStyle = UITextBorderStyleRoundedRect;

//添加背景图片

textField.background = [UIImage imageNamed:@"bg.png"];

//是否可以编辑

textField.enabled = YES;

//是否是密码的形式

textField.secureTextEntry = YES;

//键盘的形式

textField.keyboardType = UIKeyboardTypeEmailAddress;

//键盘的外观

textField.keyboardAppearance = UIKeyboardAppearanceDark;

//键盘上的return键的显示文字(done)

textField.returnKeyType = UIReturnKeyDone;

//自定义键盘

UIView*inputV = [[UIView alloc]initWithFrame:CGRectMake(0, 0,self.window.frame.size.width, 150)];

inputV.backgroundColor = [UIColor grayColor];

textField.inputView = inputV;

//定义输入视图上方的辅助视图

UIView *view= [[UIView alloc]initWithFrame:CGRectMake(0, 0,self.window.frame.size.width, 50)];

view.backgroundColor = [UIColor blueColor];

textField.inputAccessoryView = view;

//编辑框后的用来删除编辑框中内容的小叉号的显示

textField.clearButtonMode = UITextFieldViewModeAlways;

//左视图 文本框的左边一小块,用来显示图片或者提示

UIView*leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 20,20)];

leftView.backgroundColor = [UIColor redColor];

textField.leftView = leftView;

textField.leftViewMode =UITextFieldViewModeAlways;//左视图什么时候显示

textField.tag = 200;

6.UIButton 按钮

按钮有自己的初始话方法:

UIButton*btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];

btn.frame =CGRectMake(100, 290, 80, 30);

//正常情况下button上面显示的文字

[btnsetTitle:@"按钮" forState:UIControlStateNormal];

//button被长按时上面显示的文字

[btnsetTitle:@"被长按了" forState:UIControlStateHighlighted];

//按钮颜色

btn.backgroundColor = [UIColor greenColor];

[self.windowaddSubview:btn];

textField.tag = 200;

//给按钮添加事件

[btnaddTarget:self action:@selector(buttonAction:)forControlEvents:UIControlEventTouchUpInside];

点击事件:

-(void)buttonAction:(UIButton *)sender{

UITextView*text = (UITextView *)[self.window viewWithTag:200];

UILabel*label = (UILabel *)[self.window viewWithTag:100];

label.text =text.text;

}

7.打印出所有的字体的样式名

NSLog(@"%@",[UIFont familyNames]);

8.代理与协议

@interface AppDelegate () //(延展)遵守协议或在.h文件中 // 2.遵守协议

@end







//添加输入框

UITextField*textField = [[UITextField alloc]initWithFrame:CGRectMake(20, 40,self.window.frame.size.width - 40, 40)];

textField.borderStyle = UITextBorderStyleRoundedRect;

[self.windowaddSubview:textField];

// 1.将当前类对象设置为输入框的代理

textField.delegate = self;

[textFieldbecomeFirstResponder];//成为第一响应者,一开始键盘就弹出







//3.实现协议方法(系统自动调用)

-(BOOL)textFieldShouldReturn:(UITextField *)textField{

//释放第一响应者

[textFieldresignFirstResponder];//当点击return按键后,键盘收回

returnYES;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: