iPhone管理可重复使用的UIImages和UIViews [英] iPhone managing reusable UIImages and UIViews
问题描述
保持我的UI常量在所有控制器中可以单独访问的最佳方法是什么?
What is the best way to keep my UI constants in seperate class accesible from all controllers?
UIView,UIImage和UIColour所有这些图像和颜色都会造成这样的混乱在我的控制器中分配和释放,其中大多数甚至是相同的。我不想在不同的类中一遍又一遍地分配/重新分配相同的图像和视图,我想创建它们一次,缓存它们(或类似的东西)并在需要时轻松访问。
UIView, UIImage and UIColour all these images and colours create a such mess of allocations and releases in my controllers and most of them are even same. Instead of alloc/relase the same images and views, CAlayers over and over again in different classes, I want to create them once, cache them (or something like that) and easily access when needed.
我想保持记忆和我的代码清洁。
I want to keep memory and my code clean.
推荐答案
是的,可能的
创建一个类似gconstants的类,然后将所有字符串存储在h / m文件中
create a class like gconstants , then store all your string here in h/m files
extern NSString *const APP_TITLE;
@interface UIColor (APP)
+(UIColor *) APP_NAV_COLOR;
@end
.b文件中的
in .m file
NSString *const APP_TITLE = @"APP Name";
@implementation UIColor (APP)
+(UIColor *) APP_NAV_COLOR { return [UIColor colorWithRed:00/256.0 green:111/256.0
blue:59/256.0 alpha:1.0]; }
@end
以及任何controller声明头文件
and in any controller declare the header file
self.title = APP_TITLE;
这篇关于iPhone管理可重复使用的UIImages和UIViews的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!