創建constant.h
文件的NSObject
和定義該彩色全局
的#define globalColor [的UIColor colorWithRed:(238.0f/255.0f)綠色:(251.0f/255.0f)藍色:(255.0f/255.0f)alpha:0.8f];
,當你想使用它只是導入其他常量文件明智選擇2波紋管是..
第二個選項
在AppDelegate.h
文件只是財產合成像波紋管的UIColor的一個變量。 。
@interface AppDelegate : UIResponder <UIApplicationDelegate>{
///your Data
UIColor *globalColor;
}
@property (nonatomic,retain) UIColor *globalColor;
,並在像波紋管.m文件合成..
@syntesize globalColor;
和didFinishLaunchingWithOptions
方法只是asssign顏色來這個變量..
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
globalColor = [UIColor colorWithRed:(238.0f/255.0f) green:(251.0f/255.0f) blue:(255.0f/255.0f) alpha:0.8f];
}
,當你要使用這種顏色使用這樣的..
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
self.view.backgroundColor = appDelegate.globalColor;
我上面的回答使用。但是這給了我一個錯誤。 **使用未聲明的標識符'kGlobalColor'** –
不要忘記在視圖控制器中導入常量文件,在這種情況下,AppDelegate.h – pbibergal
我也這樣做了。 –