简体   繁体   English

更改所有应用的配色方案

[英]Change all the app color scheme

So, I have a HomeViewController (picture 1) with two buttons, one white and one blue. 因此,我有一个带有两个按钮的HomeViewController(图1),一个为白色,一个为蓝色。 On the right bottom corner you can see a button which modally presents a SettingsViewController (picture 2), on this view controller there are 4 buttons so the user can choose which color scheme do they prefer. 在右下角,您可以看到一个按钮,该按钮以模态呈现一个SettingsViewController(图2),在该视图控制器上,有4个按钮,因此用户可以选择他们喜欢的配色方案。 Imagine the user press the first one (red) then, when dismissing the view controller the color scheme of HomeViewController should look like picture 3. 想象用户按下第一个(红色),然后在关闭视图控制器时,HomeViewController的配色方案应如图3所示。

在此处输入图片说明

Any ideas on how to do this on a efficiently/simple way?. 关于如何有效/简单地执行此操作的任何想法?

There are two good ways you could do this: 1) Delegation, and 2) viewWillAppear: . 您可以通过两种方法进行此操作:1)委派,以及2) viewWillAppear:

For delegation , you'll need to define a protocol. 对于委派 ,您需要定义一个协议。 Your HomeViewController will be a delegate for this protocol, and your SettingsViewController will call it. 您的HomeViewController将是此协议的delegate ,而您的SettingsViewController将调用它。

//SettingsViewController.h

@protocol SettingsDelegate <NSObject>
@required
-(void)colorChanged:(UIColor *)color;
@end

@interface SettingsViewController : UIViewController

@property (nonatomic, weak) id<SettingsDelegate> delegate;

@end

Somewhere when the settings view controller is set up, make sure to set self.delegate equal to a reference to HomeViewController . 设置设置视图控制器时,请确保将self.delegate设置为等于对HomeViewController的引用。 This is a must. 这是必须的。

Then, when your user changes the color, call: 然后,当您的用户更改颜色时,请致电:

[self.delegate colorChanged:whateverColor];

Your delegate must obviously observe this method, and change the color appropriately: 您的代表显然必须遵守此方法,并适当更改颜色:

-(void)colorChanged:(UIColor *)color {

    [myButton setBackgroundColor:color];
}

For viewWillAppear: , just save the color somewhere and set the color of your button in your view controller's method for this. 对于viewWillAppear:只需将颜色保存在某个位置,然后在视图控制器的方法中设置按钮的颜色即可。 viewWillAppear: will get called when your settings view is about to disappear and show the home view controller: viewWillAppear:当您的设置视图即将消失并显示主视图控制器时,将被调用:

-(void)viewWillAppear:(BOOL)animated {

    [super viewWillAppear:animated];

    [myButton setBackgroundColor:mySavedColor];
}
In HomeViewController
On SettigButton Click
 {
   Pass the HomeViewController delegate object SettingsViewController 
   Present your color Picker SettingsViewController 

 }

In SettingsViewController
 Define protocol name SettingsViewControllerDelegate 
   {
    -(void)selectedColor:(UIColor*)color;
   }

  return the selected color On dismissViewController
  if(delegate)
    {
     [delegate selectedColor:color];
    }


Again In HomeViewController
 -(void)selectedColor:(UIColor*)color
{
  view.backgroundColor=color;

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 根据应用方案更改启动屏幕的 storyboard 背景颜色 - Change storyboard background color of the Launch Screen based on app scheme iOS应用-更改版本号方案 - iOS App - Change Version Number Scheme 根据当前配色方案更改 Sign In With Apple 按钮样式 - Change Sign In With Apple button style based on current color scheme React Native实时改变配色方案问题android - React native change color scheme in real time problem android 更改App委托中的背景颜色 - Change background color in App delegate 在旋转时更改app后面的颜色 - Change color behind app on rotation 如何根据设备主题更改 collectionview 单元格颜色(按照我的配色方案) - How to change collectionview cells color based on device theme (following my color scheme) Facebook应用程序是否有通用URI方案,适用于所有移动设备? - Is there a universal URI scheme for Facebook app, that works across all mobile devices? 有没有办法通过使用用户默认值更改我的所有IOS应用程序页面的Bg颜色? - Is there a way to change all of my IOS App page's Bg Color by using User Defaults? 如何在 Swift 中更改 UIView 中所有标签的颜色? - How to change the color of all Labels in a UIView in Swift?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM