zoukankan      html  css  js  c++  java
  • xcode资源管理

    1. 在根目录放图片。

        UIImageView *image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ok.png"]];//也可以直接填"ok",网上是说,如果扩展名是png就可以省略。
        image.frame = CGRectMake(0, 0, 320, 320);
        [self.view addSubview:image];

    2. 在实目录下放图片。

        NSString *themePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"img/ok.png"];
        NSLog(@"%@", themePath);
        UIImage *image = [UIImage imageWithContentsOfFile:themePath];
        UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
        [self.view addSubview:imageView];

    这个themePath打印出来是

    /var/containers/Bundle/Application/63DC9D8A-2249-4BC0-B220-4EF18C244784/ImageTest.app/img/ok.png

    3. 在bundle里面加载资源。bundle是一个很神奇的技术,可以把资源打包。

        NSString *path = [NSString stringWithFormat:@"QPSDK.bundle/root_bg.png"];  //QPSDK.bundle是bundle的文件名。
        UIImage *image = [UIImage imageNamed:path];
        UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
        [self.view addSubview:imageView];

    4. 读取assets里面的图片。其实这个和第一点提到的代码是一样的。只是这里的123是像集的名字。

        UIImageView *image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"123"]];  //123是像集的名字,没有扩展名。
        image.frame = CGRectMake(0, 0, 320, 320);
        [self.view addSubview:image];
  • 相关阅读:
    yum提示Another app is currently holding the yum lock
    函数参数返回值作用域笔记
    递归内置函数笔记
    装饰器笔记
    函数笔记扩展
    集合笔记
    线程和进程
    函数笔记
    线程与进程的区别
    Ubuntu操作及各种命令笔记.txt
  • 原文地址:https://www.cnblogs.com/angelshelter/p/7399854.html
Copyright © 2011-2022 走看看