• 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];
  • 相关阅读:
    产品需求说明书PRD模版
    会编程的 AI + 会修 Bug 的 AI,等于什么 ?
    会编程的 AI + 会修 Bug 的 AI,等于什么 ?
    会编程的 AI + 会修 Bug 的 AI,等于什么 ?
    luogu P1164 小A点菜
    luogu P1347 排序
    luogu P1195 口袋的天空
    luogu P1182 数列分段Section II
    luogu P1332 血色先锋队
    luogu P1983 车站分级
  • 原文地址:https://www.cnblogs.com/angelshelter/p/7399854.html
Copyright © 2020-2023  润新知