UI基础第二天(知识点)
来源:互联网 发布:经济学 知乎 编辑:程序博客网 时间:2024/05/21 06:29
一、UIView的动画播放的类方法
[UIView animateWithDuration:(NSTimeInterval) animations:^(void)animations];
animateWithDuration:表示播放时间,单位为秒
animations:表示要播放的动画内容
//以两秒的速度,顺时针旋转button M_PI_2度 [UIView animateWithDuration:2.0 animations:^{ self.headBtn.transform = CGAffineTransformRotate(self.button.transform, M_PI_2); }];
二、控件的frame值的修改
1、间接修改
//取出button的frame CGRect frame = self.button.frame; //调整frame frame.origin.x = 10; frame.origin.y = 10; frame.size.width = 10; frame.size.height = 10; //修改button的frame self.button.frame = frame;
2、强制转换
//把值强制转换成CGRect类型,在进行赋值 self.button.frame = (CGRect){10,10,10,10};
3、CGRectMake函数
//使用CGRectMake函数进行赋值 self.button.frame = CGRectMake(10,10,10,10);
三、懒加载(延迟加载)
懒加载:使用的时候才加载,效率低,节约内存;
实现懒加载:重写getter方法。
优点:代码的可读性更强,不用把加载数据写在viewDidLoad方法中;
//数据@property (nonatomic, strong) NSArray* dataArray;//懒加载,使用时加载-(NSArray*) dataArray{ //判断是否已经实例化,没有实例化才进行加载数据 if (_dataArray==nil) { //NSBundle:应用所在的文件夹 NSBundle* bundle = [NSBundle mainBundle]; //获取plist的全路径 NSString* path = [bundle pathForResource:@"imageData" ofType:@"plist"]; //根据路径取出数组数据 _dataArray = [NSArray arrayWithContentsOfFile:path]; } return _dataArray;}
四、UIImage的2种加载方式
1、根据图片名称创建图片
- 使用imageNamed创建图片,有缓存,程序运行时图片会一直在内存中,把图片放在 Images.xcassets 里,就只能通过imageNamed,放在目录里的图片也可通过imageNamed创建。
UIImage * image = [UIImage imageNamed:imageName];
2、根据图片的全路径创建图片
- 使用imageWithContentsOfFile:或initWithContentsOfFile:创建图片,无缓存,图片所占用的内存会在一些特定操作后被清除;
- 类NSBundle表示应用所在文件,pathForResource:ofType:方法是获取文件的全路径,不能获取Images.xcassets里图片的全路径。
//NSBundle 应用所在文件 NSBundle *bundle = [NSBundle mainBundle]; //获取应用所在文件下的cat.jpg的全路径 NSString * path = [bundle pathForResource:@"cat" ofType:@"jpg"]; //很据图片的全路径创建图片,imageWithContentsOfFile不带缓存 UIImage * image = [UIImage imageWithContentsOfFile:path];
五、Xcode调试方法
1、条件断点:在代码的行号右键单击,设置该行的断点条件
2、添加异常提示:切换到Show the Breakpoint navigator,在左下脚有一个加号,点击添加Add Exception Breakpoint
六、代码实现控件
1、UIButton(按钮)
UIButton *button = [[UIButton alloc]init]; [self.view addSubview:button]; //设置尺寸 button.frame = CGRectMake(30, 150, 300, 100); //设置背景颜色 [button setBackgroundColor:[UIColor blueColor]]; //设置普通状态下的标题 [button setTitle:@"按 钮" forState:UIControlStateNormal]; //设置标题字体大小 button.titleLabel.font = [UIFont boldSystemFontOfSize:30]; //设置普通状态标题的颜色 [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; //设置标题阴影大小 button.titleLabel.shadowOffset = CGSizeMake(3.0, 3.0); //设置阴影的颜色 [button setTitleShadowColor:[UIColor redColor] forState:UIControlStateNormal]; //在按钮中追加图片,只有按钮的类型为UIButtonTypeRoundedRect和UIButtonTypeCustom时有效 [button setImage:[UIImage imageNamed:@"buttongreen"] forState:UIControlStateNormal]; //调整按钮的边间距 UIEdgeInsets insets; insets.top = insets.bottom = insets.left = insets.right = 15; button.contentEdgeInsets = insets; //添加按钮的响应方法 [button addTarget:self action:@selector(helloWold) forControlEvents:UIControlEventTouchDragInside]; //根据内容对按钮的大小进行调整 [button sizeToFit]; //设置按钮的透明度 button.alpha = 0.5;
2、UILabel(标签)
UILabel *label = [[UILabel alloc]init]; [self.view addSubview:label]; //调整标签的大小,与屏幕一样大小 label.frame = self.view.bounds; //设置背景颜色 label.backgroundColor = [UIColor greenColor]; //设置标签文字 label.text = @"标签标签标签标签标签标签标签标签标签"; //设置文字的颜色 label.textColor = [UIColor yellowColor]; //设置文字大小 label.font = [UIFont systemFontOfSize:58.0]; //设置阴影的颜色 label.shadowColor = [UIColor redColor]; //设置阴影的位置 label.shadowOffset = CGSizeMake(3, 3); //设置文字居中 label.textAlignment = NSTextAlignmentCenter; //设置多行显示,0表示当标签足够大时,自动调整行数;大于0时,1表示一行,2表示两行,3表示是三行... label.numberOfLines = 0; //设置换多行时的省略方式 label.lineBreakMode = NSLineBreakByTruncatingHead; //设置标签自动调整宽和高 //label.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; //字体自动调整大小,达到能在屏幕上全部显示 //label.adjustsFontSizeToFitWidth = YES; //限制字体能缩小的最小值 //label.minimumScaleFactor = 13;
3、UITextField(文本输入框)
UITextField *TextField = [[UITextField alloc]init]; [self.view addSubview:TextField]; //设置尺寸 TextField.frame = CGRectMake(40,200, 280, 30); //设置输入框的样式 TextField.borderStyle = UITextBorderStyleRoundedRect; //设置输入框的背景颜色 TextField.backgroundColor = [UIColor whiteColor]; //设置输入框的提示信息 TextField.placeholder = @"请输入文字"; //设置默认文本 //TextField.text = @"文本输入框"; //设置字体颜色 TextField.textColor = [UIColor blueColor]; //设置字体大小 TextField.font = [UIFont systemFontOfSize:24]; //设置文本的居中对齐 TextField.textAlignment = NSTextAlignmentCenter; //追加文本框的清空按钮 TextField.clearButtonMode = UITextFieldViewModeWhileEditing; //设置第一响应者,打开键盘 [TextField becomeFirstResponder]; //失去第一响应者,关闭键盘 [TextField resignFirstResponder]; //设置输入框不可编辑 //[TextField setEnabled:NO]; //追加响应事件 [TextField addTarget:self action:@selector(eventName) forControlEvents:UIControlEventTouchDragInside];
4、UIImageView(图片显示)
- UIImageView的创建
UIImageView *ImageView = [[UIImageView alloc]init]; [self.view addSubview:ImageView]; //设置大小 ImageView.frame = CGRectMake(80, 200, 200, 200); //添加图片 ImageView.image = [UIImage imageNamed:@"buttongreen"];
- UIImageView的动画属性和相关方法
@property(nonatomic) NSTimeInterval animationDuration; //帧动画的持续时间
@property(nonatomic) NSInteger animationRepeatCount; //帧动画的执行次数(默认是无限循环)
- (void)startAnimating; //开始执行帧动画
- (void)stopAnimating; //停止执行帧动画
- (BOOL)isAnimating; //是否正在执行帧动画
0 0
- UI基础第二天(知识点)
- UI基础第二天(代码)
- UI基础第二天(自学)
- UI基础第一天(知识点)
- UI基础第三天(知识点)
- UI-第二讲:基础控件
- 第二章:java基础语法(java知识点)
- Android学习笔记---第二天---基础UI组件---Toast
- Android学习笔记---第二天---基础UI组件---TextView
- Android学习笔记---第二天---基础UI组件---EditText
- UI基础第二弹:Button基础
- springmvc第二天知识点
- UI基础的知识点与小项目
- javaSE学习第二周基础知识点总结
- 基础总结知识点-第二章:HTTP协议
- 《每天3分钟学开发》ios开发之UI基础:UI 第二天!
- UI第二天总结
- UI第二天
- mp4文件格式解析
- uva 10881
- sed,awk
- CSS flex
- 需求:子结点选中,父节点随之选中,父节点取消,子节点随之取消
- UI基础第二天(知识点)
- Android版:验证手机号码的正则表达式
- java自学——字符串
- Ubuntu安装OpenGL开发环境
- Android中使用WIFI来连接ADB
- HDOJ1715
- 一个UITableViewCell简单动画效果
- hdu1233+最小生成树
- void * 和int 类型转换