js基础
1)对js的理解?
2)请说出以下代码输出的值?
3)把以下代码,改写成依次输出0-9
4)如何区分数组对象,普通对象,函数对象
5)面向对象、面向过程
6)面向对象的三大基本特性
7)XML和JSON的区别?
8)Web Worker 和webSocket?
9)Javascript垃圾回收方法?
10)new操作符具体干了什么呢?
11)js延迟加载的方式有哪些?
12)WEB应用从服务器主动推送Data到客户端有那些方式?
- (void)viewDidLoad {
[super viewDidLoad];
//创建UIImage对象:指定图片为1.jpg
UIImage *image = [UIImage imageNamed:@“1.jpg”];
//创建UIImageView对象,指定image对象为image
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
//指定ImageView容器的位置及长宽
imageView.frame = CGRectMake(0, 0, image.size.width, image.size.height);
//指定图片以屏幕中心点放置
imageView.center = CGPointMake(self.view.frame.size.width*0.5, self.view.frame.size.height*0.5);
/*
几种UIImage的内容模式:
UIViewContentModeScaleToFill, //自动适应长宽(图片会变形)
UIViewContentModeScaleAspectFit, //自动适应宽度(如果图片过大,会被缩放)
UIViewContentModeScaleAspectFill, //自动填充(如果图片过大,只会显示一部分)
UIViewContentModeRedraw, //图片重绘
UIViewContentModeCenter, //图片以中心点放置
UIViewContentModeTop, //图片以顶部放置
UIViewContentModeBottom, //图片以底部放置
UIViewContentModeLeft, //图片以左边中心点放置
UIViewContentModeRight, //图片以右边边中心点放置
UIViewContentModeTopLeft, //图片以左上角放置
UIViewContentModeTopRight, //图片以右上角放置
UIViewContentModeBottomLeft, //图片以左下角放置
UIViewContentModeBottomRight, //图片以右下角放置
*/
imageView.contentMode = UIViewContentModeScaleToFill;
[self.view addSubview:imageView];
}
### 二、通过 NSData 方式载入
NSString *filePath = [[NSBundle mainBundle] pathForResource:fileName ofType:extension];
NSData *image = [NSData dataWithContentsOfFile:filePath];
[UIImage imageWithData:image];
### 三、使用 imageWithContentsOfFile 函数载入
通过`NSBundle`对象的`mainBundle` 方法创建`NSBundle`对象后调用`pathForResource`方法获取图片路径。然后通过`UIimage`的`imageWithContentsOfFile`类方法创建图片对象。
NSString *path = [[NSBundle mainBundle] pathForResource:@”shq5785” ofType:@”png”];
myImage = [UIImage imageWithContentsOfFile:path];
注意⚠️:
* 应用 `imageNamed` 函数方式载入时。系统会把图像`Cache`到内存。假设图像比較大。或者图像比較多。用这样的方式会消耗非常大的内存。可是利用`imageNamed`载入图像也有自己的优势。对于同一个图像系统仅仅会把它`Cache`到内存一次,这对于图像的反复利用是非常有优势的。
* 利用`NSData`或`imageWithContentsOfFile`方式载入时。仅载入图片,图像数据不会缓存。因此对于较大的图片以及使用情况较少时,那就能够用该方法,减少内存消耗。
* 通过`imageNamed`类方法加载的图片,通常放置在`Assets.xcassets`中且也能加载ipa包路径下的图片资源。
通过`imageWithContentsOfFile`类方法加载的图片,只能获取ipa包路径下的图片资源。
### 四、拓展阅读
#### react和vue的比较
相同
1)vitual dom
2)组件化
3)props,单一数据流
不同点
1)react是jsx和模板;(jsx可以进行更多的js逻辑和操作)
2)状态管理(react)
3)对象属性(vue)
4)vue:view——medol之间双向绑定
5)vue:组件之间的通信(props,callback,emit)
>**[开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】](https://bbs.csdn.net/forums/4304bb5a486d4c3ab8389e65ecb71ac0)**
![](https://img-blog.csdnimg.cn/img_convert/579fd5f6e326867f2d58a20b3fc89aeb.webp?x-oss-process=image/format,png)
![](https://img-blog.csdnimg.cn/img_convert/3c176be7ac07330d845de06d920a6129.webp?x-oss-process=image/format,png)
c3ab8389e65ecb71ac0)**
[外链图片转存中...(img-HlryGifa-1715644629882)]
[外链图片转存中...(img-uwVa4xQe-1715644629882)]