{"id":18270372,"url":"https://github.com/rnystrom/RNThemeManager","last_synced_at":"2025-04-05T01:30:32.731Z","repository":{"id":6790060,"uuid":"8037384","full_name":"rnystrom/RNThemeManager","owner":"rnystrom","description":"Easily manage themes and respond to theme changes by updating views in real time.","archived":false,"fork":false,"pushed_at":"2016-01-02T17:37:25.000Z","size":777,"stargazers_count":323,"open_issues_count":2,"forks_count":48,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-03-23T13:42:14.487Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rnystrom.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-02-05T20:31:38.000Z","updated_at":"2025-01-28T19:56:04.000Z","dependencies_parsed_at":"2022-09-05T05:00:47.454Z","dependency_job_id":null,"html_url":"https://github.com/rnystrom/RNThemeManager","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rnystrom%2FRNThemeManager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rnystrom%2FRNThemeManager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rnystrom%2FRNThemeManager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rnystrom%2FRNThemeManager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rnystrom","download_url":"https://codeload.github.com/rnystrom/RNThemeManager/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246798133,"owners_count":20835718,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-05T11:38:32.940Z","updated_at":"2025-04-05T01:30:32.354Z","avatar_url":"https://github.com/rnystrom.png","language":"Objective-C","readme":"RNThemeManager\n=====\n\nThis small utility makes theming your iOS apps clean and simple. It was originally created so that I could have themable NIBs that utilized notifications to update view properties such as fonts and colors. I pushed beyond NIB support so that however you create your views, it will respond to your themes.\n\nI also wanted to create a library that could be used by people that aren't app developers, i.e. designers. As long as someone has Xcode installed, they can easily make edits to your theme Plists without slowing down the development process.\n\n## Installation\n\n#### Cocoapods\n\nThe preferred method of installation is with [Cocoapods](http://cocoapods.org). The latest version is 0.1.0.\n\nIf you do not wish to use Cocoapods (and you really should), you can manually install RNThemeManager by just dragging and dropping all of the source files into your project. There are no framework dependencies.\n\n## Setup\n\nThe only required setup is that you create a Plist file named \u003ccode\u003edefault.plist\u003c/code\u003e. The root of this file should be a dictionary. Each key represents the name of an attribute. Values should be either the name of a font, the size of a font, or a hex color code.\n\n## Fonts\n\nView a list, and examples, of fonts included with iOS 6 [here](http://iosfonts.com).\n\nYou can include custom fonts in your project and use them in your themes just as you would with a system font. For instructions on importing custom fonts see this [Stackoverflow answer](http://stackoverflow.com/a/2616101/940936).\n\n#### Font Sizes\n\nRNThemeManager automatically builds your font and size based on the keyword for the font. Each font name must be accompanied by a font size key that is the **font name suffixed with \"Size\"**. For example:\n\n``` objective-c\nheaderFont : ArialRoundedMTBold\nheaderFontSize : 24\n```\n\nThen when assigning a font key to a label (or any other view with text), the size will be automatically assigned.\n\n``` objective-c\n- (UIFont *)fontForKey:(NSString*)key;\n```\n\n## Colors\n\nColors are fairly simple. Just use a hexidecimal color code for the key value. There is no need to prefix with \u003ccode\u003e#\u003c/code\u003e.\n\n``` objective-c\n- (UIImage *)imageForKey:(NSString *)key;\n```\n\n## Images\n\nJust like \u003ccode\u003e[UIImage imageNamed:@\"name\"]\u003c/code\u003e, simply assign the image name of your asset as the value for an image key.\n\n``` objective-c\n- (UIImage *)imageForKey:(NSString *)key;\n```\n\n## Inheriting theme values\n\nIf you would like to use a single value as multiple keys you may, just set the value of a key to another key.\n\n```\nheaderFont : Helvetica\nheaderFontSize : 20\nbackgroundColor : ffffff\nredColor : d81417\nheaderColor : backgroundColor\nheaderButtonColor : headerColor\ncellHeaderFontSize : headerFontSize\nbuttonBackgroundColor : redColor\n// etc\n```\n\n## Theming with NIBs\n\nThere are three steps to applying themes within NIBs. All of this is done in the Identity Inspector (⌥ ⌘ 3).\n\n1. Class a view as a respective \u003ccode\u003eRNTheme*\u003c/code\u003e subclass. You can subclass any of the \u003ccode\u003eRNTheme*\u003c/code\u003e classes as well.\n2. Setup keyPath keys that match the \u003ccode\u003eRNTheme*\u003c/code\u003e subclass.\n3. Set the values to said keyPaths to the keys you defined in your theme plists.\n\nSorry if that's a little confusing. Here are some pictures.\n\n#### default.plist\n\n\u003cimg src=\"https://raw.github.com/rnystrom/RNThemeManager/master/images/plist.png\" /\u003e\n\n#### RNThemeButton.h\n\n``` objective-c\n@interface RNThemeButton : UIButton\n\u003cRNThemeUpdateProtocol\u003e\n\n// available theme keys\n@property (nonatomic, strong) NSString *backgroundImageKey;\n@property (nonatomic, strong) NSString *backgroundColorKey;\n@property (nonatomic, strong) NSString *fontKey;\n@property (nonatomic, strong) NSString *textColorKey;\n@property (nonatomic, strong) NSString *highlightedTextColorKey;\n\n@end\n```\n\n#### MainStoryboard.storyboard\n\n\u003cimg src=\"https://raw.github.com/rnystrom/RNThemeManager/master/images/keypaths.png\" /\u003e\n\n## Theming with Code\n\n``` objective-c\n// optional: conform your View or ViewController to provided protocol\n@interface MYViewController : UIViewController\n\u003cRNThemeUpdateProtocol\u003e\n\n// in -viewDidLoad (remember to removeObserver in -dealloc)\n[[NSNotificationCenter defaultCenter] addObserver:self action:@selector(applyTheme) withObject:nil];\n\n// in -viewWillAppear (or where you do your layout bits)\n[self applyTheme];\n\n- (void)applyTheme {\n    // these objects do _not_ need to be RNTheme* classes/subclasses\n    self.view.backgroundColor = [[RNThemeManager sharedManager] colorForKey:@\"backgroundColor\"];\n    self.textField.font = [[RNThemeManager sharedManager] fontForKey:@\"textFieldFont\"];\n\n    // example of custom theming\n    self.textField.layer.cornerRadius = [RNThemeManager sharedManager].styles[@\"cornerRadius\"].floatValue;\n}\n```\n\nNow whenever your theme file is changed the ViewController will automatically restyle your views based on your theme's setup.\n\n## Using Multiple Themes\n\nTo change the active theme, just call the following method:\n\n``` objective-c\n[[RNThemeManager sharedManager] changeTheme:@\"lowcontrast\"];\n```\n\nJust make sure you have a plist with whatever theme name you provide.\n\n## Updating Views\n\nAll \u003ccode\u003eRNTheme*\u003c/code\u003e subclasses subscribe to notifications when a theme is changed and conform to a custom protocol (that only exists for semantics) called \u003ccode\u003eRNThemeUpdateProtocol\u003c/code\u003e.\n\nIf you wish not to use any of the \u003ccode\u003eRNTheme*\u003c/code\u003e views (and you certainly do not need to), you can update your views or even view controllers by listening for the following notification:\n\n``` objective-c\nRNThemeManagerDidChangeThemes\n```\n\nSee the above example of [Theming With Code](https://github.com/rnystrom/RNThemeManager#theming-with-code) for how to implement.\n\n## Contact\n\n* [@nystrorm](https://twitter.com/_ryannystrom) on Twitter\n* [@rnystrom](https://github.com/rnystrom) on Github\n* \u003ca href=\"mailTo:rnystrom@whoisryannystrom.com\"\u003ernystrom [at] whoisryannystrom [dot] com\u003c/a\u003e\n\n## License\n\nRNThemeManager is a work from Ryan Nystrom under the MIT license. See the [license doc](https://github.com/rnystrom/RNThemeManager/blob/master/LICENSE) for details.\n","funding_links":[],"categories":["etc"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frnystrom%2FRNThemeManager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frnystrom%2FRNThemeManager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frnystrom%2FRNThemeManager/lists"}