How to create a theme based application? - ios

I know similar question is already asked, but didn't get a satisfactory answer. So i am adding this question again .
Based on user selection in iphone application , i need to change the look and feel of the application (color font background images etc ). Is there any standard way to achieve this ?
one possible solution can be duplicating xib files for each theme and loading it based on selection. Is this a good approach? mainly because wiring the outlets and actions for xib copies sounds to be a redundant task.
I would like to see expert suggestion for this doubt.
Thanks for any help in advance.
-mia

For the non-XIB route
Color: iOS 5 exposes the new appearance APIs. Most UI elements have the option if setting a tintColor or a backgroundColor. Rarely, even a background image.
Font: Was always able to change, but you couldn't animate it.
Background image: Your main UIView should have the option for a background image, or if that fails, a background color with a pattern image.

As CodaFI said, if you are using iOS 5 or greater, you already have a theming feature. It works like this:
Add the protocol <IAppearanceContainer> to the class.
Decorate the property you intend to change with UI_APPEARANCE_SELECTOR. Example:
#interface UINavigationBar : ... <IAppearanceContainer>
#property(nonatomic,retain) UIColor *tintColor UI_APPEARANCE_SELECTOR;
#end
Change the color for all instances of the class:
[[UINavigationBar appearance] setTintColor:[UIColor redColor]];
The example above is the UINavigationBar, but it would work with any custom class. To see the objects already supported in iOS 6.1, check the documentation or run the following commands:
cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/System/Library/Frameworks/UIKit.framework/Headers
grep -H UI_APPEARANCE_SELECTOR ./* | sed 's/ __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0) UI_APPEARANCE_SELECTOR;//'
Let's say you want modular themes:
Write a big plist file with all the fonts, colors, music, and what not. Each of these files will be a theme.
Read the file through a singleton and set the values with lines like [x appearance] setWhatever:<plist value>] for each theme-able element.
If you have instances of the same element that need to display different elements, get those images through the singleton.
That is more or less the tip from Amit Vyawahare. I said plist instead xml because they are easier to read. Don't duplicate the NIBs unless you really have to.

Best way to implement theme based application IOS application (not using ~xib route). you should create a build.xml file which will content all the pieces of themes. You should keep your layout same and you can change images, style, fonts, lang, views, in that layout according to users pref. By doing this you are not duplicating any code and you will achieve best performances from your application.

Related

Is there a colors.xml equivalent for IOS storyboards?

Right now I am setting all my colors by hand when editing in the storyboard. This is rather unfortunate as any future changes to hex codes will mean that I need to manually change each colored element.
I was wondering if there was a way to abstract all color configurations into a colors.xml android-esque file for IOS
It's only available in iOS 11 and later, but you can make a color set in your .xcassets file and reference that color in your storyboards and your code, as described in this blog post

How to style GCKUIMiniMediaControlsViewController in iOS?

I'm upgrading current Cast SDK to V3 and want to use build-in UI components and remove deprecated functions.
Currently, the GCKUIMiniMediaControlsViewController has a white/light theme but I'd like to change it to a darker theme. However, I couldn't find any function/propert/protocol that I can use to change the style. The document Add Advanced Cast v3 Features to your iOS App says:
The Cast framework widgets supports the Apple UIAppearance Protocol in
UIKit to change the appearance of the widgets across your app, such as
the position or border of a button. Use this protocol to style the
Cast framework widgets to match an existing apps styling.
This makes me feel like I can change the appearance but I'm not quite sure what does The Cast framework widgets supports the Apple UIAppearance Protocol in UIKit mean :(
I also find a previous question which also related to Cast SDK's UI component. How can I get access to Introductory Overlay?
Can anyone help me how to change the style for GCKUIMiniMediaControlsViewController?
Cast SDK v3 for iOS introduced GCKUIStyle.
This makes styling of all cast views very easy (which includes mini controller, expanded controller, etc). As it contains pretty much all properties for customization.
For GCKUIMiniMediaControlsViewController specifically
GCKUIStyle *castStyle = [GCKUIStyle sharedInstance];
// customize Mini Controller
GCKUIStyleAttributesMiniController *miniCtrlStyle = [[[castStyle castViews] mediaControl] miniController];
[miniCtrlStyle setBackgroundColor:backColor];
[miniCtrlStyle setIconTintColor:[UIColor whiteColor]];
[miniCtrlStyle setHeadingTextColor:[UIColor whiteColor]];
[castStyle applyStyle];
https://developer.apple.com/reference/uikit/uiappearance
For example if you want to change the background color of every UILabel that is contained in GCKUIExpandedMediaControlsViewController.
ex in Swift:
UILabel.appearance(whenContainedInInstancesOf:[GCKUIExpandedMediaControlsViewController.self]).backgroundColor = URColors.URStrawberryRed
You need to follow Apple's instructions on using the UIAppearance protocol. Note that any changes you make to the styling will happen across the entire app.

Can I use the default UIBarButton icons provided by Apple in other assets of my app?

Like in UIButton or a UIImageView etc..
If so how do I do that using the StoryBoard or in a Xib
I am able to use the default icons inside UIBarButton items but cannot look them up in normal buttons . A solution using Storyboard would be really nice
In order to use them you need to extract them using a handy little app called (fittingly enough) iOS Artwork Extractor. I use it all the time when I want to mimic iOS system behaviours.
Download the Xcode project at:
https://github.com/0xced/iOS-Artwork-Extractor
Or another way:
The Other.artwork file is in /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/System/Library/Frameworks/UIKit.framework/ (you need the SDK).
Use the "iPhoneShop-1.3.jar" program -- available currently here to extract all of the images into a directory.
java -jar iPhoneShop-1.3.jar ARTWORK Other.artwork EXPORT Other
No you cannot use UIBarButtonItem on other as subview like UIButton. UIBarButtonItem can only over UINavigationBar.

iOS app that change whole app color theme (background, uibutton, icons color...) base on user selection

I have a requirement to make application that has color theme base on user selection
User selects an color at begining (in 8 available colors), that color will be applied for the whole app (background color, buttons, icons ....)
If I create images for each color, the app will have lots of images and can be heavy in size, and that approach not seem to be good one.
I tried to import images with 1 color and then change images color according to user-selected color, but got problem with some controls like slider, and also the image that is changed does not look good as photoshop one
Would u plz help me with good approach for this?
Make all the images one color (black probably), then let the user pick a color and save it to user defaults. Link all items that need to get the theme to the color from the user defaults. Then use the tintColor property of the UIImageView to themefy your app.
Method to tint any UIImageView:
- (void)tintImageView:(UIImageView *)imageView withTint:(UIColor *)tintColor
{
imageView.image = [imageView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
[imageView setTintColor:tintColor];
}
Example use to tint Button:
[self tintImageView:self.button.imageView withTint:[UIColor blueColor]];
Example use to tint UIImageView:
[self tintImageView:self.imageView withTint:[UIColor blueColor]];
If you're using iOS7 you can take advantage of the tintColor property.
For images you need to be sure they are created using template option.
Please checkout this clear tutorial that will guide you to apply themes to different kind of controls in your app: Theming iOS Applications
You could probably be interested in trying Pixate Freestyle too, which basically allow you to apply styles like css does to your iOS app, that a pretty cool tool and I've found it very easy to use too.

How to include skins in ios app

I developed a new iPad calculator and am working on an update for it that has a settings option where you can change the app's skin. Currently, I am using different UIViewControllers for that, but it is not the best solution.
To build on #MJN's answer, once you have selected a skin/theme class, you can easily apply it across your app using UIAppearance, which lets you set styles for all instances of common UIKit classes like UIButton, UIBarButtonItem, UINavigationBar, etc.
You can make an AppSkinProtocol that has methods like the following
- (NSString*)skinIdentifier;
- (UIColor*)highlightedButtonColor;
- (UIImage*)successfulDownloadAlertBackground;
Then make subclasses of NSObject that conform to your AppSkinProtocol.
You can then make a AppSkinManager to save the selected skin to NSUserDefaults. When the app launches load the skin with the identifier matching the string saved to defaults.

Resources