如何用UIColor类设置全局变量 [英] How to set global variable with UIColor class

查看:159
本文介绍了如何用UIColor类设置全局变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发iPhone应用程序。在这个应用程序中我有4种不同的意见。在所有视图中我设置背景颜色。见下面的代码

  self.view.backgroundColor = [UIColor colorWithRed:(238.0f / 255.0f)green:(251.0f / 255.0f)蓝色:(255.0f / 255.0f)alpha:0.8f]; 

我正在测试背景颜色的各种颜色。当我必须改变任何颜色时,我需要在所有视图控制器中进行更改。而不是我可以让这个全局变量?我不知道如何在全局变量中设置UIColor。请给我一些建议。

解决方案

非常简单。

在AppDelegate.h中:
$ b $ pre $ #define kGlobalColor [UIColor colorWithRed:(238.0f / 255.0f)绿色:(251.0f / 255.0f)蓝色:(255.0f / 255.0f)alpha:0.8f]

在ViewControllers中:

$ p $ #importAppDelegate.h

self.view.backgroundColor = kGlobalColor;


i am developing on iPhone application. in this app i have 4 different views. in all views i set background color. see bellow code

self.view.backgroundColor = [UIColor colorWithRed:(238.0f/255.0f) green:(251.0f/255.0f) blue:(255.0f/255.0f) alpha:0.8f];

i am testing various colors for background color. when i have to change any colour i need to change in all view controllers. instead of that can i make global variable for this ? i don't know how to set UIColor in global variable. please suggest me some ideas.

解决方案

Very simple.
In AppDelegate.h:

#define kGlobalColor [UIColor colorWithRed:(238.0f/255.0f) green:(251.0f/255.0f) blue:(255.0f/255.0f) alpha:0.8f]

In ViewControllers:

#import "AppDelegate.h"

self.view.backgroundColor = kGlobalColor;

这篇关于如何用UIColor类设置全局变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆