zoukankan      html  css  js  c++  java
  • 10

    换肤的话,需要 UI 设计师提供一整套不同风格的素材. 为了双方方便, 有以下两条注意点

    (1)  直接让设计师将风格不同的图片分成不同的文件夹

    (2) 不同文件下的图片名称都相同即可

    换肤实现步骤:

    1. 将美工提供的已经分好的文件夹拖入项目中, 以实体文件夹而非Group

    2. 写一个 UIImage 的分类

    3. 为 UIImage 添加方法 

    + (UIImage *)imageWithName:(NSString *)name;

    4. 实现该方法(将文件的解析过程封装在此方法中, 一劳永逸)

    + (UIImage *)imageWithName:(NSString *)name
    {
        NSString *dir = [[NSUserDefaults standardUserDefaults] stringForKey:@"SkinDirNameKey"];
        NSString *path = [NSString stringWithFormat:@"Skins/%@/%@", dir, name];
        return [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:path ofType:nil]];
    }
    // 1. 从本地沙盒中取出当前皮肤的类型
    // 2. 根据当前皮肤类型拼接字符串,得到图片存在于本地的路径
    // 3. 根据路径,拿到并返回当前图片

    5. 这样, 设置图片的时候就可以通过 UIImage 的

    + (UIImage *)imageWithName:(NSString *)name;

    方法进行图片的获取

    6. (拓展) 如果说项目中已经用到了 

    + (nullable UIImage *)imageNamed:(NSString *)name;

    这个方法获取图片, 那么可以通过 Runtime 的方法交换将 UIImage 的 imageNamed 方法交换为 分类中的 imageWithName 方法

  • 相关阅读:
    WPF Margin和Padding
    WPF Tab切换顺序设置
    WPF DataGrid DataGridTemplateColumn
    WPF CheckBox IsHitTestVisible
    WPF Tag
    WPF RadioButton
    WPF 用户控件(UserControl)
    WPF ToolTip
    Style Lessons in Clarity and Grace (11th Edition)中文翻译
    AI for AI
  • 原文地址:https://www.cnblogs.com/chnyang/p/5542967.html
Copyright © 2011-2022 走看看