利用RunTime实现iOS不同版本下使用不同的图片
2016-01-29 21:28
495 查看
1.UIImage 的类目
.h//自己的
非系统的
+(UIImage *)imageWithNamed:(NSString *)name;
.m
//引入runtime
框架库
#import <objc/runtime.h>
+(void)load{ //先执行编译,在执行main函数
NSLog(@"加载");
//在该文件加载到内存的时候
//exchange imageNamed: & imageWithName:
//获取方法名
Method system =
class_getClassMethod([UIImage
class], @selector(imageNamed:));//类方法
Method myfangfa =
class_getClassMethod([UIImage
class], @selector(imageWithNamed:));
//交换方法名
method_exchangeImplementations(system, myfangfa);
}
//方法的实现
+(UIImage *)imageWithNamed:(NSString *)name{
NSString *newName =[name
stringByAppendingString:@"_ios9.1"];
UIImage *image =
nil;
if ([UIDevice
currentDevice].systemVersion.floatValue >=
9) {
image = [UIImage
imageWithNamed:newName];
if (image) {
return image;
}
}
image = [UIImage
imageWithNamed:name];
return image;
}
2."viewController"
UIImageView *imageView = [[UIImageViewalloc]initWithFrame:self.view.bounds];
imageView.image = [UIImage
imageNamed:@"1"];
[self.view
addSubview:imageView];
NSLog(@"%.2f",[UIDevice
currentDevice].systemVersion.floatValue);//系统版本号
相关文章推荐
- iOS开发流程
- 软件瘦身,ios
- iOS 保持界面流畅的技巧
- iOS后台播放
- 【iOS提高】CoreAnimation--Layer
- ios开发(1)
- iOS Label行间距设置
- ios通过代码方式获取crash日志
- iOS MBProgressHUD的简单使用
- iOS判断设备
- iOS推送
- iOS 获取当前日期和星期几,改变导航系统返回按钮的标题
- IOS只改变父视图的的透明度,不会改变子View的透明度
- iOS symbol(s) not found for architecture i386 BUG解决办法
- iOS工程引入ios-charts-master(手动导入)
- iOS解析xml数据
- 好的 iOS 代码习惯
- IOS 开发: NSBundle
- iOS库--.a与.framework
- iOS中动画的使用