UIImage用imageNamed的内存问题

本文深入探讨了使用Objective-C进行iOS应用开发的技术细节和最佳实践,包括面向对象编程、类继承、消息传递机制、核心数据管理、UIKit组件使用、Core Animation动画效果等。同时,介绍了如何利用Xcode集成开发环境高效编写和调试代码,确保应用的稳定性和性能优化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

@implementation UIImage(imageNamed_Hack)

+ (UIImage *)imageNamed:(NSString *)name {
NSString *path = [NSString stringWithFormat:@"%@/%@",
[[NSBundle mainBundle] bundlePath],
name];
return [UIImage imageWithContentsOfFile:path];
}

@end
/ // HBBaseTabbarViewController.m // wechat // // Created by josh on 2025/3/21. // #import "HBBaseTabbarViewController.h" #import "HBCustomTabBar.h" #import "HBFriendLineViewController.h" #import "HBProfileViewController.h" #import "HBHomeViewController.h" #import "HBContactViewController.h" @interface HBBaseTabbarViewController () @end @implementation HBBaseTabbarViewController - (void)viewDidLoad { [super viewDidLoad]; // 替换默认的 TabBar [self setValue:[[HBCustomTabbar alloc] init] forKey:@"tabBar"]; // 设置子视图控制器 [self setupViewControllers]; } - (void)setupViewControllers { // 创建 4 个子视图控制器 HBHomeViewController *homeVC = [[HBHomeViewController alloc] init]; // homeVC.view.backgroundColor = [UIColor whiteColor]; homeVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"首页" image:[UIImage imageNamed:@"home"] selectedImage:[UIImage imageNamed:@"home-sel"]]; HBContactViewController *contactVC = [[HBContactViewController alloc] init]; // contactVC.view.backgroundColor = [UIColor whiteColor]; contactVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"通讯录" image:[UIImage imageNamed:@"contact"] selectedImage:[UIImage imageNamed:@"tongxunlu-sel"]]; HBFriendLineViewController *frienVC = [[HBFriendLineViewController alloc] init]; frienVC.view.backgroundColor = [UIColor whiteColor]; frienVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"朋友圈" image:[UIImage imageNamed:@"pengyouquan"] selectedImage:[UIImage imageNamed:@"pengyouquan-sel"]]; HBProfileViewController *profileVC = [[HBProfileViewController alloc] init]; profileVC.view.backgroundColor = [UIColor whiteColor]; profileVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"我的" image:[UIImage imageNamed:@"me"] selectedImage:[UIImage imageNamed:@"me-sel"]]; // 将子视图控制器添加到 TabBarController self.viewControllers = @[homeVC, contactVC, frienVC, profileVC]; } 这一串代码的作用
最新发布
03-24
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值