xcode 如何使 iPhone 应用程序“可换肤”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7165663/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 21:47:56  来源:igfitidea点击:

How to make iPhone app "skinnable"?

iphoneiosxcodeskin

提问by jorjap

I was asked by a client to make a "skinnable" app and I don't really know what that means. I googled like crazy and I didn't found a clear answer or an example.

一位客户要求我制作一个“可换肤”的应用程序,但我真的不知道这意味着什么。我疯狂地搜索,但没有找到明确的答案或示例。

If anyone has a clue about this, any tip would be appreciated.

如果有人对此有任何线索,将不胜感激。

Thanks.

谢谢。

回答by Luke

Generally this means the app will allow the user to choose different looks for the UI, each of which will have a different color scheme, feel, etc.

一般来说,这意味着应用程序将允许用户为 UI 选择不同的外观,每个外观都有不同的配色方案、感觉等。

回答by Nathan Denlinger

What I actually did with my project. I decided to use multiple storyboards to give me greater control over the entire UI and UX of each theme. I programmatically link them all together via a master storyboard that links them all together. That's what I did, and it works very very well. Performance is great, while still maintaining high level of fine grain control over each theme. You can even keep your Header and Implementation files the same for individual view controllers, just so as you keep the names the same on the storyboard.

我实际上对我的项目做了什么。我决定使用多个故事板来让我更好地控制每个主题的整个 UI 和 UX。我通过将它们链接在一起的主故事板以编程方式将它们链接在一起。这就是我所做的,而且效果非常好。性能很棒,同时仍然保持对每个主题的高水平细粒度控制。您甚至可以为各个视图控制器保持 Header 和 Implementation 文件相同,就像在故事板上保持名称相同一样。

So for instance, one of my apps that I'm working on called Jam-mout (A music player) has multiple high quality themes. (Image attached). Each theme has it's own storyboard.

例如,我正在开发的一个名为 Jam-mout(音乐播放器)的应用程序具有多个高质量主题。(附图片)。每个主题都有自己的故事板。

回答by damian

For iPhone apps, where the majority of the GUI design is provided by the operating system, you could do it by setting custom Navigation bar background images, custom button graphics, and different fonts/sizes/weights and whitespace. Make sure you're working with a designer who's familiar with the iPhone GUI (if you're not working closely with a designer this is going to be a nightmare).

对于大部分 GUI 设计由操作系统提供的 iPhone 应用程序,您可以通过设置自定义导航栏背景图像、自定义按钮图形以及不同的字体/大小/粗细和空白来实现。确保您正在与熟悉 iPhone GUI 的设计师合作(如果您不与设计师密切合作,这将是一场噩梦)。

I recently put together an app for a client who wanted a heavily customised GUI: http://itunes.apple.com/us/app/gogoparis/id428497937?mt=8. A 'skinnable' app would have several sets like this, so the user could choose between several different overall styles. (I hope your client has an enormous design budget!)

我最近为想要高度定制的 GUI 的客户组合了一个应用程序:http: //itunes.apple.com/us/app/gogoparis/id428497937?mt=8。一个“可换肤”应用程序将有多个这样的集合,因此用户可以在几种不同的整体样式之间进行选择。(我希望您的客户有庞大的设计预算!)

回答by justin

my post here should help you get started:

我在这里的帖子应该可以帮助您入门:

What is the recommended method of styling an iOS app?

推荐的 iOS 应用样式的方法是什么?

if you need live theme changes, each theme in this example could post notifications when the user selects another theme (or skin) - then you can update either the theme instance itself.

如果您需要实时主题更改,则此示例中的每个主题都可以在用户选择另一个主题(或皮肤)时发布通知 - 然后您可以更新主题实例本身。

alternatively, you can create identifiers for themes which are mapped (NSCFDictionary) to a central theme factory. an example identifier for a specific view for use with the theme factory could be a string MONImageSelectorTableCellThemeIdentifier.

或者,您可以为映射 (NSCFDictionary) 到中央主题工厂的主题创建标识符。与主题工厂一起使用的特定视图的示例标识符可以是 string MONImageSelectorTableCellThemeIdentifier

an example manager/factory which handles all theme loading and vends references to themes:

处理所有主题加载并提供对主题的引用的示例管理器/工厂:

@interface MONThemeManager : NSObject

//...

- (MONTheme *)themeForCurrentlySelectedSkinForViewWithIdentifier:(NSString *)identifier;

//...

@end

beyond that, it's hard to answer your question in more detail without knowing your requirements. the implementation of skinning an app can range from very simple to very very complex. good luck.

除此之外,在不了解您的要求的情况下很难更详细地回答您的问题。应用程序皮肤的实现可以从非常简单到非常复杂。祝你好运。

回答by NWCoder

Already some good answer here, but I'd add that if you use a ui toolkit such as Three20you can skin everything using CSS as you might for web pages.

这里已经有一些很好的答案,但我要补充一点,如果您使用诸如Three20 之类的 ui 工具包, 您可以像处理网页一样使用 CSS 为所有内容设置外观。

回答by Adrian Sluyters

I do realise this is an old post, but I thought I'd share my penny on the matter:)

我确实意识到这是一个旧帖子,但我想我会在这件事上分享我的一分钱:)

To make any Cocoa app skinnable you need you think of 3 aspects of the app:

要使任何 Cocoa 应用程序可换肤,您需要考虑应用程序的 3 个方面:

1) Uniformity: By this I mean that on all windows, views (including buttons, text inputs etc...) you want to have a 'standard' that will apply throughout the app. This is the first thing you need to look at. Although iOS and OS X alike already have 'themes' as to put it i.e. Apples default way of shading and laying things out, you can override these (refer to the individual view / window etc... documentation.

1) 统一性:我的意思是,在所有窗口、视图(包括按钮、文本输入等)上,您都希望拥有一个适用于整个应用程序的“标准”。这是您需要查看的第一件事。尽管 iOS 和 OS X 都已经有了“主题”,即苹果默认的着色和布局方式,但您可以覆盖这些(请参阅个人视图/窗口等...文档。

2) Performance: With skinning etc... performance is always an issue when it comes to writing your own drawRect etc... methods. The code apple have in place for the 'default' is already optimised, so you need to keep a close eye on the performance of the app whilst you are doing this. Good examples are: Do I use an image with a gradient, or do I use NSGradient? Both of which have performance issues when it comes to rendering them, but it's a question of which is the better of the two

2) 性能:使用蒙皮等...在编写您自己的 drawRect 等...方法时,性能始终是一个问题。苹果为“默认”设置的代码已经过优化,因此您在执行此操作时需要密切关注应用程序的性能。很好的例子是:我使用带有渐变的图像,还是使用 NSGradient?两者在渲染时都存在性能问题,但问题在于两者中哪个更好

3) userDefaults: This is generally the area where you'd be getting your 'skin settings' pulled from. userDefaults is basically where you store all of the information which you generally set in a preference pane.

3) userDefaults:这通常是您要从中提取“皮肤设置”的区域。userDefaults 基本上是您存储通常在首选项窗格中设置的所有信息的地方。

If I were you I'd look into the class reference of it:

如果我是你,我会研究它的类参考:

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSUserDefaults_Class/

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSUserDefaults_Class/

Furthermore, here's a nifty example of using userDefaults:

此外,这是一个使用 userDefaults 的漂亮示例:

http://mobile.tutsplus.com/tutorials/iphone/nsuserdefaults_iphone-sdk/

http://mobile.tutsplus.com/tutorials/iphone/nsuserdefaults_iphone-sdk/

Hope this helps!

希望这可以帮助!