快速接手新項目技巧:使用Runtime找到UIImage名字

在新接手的項目上作開發是比較慢的,尤爲是開發、產品、設計都換了幾波人的上了年紀的項目。其實咱們仍是能夠經過一些途徑來提升維護老項目的效率。好比今天(全新的開發人員、產品、設計)就碰到設計說新作的需求有一個切圖是app中原來就有的,爲了保持風格統一,沿用原來的切圖。難道還須要定位到當前的頁面對應的代碼中去尋找相應圖片的名字嗎?若是後面的新需求有大量相似的圖片怎麼辦?通過一番思考,肯定了一種比較快速定位圖片名字的方法。以下:html

第一步:給UIImage添加name屬性

利用runtimeUIImage的分類中給UIImage關聯一個屬性p_name,替換原來的imageNamed:方法,在本身的方法中將圖片的名字保存到p_name中。ios

#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface UIImage (name)
@end
NS_ASSUME_NONNULL_END
複製代碼
#import "UIImage+name.h"
#import <objc/runtime.h>

@implementation UIImage (name)
- (void)setP_name:(NSString *)p_name {
    objc_setAssociatedObject(self, @selector(p_name), p_name, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
-(NSString *)p_name {
    return objc_getAssociatedObject(self, _cmd);
}
+ (UIImage *)wsk_imageNamed:(NSString *)imageName {
    UIImage *image = [UIImage wsk_imageNamed:imageName];
    image.p_name = imageName;
    return image;
}
+(void)load {
    Method imageNameMethod = class_getClassMethod([self class], @selector(imageNamed:));
    Method wsk_imageNamedMethod = class_getClassMethod([UIImage class], @selector(wsk_imageNamed:));
    method_exchangeImplementations(imageNameMethod, wsk_imageNamedMethod);
}
@end
複製代碼

第二步:找到目標UIImageVIew的地址

  • 方法二:使用Chisel命令pviews

  • 方法三:使用工具FLEX找到UIImageVIew的地址。

第三步:打印圖片的名字

使用LLDBpo命令 po [((UIImageView*)0x122203f40).image valueForKey:@"p_name"] 打印圖片的名字。git

注意: xib中設置的圖片名字,打印爲nilgithub


視頻轉GIF步驟xcode

  • 一、brew install ffmpeg
  • 二、ffmpeg -ss 00:00:00 -i flex.mov -s 375x667 -r "2" flex.gif
相關文章
相關標籤/搜索