Tim*_*Tim 4 iphone user-interface themes
嗨我正在尝试用主题切换器编写一些iPhone应用程序,用户可以选择主题来更改背景颜色,alpha,图像和一些按钮的外观(大小,图像,甚至位置).
应用主题的最佳方式是什么?
蒂姆,谢谢
这是我如何实现改变FemCal主题的能力.我已经以代码片段的形式包含了一些细节.
创建一个存储颜色,图像等的单例ThemeMgr类.在需要时获取单例.
@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];
}
显然,您将有一些UI来选择所需的主题.在这种情况下,用户选择一个主题并// listen for change notification
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateAppearance:) name:@"ThemeChange" object:nil];
在0.5秒后触发.在强制UI重绘之前,这给其他UI更新提供了一个很好的延迟.在需要处理主题更改的任何地方收听通知.
fireTimer
- (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];
}
不要忘记在必要时重新签名任何通知,并且您必须在viewDidLoad或类似代码中编写代码以在显示视图之前应用任何主题.
| 归档时间: |
|
| 查看次数: |
938 次 |
| 最近记录: |