1016-07-6、7适配问题

     图片拉伸

___________________________________________________

___________________________________________________

 

1. 如果图片比较大得话,不要用 [UIImage imageNamed:@"big.png"]; 去加载.

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIImageView *imageView = [[UIImageView alloc] init];
    imageView.image = [UIImage imageNamed:@"avatar_vip"];
//    NSString *file = [[NSBundle mainBundle] pathForResource:@"avatar_vip@2x" ofType:@"png"];
//    imageView.image = [UIImage imageWithContentsOfFile:file];
    imageView.frame = CGRectMake(10, 50, 34, 34);
    [self.view addSubview:imageView];
    
    
    // 这个方法加载的图片不会有缓存,适合用来加载大图片、一次性的图片(使用频率比较低)
//    [UIImage imageWithContentsOfFile:<#(NSString *)#>];
    
    // 这个方法加载的图片会有缓存,适合用来加载小图片、使用频率比较高的图片
//    [UIImage imageNamed:@"searchbar_textfield_background"];
    
    
    // 建议:1.小图片可以放在Images.xcassets中;2.大图片建议放在Supporting Files中

}

 

___________________ 这个是NSBunld mainBunld 路径,不是沙盒路径  ________________________________

     

________________图1  _______________________________________________________________图2 ___________________ 

___________图3  ________

图一图二图三加起来是沙盒路径,缓存的图片都存在 “6/7适配问题” 这个文件夹这级目录下面。[[NSBundle mainBundle] pathForResource:@"avatar_vip@2x" ofType:@"png"]; 在这一级目录下找图片资源。

 

1. 所有图片都会压缩在 Assets.car 里面。

2. 图片不管是放在 [NSBundle mainBundle] 里面,还是压缩在 Assets.car 里面,[UIImage imageNamed:@"avatar_vip"];都是好使的。

3. 在iOS6中,图片放在 Assets.car 里面,[[NSBundle mainBundle] pathForResource:@"avatar_vip@2x" ofType:@"png"];是找不到的。iOS7是可以找到的。放在 Images.xcassets 里面的图片是有缓存的。

4. 不管是适配几,只要将图片放在 Supporting Files 下面,图片就会出现在 mainBundle 路径里面。所以只要放在这个目录下,通过任何方法都能加载。

5. 放在Assets.car 里面的图片是不能通过 imageWithContentsOfFile 来加载的。

 

以上待整理。

 

6. Supporting Files 只能放图片,不能看图片的特性;放 Images.xcassets 下面的图片却可以。

7. [[NSBundle mainBundle] pathForResource:@"avatar_vip@2x" ofType:@"png"];是加载图片的全路径。

posted @ 2016-03-13 14:06  nxz_diy  阅读(390)  评论(0编辑  收藏  举报