Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将主题应用于iPhone应用程序的最佳方式_Iphone_User Interface_Themes - Fatal编程技术网

将主题应用于iPhone应用程序的最佳方式

将主题应用于iPhone应用程序的最佳方式,iphone,user-interface,themes,Iphone,User Interface,Themes,大家好,我正在尝试编写一些带有主题切换器的iPhone应用程序,用户可以选择一个主题来更改背景色、alpha、图像和一些按钮的外观(大小、图像甚至位置) 应用主题的最佳方式是什么 谢谢, 蒂姆还没有得到任何答案。我用events和singlton实现了它。基本上,单例设置对象将更改发送给观察者,观察者根据事件更新GUI。 我记得有一种方法可以让你听到一个实例变量的变化,但是忘记了怎么做。不管怎样,我目前的方式对我来说非常有效。以下是我如何实现在FemCal中更改主题的功能。我已经以代码片段的形式

大家好,我正在尝试编写一些带有主题切换器的iPhone应用程序,用户可以选择一个主题来更改背景色、alpha、图像和一些按钮的外观(大小、图像甚至位置)

应用主题的最佳方式是什么

谢谢,
蒂姆还没有得到任何答案。我用events和singlton实现了它。基本上,单例设置对象将更改发送给观察者,观察者根据事件更新GUI。
我记得有一种方法可以让你听到一个实例变量的变化,但是忘记了怎么做。不管怎样,我目前的方式对我来说非常有效。

以下是我如何实现在FemCal中更改主题的功能。我已经以代码片段的形式包含了一些细节

  • 创建一个存储颜色、图像等的singleton ThemeMgr类。在需要时获取singleton。
    我只有几个视图,所以我已经在我使用的每个控制器中编写了代码,但是您可以使用objective-C的强大功能来混合代码,以更好的方式处理这个问题

  • 实现基于主题实际重画视图的代码。
    -(void)更新外观:(NSNotification*)通知
    {
    //分组表视图的背景
    ThemeMgr*ThemeMgr=[ThemeMgr defaultMgr];
    //更改颜色并重新加载
    [self.tableView setBackgroundColor:[themeMgr tableBackground]];
    [self.tableView重载数据];
    self.navigationController.navigationBar.tintColor=[themeMgr tintColor];
    }
    

  • 在必要时不要忘记放弃任何通知,在显示视图之前,您必须在viewDidLoad或类似工具中编写代码以应用任何主题

    @interface ThemeMgr : NSObject { // selected color and image NSString * selectedColor; NSString * selectedPicture; // dictionaries for color and image NSDictionary * colorData; NSDictionary * imageData; NSDictionary * backgroundData; // names NSArray * colors; NSArray * images; // themes UIColor * tintColor; UIImageView * panelTheme; UIColor * tableBackground; } - (void)fireTimer:(NSTimer *)timer { NSNotification * themeChange = [NSNotification notificationWithName:@"ThemeChange" object:nil]; [[NSNotificationQueue defaultQueue] enqueueNotification:themeChange postingStyle:NSPostWhenIdle]; } // listen for change notification [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateAppearance:) name:@"ThemeChange" object:nil]; - (void)updateAppearance:(NSNotification *)notification { // background for grouped table view ThemeMgr * themeMgr = [ThemeMgr defaultMgr]; // change color and reload [self.tableView setBackgroundColor:[themeMgr tableBackground]]; [self.tableView reloadData]; self.navigationController.navigationBar.tintColor = [themeMgr tintColor]; }