我單身全球一流的具有都在同一類這些categeories,在頭文件中的接口和implemantation提交其實現如下,帶有類別的iPhone全球課,這是正確的嗎?
這工作,但我不太清楚我在做什麼是一個好習慣這裏是因爲它已經是一個單例類了,我將這些方法稱爲類別並執行一些分配,釋放......以及其他東西。或者他們在全球一級之外是因爲他們是不同的實現?
你能告訴我一切是否正確嗎?
#import "GlobalConfig.h"
#import "SynthesizeSingleton.h"
@implementation GlobalConfig
SYNTHESIZE_SINGLETON_FOR_CLASS(GlobalConfig);
@end
@implementation UIColor (APP)
+(UIColor *) APP_NAV_COLOR { return [UIColor colorWithRed:00/256.0 green:111/256.0
blue:59/256.0 alpha:1.0]; }
+(UIColor *) APP_BUTTON_COLOR { return [UIColor colorWithRed:00/256.0 green:00/256.0
@end
@implementation UIImage(APP)
+(UIImage *) APP_IMAGE_BCKGROUND {
NSString *path = [[NSBundle mainBundle] pathForResource:@"bckPhone" ofType:@"png"];
return [UIImage imageWithContentsOfResolutionIndependentFile:path];
}
@end
@implementation CALayer(APP)
+(CALayer *) APP_SELECTION_VIEW:(UITableViewCell *)cell {
UIView *cellView = [[UIView alloc] initWithFrame:cell.frame];
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = cellView.bounds;
gradient.startPoint = CGPointMake(0.5, 0);
gradient.endPoint = CGPointMake(0.5, 1);
gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor APP_WHITE_COLOR] CGColor], (id)[[UIColor APP_BLACK_COLOR] CGColor], nil];
[cellView release];
return gradient;
}
@end
@implementation UIView(APP)
+(UIView *) APP_BACKGROUND_VIEW:(UITableViewCell *)cell {
UIView *cellView2 = [[UIView alloc] initWithFrame:cell.frame];
CAGradientLayer *gradient2 = [CAGradientLayer layer];
gradient2.frame = cellView2.bounds;
gradient2.startPoint = CGPointMake(0, 0.5);
gradient2.endPoint = CGPointMake(1, 0.5);
gradient2.colors = [NSArray arrayWithObjects:(id)[[UIColor APP_WHITE_COLOR] CGColor], (id)[[UIColor APP_COLOR] CGColor], nil];
[cell.layer insertSublayer:gradient2 atIndex:0];
[cellView2 release];
UIView *myBackView = [[UIView alloc] initWithFrame:cell.frame];
myBackView.backgroundColor=[[UIColor APP_COLOR] colorWithAlphaComponent:0.1];
[myBackView autorelease];
return myBackView;
}
@end
tnx我應該創建另一個非單實例的utiliy類,並將其中的所有類別? – Spring
如果您願意,您可以創建一個實用程序文件,並將所有類別(每個類別都視爲類/接口語法)。然後,當您使用它們時,您將立即導入所有這些文件。或者你可以有單獨的文件,所以你可以一個一個地導入它們。 – sergio
我剛剛將它們移到另一個類中,並且我收到了其他正在使用它們的類的警告,因爲它們可能不會響應該方法?我是否必須手動將該類導入到每個我使用的類中?並且不需要實例化我猜? – Spring