`

[UIImage imageNamed:@"icon.png"] 加载图片的问题

    博客分类:
  • iOS
阅读更多

 [UIImage imageNamed:@"icon.png"]

用上面的方法加载图片有问题.
这种方法在application bundle的顶层文件夹寻找由供应的名字的图象 。 如果找到图片,装载到iPhone系统缓存图象。那意味图片是(理论上)放在内存里作为cache的。
如果图片多乐,就傻了.
图片cache极有可能不会响应 memory warnings and release its objects

使用图片的时候一定要小心的alloc和release

 

推荐使用下面的方法做处理:


NSString *path = [[NSBundle mainBundle] pathForResource:@"icon" ofType:@"png"];
myImage = [UIImage imageWithContentsOfFile:path];

分享到:
评论

相关推荐

    ios-图片拖动更换位置.zip

    imageview上面加长按及滑动手势来重置imageView的位置 ..._imagesUrlArr=[@[@"http://chenggua.com/imagesUrl/20151204/201512042214246086.png",[UIImage imageNamed:@"22.jpg"],[UIImage imageNamed:@"33.jpg"],@...

    ios-iOS图片浏览工具,简单使用,支持缩放,放大,双击单击操作.zip

    STPhotoBroswer * broser = [[STPhotoBroswer alloc]initWithImageArray:@[[UIImage imageNamed:@"1.jpg"],[UIImage imageNamed:@"2.jpg"],[UIImage imageNamed:@"3.jpg"],[UIImage imageNamed:@"1.jpg"],[UIImage ...

    SDK1.6.2 demo.zip

    UIImage *thumbImage = [UIImage imageNamed:@"res1thumb.png"]; [WXApiResponseHandler respImageData:imageData MessageExt:nil Action:nil ThumbImage:thumbImage]; [self ...

    ios-Clock for iOS (秒针两种旋转样式).zip

    [self setClockBackgroundImage:[UIImage imageNamed:@"xxx"].CGImage]; [self setSecHandImage:[UIImage imageNamed:@"xxx"].CGImage]; [self setMinHandImage:[UIImage imageNamed:@"xxx"].CGImage]; [self ...

    ios-HcdGuideView引导页-通过简单的方法给app加入引导页面.zip

    [images addObject:[UIImage imageNamed:@"1"]];[images addObject:[UIImage imageNamed:@"2"]];[images addObject:[UIImage imageNamed:@"3"]];[[HcdGuideViewManager sharedInstance] showGuideViewWithImages:...

    iOS 各种动画

    imageView.image = [UIImage imageNamed:@"twitter background.png"]; [self.view addSubview:imageView]; //Twitter style splash SKSplashIcon *twitterSplashIcon = [[SKSplashIcon alloc] initWithImage:...

    ios-包装了一个富文本类.zip

    att_str = [SHAttributedString attributedEmailStringWithString:att_str insertImage:[UIImage imageNamed:@"compose_emoticonbutton_background_highlighted@2x"] orEmailNameString:@"邮箱"]; //计算size ...

    IOS点赞效果按钮源代码下载

    CatZanButton *zanBtn=[[CatZanButton alloc] initWithFrame:CGRectMake(0, 0, 50, 50) zanImage:[UIImage imageNamed:@"Zan"] unZanImage:[UIImage imageNamed:@"UnZan"]]; [zanBtn setCenter:self.view.center]; ...

    ios-iOS随机数字键盘,可设背景图等.zip

    XTYRandomKeyboard *keyBoad = [[XTYRandomKeyboard alloc] initWithTitleColor:[UIColor blackColor] backGroundImage:[UIImage imageNamed:@"bg.jpg"]]; [keyBoad setInputView:textField]; [self.view ...

    IOS 裁剪图片 封装 简单易用

    _tkImageView.toCropImage = [UIImage imageNamed: @"test.jpg"]; _tkImageView.showMidLines = YES; _tkImageView.needScaleCrop = YES; _tkImageView.showCrossLines = YES; _tkImageView....

    ios-点击切换状态の按钮Multi-Button.zip

    Multi-Button, click ...[btn setBackgroundImage:[UIImage imageNamed:@"xxx.png"]]; [btn setBackgroundColor:[UIColor orangeColor]]; [btn.titleLabel setFont:...]; [btn.detailLabel setFont:...];

    ios-项目内语言切换.zip

    4.在pch文件里增加宏定义: 文字 KLOCALIZED_String(STR) [[InternationalControl bundle] localizedStringForKey:STR value:nil table:@"Localizable"] 图片 KLOCALIZED_UIImageName(NAME) [UIImage imageNamed:[...

    KXMenu 十分好用的弹出菜单

    image:[UIImage imageNamed:@"action_icon"] target:self action:@selector(feedBack:)], UIButton * btn = sender; [KxMenu showMenuInView:self.view fromRect:btn.frame menuItems:menuItems]; } - (void)...

    OC Extension UIImage+FHXImage(图片扩展).zip

    注意:.m文件小了一个方法 ,下载下来把它复制进去 /** 加载gif动画 */ ... * 返回圆形图片 iconView.image = [[UIImage imageNamed:@"Yosemite01"] dc_circleImage]; */ + (instancetype)circle

    iPhone SDK Examples

    [myImage setImage:[UIImage imageNamed:@"myImage.png"]]; myImage.opaque = YES; // 为了性能,设置为不透明 [self.view addSubview:myImage]; [myImage release]; ``` 这段代码创建了一个指定大小的`...

    IOS 代码 自动化布局

    bgImage.image=[UIImage imageNamed:@"bg.png"]; bgImage.translatesAutoresizingMaskIntoConstraints = NO; [self.view addSubview:bgImage]; NSDictionary *viewsbg = NSDictionaryOfVariableBindings(self....

    iOS常用动画

    UIView *manImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"your_image"]]; [UIView beginAnimations:@"doflip" context:nil]; [UIView setAnimationDuration:1]; [UIView ...

    02-通过代码创建按钮

    // 1.创建按钮 UIButton *btn = [[UIButton alloc] init];... UIImage *normal = [UIImage imageNamed:@"btn_01"]; // 4.2设置普通状态下的背景图片 [btn setBackgroundImage:normal forState:UIControlStateNormal];

    ios-酷炫重力感应imageView.zip

    imageView.image = [UIImage imageNamed:@"login_bg6.png"]; [self.view addSubview:imageView]; [imageView startAnimate]; 觉得好用的话请给个star哦 Xcode 7.3.1编译通过,iOS 9.x、8.x测试通过

    ios-MKShow修改版.zip

    [MKShowDynamic setDefaultBackImage:[UIImage imageNamed:@"ico_show_black"]]; //设置默认的弹出样式 [MKShowDynamic setDefaultMKShowShowStyle:MKShowShowStyleDefault]; //不设置动画 ...

Global site tag (gtag.js) - Google Analytics