├── Tests ├── logo.jpg ├── TViewStyling.h └── TViewStyling.m ├── Samples ├── Theme Explorer │ ├── images │ │ ├── Icon.png │ │ ├── 12-6AM.png │ │ ├── 12-6PM.png │ │ ├── 6-12AM.png │ │ ├── 6-12PM.png │ │ ├── scene1.jpg │ │ ├── scene2.jpg │ │ ├── scene3.jpg │ │ ├── scene4.jpg │ │ ├── scene5.jpg │ │ ├── Default.png │ │ ├── Icon-72.png │ │ ├── Icon@2x.png │ │ ├── iTunesArtwork │ │ ├── Icon-Small.png │ │ ├── blueButton.png │ │ ├── orangeslide.png │ │ ├── slider_ball.png │ │ ├── whiteButton.png │ │ ├── yellowslide.png │ │ ├── Icon-Small-50.png │ │ ├── Icon-Small@2x.png │ │ ├── segment_check.png │ │ ├── segment_search.png │ │ ├── segment_tools.png │ │ └── UIButton_custom.png │ ├── main.m │ ├── Theme Explorer-Prefix.pch │ ├── Theme Explorer-Info.plist │ ├── en.lproj │ │ ├── Localizable.strings │ │ ├── WebViewController.xib │ │ ├── SearchBarController.xib │ │ ├── SegmentViewController.xib │ │ ├── AlertsViewController.xib │ │ ├── TextViewController.xib │ │ ├── ButtonsViewController.xib │ │ ├── ControlsViewController.xib │ │ └── TextFieldController.xib │ ├── ThemeAppDelegate.h │ ├── SegmentViewController.h │ ├── MainViewController.h │ ├── TextViewController.h │ ├── Picker │ │ ├── CustomPickerDataSource.h │ │ ├── CustomView.h │ │ ├── CustomView.m │ │ └── CustomPickerDataSource.m │ ├── WebViewController.h │ ├── SearchBarController.h │ ├── Constants.h │ ├── AlertsViewController.h │ ├── ImagesViewController.h │ ├── TransitionViewController.h │ ├── TextFieldController.h │ ├── ControlsViewController.h │ ├── ButtonsViewController.h │ ├── styles.html │ ├── ToolbarViewController.h │ ├── PickerViewController.h │ ├── SearchBarController.m │ ├── ImagesViewController.m │ ├── ThemeAppDelegate.m │ ├── TransitionViewController.m │ ├── WebViewController.m │ ├── TextViewController.m │ └── SegmentViewController.m └── GAJavaScript │ └── README.txt ├── .gitignore ├── Classes ├── UIControl+GAViewStyling.h ├── UIView+GAViewStyling.h ├── GAViewStyling.h ├── UIControl+GAViewStyling.m └── GAViewStyling.m └── README.markdown /Tests/logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newyankeecodeshop/GAViewStyling/HEAD/Tests/logo.jpg -------------------------------------------------------------------------------- /Samples/Theme Explorer/images/Icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newyankeecodeshop/GAViewStyling/HEAD/Samples/Theme Explorer/images/Icon.png -------------------------------------------------------------------------------- /Samples/Theme Explorer/images/12-6AM.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newyankeecodeshop/GAViewStyling/HEAD/Samples/Theme Explorer/images/12-6AM.png -------------------------------------------------------------------------------- /Samples/Theme Explorer/images/12-6PM.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newyankeecodeshop/GAViewStyling/HEAD/Samples/Theme Explorer/images/12-6PM.png -------------------------------------------------------------------------------- /Samples/Theme Explorer/images/6-12AM.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newyankeecodeshop/GAViewStyling/HEAD/Samples/Theme Explorer/images/6-12AM.png -------------------------------------------------------------------------------- /Samples/Theme Explorer/images/6-12PM.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newyankeecodeshop/GAViewStyling/HEAD/Samples/Theme Explorer/images/6-12PM.png -------------------------------------------------------------------------------- /Samples/Theme Explorer/images/scene1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newyankeecodeshop/GAViewStyling/HEAD/Samples/Theme Explorer/images/scene1.jpg -------------------------------------------------------------------------------- /Samples/Theme Explorer/images/scene2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newyankeecodeshop/GAViewStyling/HEAD/Samples/Theme Explorer/images/scene2.jpg -------------------------------------------------------------------------------- /Samples/Theme Explorer/images/scene3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newyankeecodeshop/GAViewStyling/HEAD/Samples/Theme Explorer/images/scene3.jpg -------------------------------------------------------------------------------- /Samples/Theme Explorer/images/scene4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newyankeecodeshop/GAViewStyling/HEAD/Samples/Theme Explorer/images/scene4.jpg -------------------------------------------------------------------------------- /Samples/Theme Explorer/images/scene5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newyankeecodeshop/GAViewStyling/HEAD/Samples/Theme Explorer/images/scene5.jpg -------------------------------------------------------------------------------- /Samples/Theme Explorer/images/Default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newyankeecodeshop/GAViewStyling/HEAD/Samples/Theme Explorer/images/Default.png -------------------------------------------------------------------------------- /Samples/Theme Explorer/images/Icon-72.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newyankeecodeshop/GAViewStyling/HEAD/Samples/Theme Explorer/images/Icon-72.png -------------------------------------------------------------------------------- /Samples/Theme Explorer/images/Icon@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newyankeecodeshop/GAViewStyling/HEAD/Samples/Theme Explorer/images/Icon@2x.png -------------------------------------------------------------------------------- /Samples/Theme Explorer/images/iTunesArtwork: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newyankeecodeshop/GAViewStyling/HEAD/Samples/Theme Explorer/images/iTunesArtwork -------------------------------------------------------------------------------- /Samples/Theme Explorer/images/Icon-Small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newyankeecodeshop/GAViewStyling/HEAD/Samples/Theme Explorer/images/Icon-Small.png -------------------------------------------------------------------------------- /Samples/Theme Explorer/images/blueButton.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newyankeecodeshop/GAViewStyling/HEAD/Samples/Theme Explorer/images/blueButton.png -------------------------------------------------------------------------------- /Samples/Theme Explorer/images/orangeslide.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newyankeecodeshop/GAViewStyling/HEAD/Samples/Theme Explorer/images/orangeslide.png -------------------------------------------------------------------------------- /Samples/Theme Explorer/images/slider_ball.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newyankeecodeshop/GAViewStyling/HEAD/Samples/Theme Explorer/images/slider_ball.png -------------------------------------------------------------------------------- /Samples/Theme Explorer/images/whiteButton.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newyankeecodeshop/GAViewStyling/HEAD/Samples/Theme Explorer/images/whiteButton.png -------------------------------------------------------------------------------- /Samples/Theme Explorer/images/yellowslide.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newyankeecodeshop/GAViewStyling/HEAD/Samples/Theme Explorer/images/yellowslide.png -------------------------------------------------------------------------------- /Samples/Theme Explorer/images/Icon-Small-50.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newyankeecodeshop/GAViewStyling/HEAD/Samples/Theme Explorer/images/Icon-Small-50.png -------------------------------------------------------------------------------- /Samples/Theme Explorer/images/Icon-Small@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newyankeecodeshop/GAViewStyling/HEAD/Samples/Theme Explorer/images/Icon-Small@2x.png -------------------------------------------------------------------------------- /Samples/Theme Explorer/images/segment_check.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newyankeecodeshop/GAViewStyling/HEAD/Samples/Theme Explorer/images/segment_check.png -------------------------------------------------------------------------------- /Samples/Theme Explorer/images/segment_search.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newyankeecodeshop/GAViewStyling/HEAD/Samples/Theme Explorer/images/segment_search.png -------------------------------------------------------------------------------- /Samples/Theme Explorer/images/segment_tools.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newyankeecodeshop/GAViewStyling/HEAD/Samples/Theme Explorer/images/segment_tools.png -------------------------------------------------------------------------------- /Samples/Theme Explorer/images/UIButton_custom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newyankeecodeshop/GAViewStyling/HEAD/Samples/Theme Explorer/images/UIButton_custom.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.mode1 3 | *.mode1v3 4 | *.mode2v3 5 | *.perspective 6 | *.perspectivev3 7 | *.pbxuser 8 | *.xcuserdatad 9 | *.xcworkspacedata 10 | ThirdParty/GHUnit* 11 | Samples/GAJavaScript/Classes 12 | Samples/GAJavaScript/ga-js-runtime.js 13 | -------------------------------------------------------------------------------- /Samples/GAJavaScript/README.txt: -------------------------------------------------------------------------------- 1 | This is where the GAJavaScript files need to go. You can get them from https://github.com/newyankeecodeshop/GAJavaScript. You can clone the repository as this directory, or simply copy the GAJavaScript/Classes and GAJavaScript/ga-js-runtime.js files into this folder. -------------------------------------------------------------------------------- /Samples/Theme Explorer/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // Theme Explorer 4 | // 5 | // Created by Andrew Goodale on 6/23/11. 6 | // Copyright 2011 Wingspan Technology, Inc. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, char *argv[]) 12 | { 13 | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 14 | int retVal = UIApplicationMain(argc, argv, nil, nil); 15 | [pool release]; 16 | return retVal; 17 | } 18 | -------------------------------------------------------------------------------- /Samples/Theme Explorer/Theme Explorer-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'Theme Explorer' target in the 'Theme Explorer' project 3 | // 4 | 5 | #import 6 | 7 | #ifndef __IPHONE_3_0 8 | #warning "This project uses features only available in iPhone SDK 3.0 and later." 9 | #endif 10 | 11 | #ifdef __OBJC__ 12 | #import 13 | #import 14 | #import 15 | #endif 16 | 17 | #include "GADebugMacros.h" -------------------------------------------------------------------------------- /Samples/Theme Explorer/Theme Explorer-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIconFile 12 | 13 | CFBundleIdentifier 14 | com.newyankeecodeshop.${PRODUCT_NAME:rfc1034identifier} 15 | CFBundleInfoDictionaryVersion 16 | 6.0 17 | CFBundleName 18 | ${PRODUCT_NAME} 19 | CFBundlePackageType 20 | APPL 21 | CFBundleShortVersionString 22 | 1.0 23 | CFBundleSignature 24 | ???? 25 | CFBundleVersion 26 | 1.0 27 | LSRequiresIPhoneOS 28 | 29 | NSMainNibFile 30 | MainWindow 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /Samples/Theme Explorer/en.lproj/Localizable.strings: -------------------------------------------------------------------------------- 1 | "ButtonsTitle" = "Buttons"; 2 | "ButtonsExplain" = "Various uses of UIButton"; 3 | "ControlsTitle" = "Controls"; 4 | "ControlsExplain" = "Various uses of UIControl"; 5 | "TextFieldTitle" = "TextFields"; 6 | "TextFieldExplain" = "Uses of UITextField"; 7 | "SearchBarTitle" = "SearchBar"; 8 | "SearchBarExplain" = "Use of UISearchBar"; 9 | "TextViewTitle" = "TextView"; 10 | "TextViewExplain" = "Use of UITextField"; 11 | "SegmentTitle" = "Segment"; 12 | "SegmentExplain" = "Various uses of UISegmentedControl"; 13 | "ToolbarTitle" = "Toolbar"; 14 | "ToolbarExplain" = "Uses of UIToolbar"; 15 | "PickerTitle" = "Pickers"; 16 | "PickerExplain" = "Uses of UIDatePicker, UIPickerView"; 17 | "ImagesTitle" = "Images"; 18 | "ImagesExplain" = "Use of UIImageView"; 19 | "WebTitle" = "Web"; 20 | "WebExplain" = "Use of UIWebView"; 21 | "AlertTitle" = "Alerts"; 22 | "AlertExplain" = "Various uses of UIAlertView, UIActionSheet"; 23 | "TransitionsTitle" = "Transitions"; 24 | "TransitionsExplain" = "Shows UIViewAnimationTransitions"; 25 | 26 | "StartTitle" = "Start"; 27 | "StopTitle" = "Stop"; 28 | 29 | "StyleTitle" = "Style"; 30 | "ChooseStyleTitle" = "Choose a UIBarStyle for the bottom toolbar:"; 31 | 32 | "FlipTitle" = "Flip Image"; 33 | "CurlTitle" = "Curl Image"; 34 | 35 | "LeftView" = "Left View:"; 36 | 37 | "ArrowButton" = "Right pointing arrow"; 38 | "MoreInfoButton" = "More info"; 39 | "AddContactButton" = "Add contact"; 40 | "StandardSwitch" = "Standard"; 41 | "CustomSlider" = "Custom"; 42 | "StandardSlider" = "Standard"; 43 | "RoundedTextField" = "Rounded"; 44 | "SecureTextField" = "Secure"; 45 | "NormalTextField" = "Normal"; 46 | "DurationSlider" = "Duration"; 47 | "URLTextField" = "URL entry"; 48 | "CheckMarkIcon" = "Check"; 49 | "SearchIcon" = "Search"; 50 | "ToolsIcon" = "Tools"; 51 | "TintSwitch" = "Tinted"; 52 | 53 | -------------------------------------------------------------------------------- /Tests/TViewStyling.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Andrew Goodale. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY ANDREW GOODALE "AS IS" AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Andrew Goodale. 27 | */ 28 | 29 | #import 30 | 31 | 32 | @interface TViewStyling : GHTestCase 33 | { 34 | 35 | } 36 | 37 | @end 38 | 39 | #pragma mark - 40 | 41 | @interface MockCSSDeclaration : NSObject 42 | { 43 | @private 44 | NSString* _fontFamily; 45 | NSString* _fontSize; 46 | NSString* _fontWeight; 47 | NSString* _fontStyle; 48 | } 49 | 50 | @property (nonatomic, retain) NSString* fontFamily; 51 | @property (nonatomic, retain) NSString* fontSize; 52 | @property (nonatomic, retain) NSString* fontWeight; 53 | @property (nonatomic, retain) NSString* fontStyle; 54 | 55 | @end -------------------------------------------------------------------------------- /Samples/Theme Explorer/ThemeAppDelegate.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Andrew Goodale. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY ANDREW GOODALE "AS IS" AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Andrew Goodale. 27 | */ 28 | 29 | #import 30 | 31 | @class GAScriptEngine; 32 | 33 | @interface ThemeAppDelegate : NSObject 34 | 35 | { 36 | @private 37 | GAScriptEngine* _scriptEngine; 38 | 39 | BOOL _themeChanged; 40 | } 41 | 42 | @property (nonatomic, retain) IBOutlet UIWindow *window; 43 | @property (nonatomic, retain) IBOutlet UINavigationController *navigationController; 44 | 45 | @property (nonatomic, retain) GAScriptEngine* scriptEngine; 46 | 47 | + (ThemeAppDelegate *)sharedAppDelegate; 48 | 49 | - (IBAction)changeTheme:(id)sender; 50 | 51 | - (void)applyStylesToView:(UIView *)view; 52 | 53 | @end 54 | -------------------------------------------------------------------------------- /Classes/UIControl+GAViewStyling.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Andrew Goodale. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY ANDREW GOODALE "AS IS" AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Andrew Goodale. 27 | */ 28 | 29 | #import 30 | 31 | @interface UIButton (GAViewStyling) 32 | 33 | /** 34 | * Drive the styling of the titleLabel 35 | */ 36 | - (void)applyComputedStyles:(id)cssDeclaration; 37 | 38 | @end 39 | 40 | #pragma mark - 41 | 42 | @interface UISegmentedControl (GAViewStyling) 43 | 44 | /** 45 | * This implementation sets the following view properties: 46 | * tintColor - "color" 47 | */ 48 | - (void)applyComputedStyles:(id)cssDeclaration; 49 | 50 | @end 51 | 52 | #pragma mark - 53 | 54 | @interface UITextField (GAViewStyling) 55 | 56 | /** 57 | * This implementation sets the following view properties: 58 | * font - "font-family, font-size, font-style, font-weight" 59 | * textColor - "color" 60 | * textAlignment - "text-align" 61 | */ 62 | - (void)applyComputedStyles:(id)cssDeclaration; 63 | 64 | @end 65 | 66 | -------------------------------------------------------------------------------- /Samples/Theme Explorer/SegmentViewController.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: SegmentViewController.h 3 | Abstract: The view controller for hosting the UISegmentedControl features of this sample. 4 | Version: 2.9 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2011 Apple Inc. All Rights Reserved. 45 | 46 | */ 47 | 48 | #import 49 | 50 | @interface SegmentViewController : UIViewController 51 | { } 52 | 53 | @end 54 | -------------------------------------------------------------------------------- /Samples/Theme Explorer/MainViewController.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: MainViewController.h 3 | Abstract: The application's main view controller (front page). 4 | Version: 2.9 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2011 Apple Inc. All Rights Reserved. 45 | 46 | */ 47 | 48 | #import 49 | 50 | @interface MainViewController : UITableViewController 51 | { 52 | NSMutableArray *menuList; 53 | } 54 | 55 | @property (nonatomic, retain) NSMutableArray *menuList; 56 | 57 | @end 58 | -------------------------------------------------------------------------------- /Samples/Theme Explorer/TextViewController.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: TextViewController.h 3 | Abstract: The view controller for hosting the UITextView features of this sample. 4 | Version: 2.9 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2011 Apple Inc. All Rights Reserved. 45 | 46 | */ 47 | 48 | #import 49 | 50 | @interface TextViewController : UIViewController 51 | { 52 | UITextView *textView; 53 | } 54 | 55 | @property (nonatomic, retain) UITextView *textView; 56 | 57 | @end 58 | -------------------------------------------------------------------------------- /Samples/Theme Explorer/Picker/CustomPickerDataSource.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: CustomPickerDataSource.h 3 | Abstract: The data source for the Custom Picker that displays text and images. 4 | Version: 2.9 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2011 Apple Inc. All Rights Reserved. 45 | 46 | */ 47 | 48 | @interface CustomPickerDataSource : NSObject 49 | { 50 | NSArray *customPickerArray; 51 | } 52 | 53 | @property (nonatomic, retain) NSArray *customPickerArray; 54 | 55 | @end 56 | -------------------------------------------------------------------------------- /Samples/Theme Explorer/WebViewController.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: WebViewController.h 3 | Abstract: The view controller for hosting the UIWebView feature of this sample. 4 | Version: 2.9 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2011 Apple Inc. All Rights Reserved. 45 | 46 | */ 47 | 48 | #import 49 | 50 | @interface WebViewController : UIViewController 51 | { 52 | UIWebView *myWebView; 53 | } 54 | 55 | @property (nonatomic, retain) UIWebView *myWebView; 56 | 57 | @end 58 | -------------------------------------------------------------------------------- /Samples/Theme Explorer/SearchBarController.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: SearchBarController.h 3 | Abstract: The view controller for hosting the UISearchBar features of this sample. 4 | Version: 2.9 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2011 Apple Inc. All Rights Reserved. 45 | 46 | */ 47 | 48 | #import 49 | 50 | @interface SearchBarController : UIViewController 51 | { 52 | UISearchBar *mySearchBar; 53 | } 54 | 55 | @property (nonatomic, retain) UISearchBar *mySearchBar; 56 | 57 | @end 58 | 59 | -------------------------------------------------------------------------------- /Samples/Theme Explorer/Picker/CustomView.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: CustomView.h 3 | Abstract: The custom view holding the image and title for the custom picker. 4 | Version: 2.9 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2011 Apple Inc. All Rights Reserved. 45 | 46 | */ 47 | 48 | #import 49 | 50 | @interface CustomView : UIView 51 | { 52 | NSString *title; 53 | UIImage *image; 54 | } 55 | 56 | @property (nonatomic, retain) NSString *title; 57 | @property (nonatomic, retain) UIImage *image; 58 | 59 | + (CGFloat)viewWidth; 60 | + (CGFloat)viewHeight; 61 | 62 | @end 63 | -------------------------------------------------------------------------------- /Classes/UIView+GAViewStyling.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Andrew Goodale. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY ANDREW GOODALE "AS IS" AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Andrew Goodale. 27 | */ 28 | 29 | #import 30 | 31 | @class GAScriptEngine; 32 | 33 | /** 34 | * Extension to UIViews for driving visual features via CSS. 35 | */ 36 | @interface UIView (GAViewStyling) 37 | 38 | - (NSString *)styleSelector; 39 | 40 | - (void)applyStylesWithScriptEngine:(GAScriptEngine *)engine; 41 | 42 | - (void)applyComputedStyles:(id)cssDeclaration; 43 | 44 | @end 45 | 46 | #pragma mark - Bar styling 47 | 48 | @interface UINavigationBar (GAViewStyling) 49 | 50 | - (void)applyComputedStyles:(id)cssDeclaration; 51 | 52 | @end 53 | 54 | @interface UISearchBar (GAViewStyling) 55 | 56 | - (void)applyComputedStyles:(id)cssDeclaration; 57 | 58 | @end 59 | 60 | @interface UIToolbar (GAViewStyling) 61 | 62 | - (void)applyComputedStyles:(id)cssDeclaration; 63 | 64 | @end 65 | 66 | #pragma mark - Image styling 67 | 68 | @interface UIImageView (GAViewStyling) 69 | 70 | - (void)applyComputedStyles:(id)cssDeclaration; 71 | 72 | @end 73 | 74 | #pragma mark - Text styling 75 | 76 | @interface UILabel (GAViewStyling) 77 | 78 | - (void)applyComputedStyles:(id)cssDeclaration; 79 | 80 | @end 81 | 82 | #pragma mark - Table styling 83 | 84 | @interface UITableView (GAViewStyling) 85 | 86 | - (void)applyComputedStyles:(id)cssDeclaration; 87 | 88 | @end 89 | 90 | @interface UITableViewCell (GAViewStyling) 91 | 92 | - (void)applyComputedStyles:(id)cssDeclaration; 93 | 94 | @end 95 | 96 | 97 | -------------------------------------------------------------------------------- /Samples/Theme Explorer/Constants.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: Constants.h 3 | Abstract: Common constants across source files (screen coordinate consts, etc.) 4 | Version: 2.9 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2011 Apple Inc. All Rights Reserved. 45 | 46 | */ 47 | 48 | // these are the various screen placement constants used across most the UIViewControllers 49 | 50 | // padding for margins 51 | 52 | // for general screen 53 | #define kLeftMargin 20.0 54 | #define kTopMargin 20.0 55 | #define kRightMargin 20.0 56 | #define kTweenMargin 10.0 57 | 58 | #define kTextFieldHeight 30.0 59 | -------------------------------------------------------------------------------- /Samples/Theme Explorer/AlertsViewController.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: AlertsViewController.h 3 | Abstract: The view controller for hosting various kinds of alerts and action sheets 4 | Version: 2.9 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2011 Apple Inc. All Rights Reserved. 45 | 46 | */ 47 | 48 | #import 49 | 50 | @interface AlertsViewController : UITableViewController // for UIActionSheet 52 | { 53 | NSArray *dataSourceArray; 54 | } 55 | 56 | @property (nonatomic, retain) NSArray *dataSourceArray; 57 | 58 | @end 59 | 60 | -------------------------------------------------------------------------------- /Samples/Theme Explorer/ImagesViewController.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: ImagesViewController.h 3 | Abstract: The view controller for hosting the UIImageView containing multiple images. 4 | Version: 2.9 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2011 Apple Inc. All Rights Reserved. 45 | 46 | */ 47 | 48 | #import 49 | 50 | @interface ImagesViewController : UIViewController 51 | { 52 | UIImageView *imageView; 53 | UISlider *slider; 54 | } 55 | 56 | @property (nonatomic, retain) IBOutlet UIImageView *imageView; 57 | @property (nonatomic, retain) IBOutlet UISlider *slider; 58 | 59 | - (IBAction)sliderAction:(id)sender; 60 | 61 | @end 62 | 63 | -------------------------------------------------------------------------------- /Classes/GAViewStyling.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Andrew Goodale. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY ANDREW GOODALE "AS IS" AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Andrew Goodale. 27 | */ 28 | 29 | #import 30 | 31 | 32 | @interface UIColor (GAViewStyling) 33 | 34 | /** 35 | * Returns a UIColor for a "rgb(r, g, b)" string. 36 | */ 37 | + (UIColor *)colorWithCSSColor:(NSString *)cssColor; 38 | 39 | @end 40 | 41 | #pragma mark - 42 | 43 | @interface UIFont (GAViewStyling) 44 | 45 | /** 46 | * Create a font given a CSSDeclaration containing "font-family", "font-size", "font-weight", "font-style". 47 | * Any object that supports these key-values will work. 48 | */ 49 | + (UIFont *)fontWithCSSDeclaration:(id)cssDeclaration; 50 | 51 | @end 52 | 53 | #pragma mark - 54 | 55 | @interface UIImage (GAViewStyling) 56 | 57 | /** 58 | * Create an image from the main resource bundle or a data URL. For example: 59 | * url() 60 | * url(data:image/jpg;base64,) 61 | * 62 | */ 63 | + (UIImage *)imageWithCSSURL:(NSString *)cssUrl; 64 | 65 | @end 66 | 67 | #pragma mark - 68 | 69 | /** 70 | * Returns a size from a CSS declaration that contains two lengths (i.e. "320px 240px"). 71 | * The first length is width (x), the second is height (y). If the string does not have at least two lengths, 72 | * the function returns CGSizeZero. 73 | */ 74 | CGSize GASizeFromCSSLengths (NSString* cssString); 75 | 76 | #pragma mark - 77 | 78 | @interface CAGradientLayer (GAViewStyling) 79 | 80 | /** 81 | * Support setting a gradient from the WebKit gradient CSS declaration. 82 | */ 83 | - (void)setValuesWithCSSGradient:(NSString *)cssGradient; 84 | 85 | @end 86 | -------------------------------------------------------------------------------- /Samples/Theme Explorer/TransitionViewController.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: TransitionViewController.h 3 | Abstract: The view controller for showing transitions with UIView. 4 | Version: 2.9 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2011 Apple Inc. All Rights Reserved. 45 | 46 | */ 47 | 48 | #import 49 | 50 | @interface TransitionsViewController : UIViewController 51 | { 52 | UIView *containerView; 53 | UIImageView *mainView; 54 | UIImageView *flipToView; 55 | } 56 | 57 | @property (nonatomic, retain) UIView *containerView; 58 | @property (nonatomic, retain) UIImageView *mainView; 59 | @property (nonatomic, retain) UIImageView *flipToView; 60 | 61 | - (IBAction)curlAction:(id)sender; 62 | - (IBAction)flipAction:(id)sender; 63 | 64 | @end 65 | -------------------------------------------------------------------------------- /Samples/Theme Explorer/TextFieldController.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: TextFieldController.h 3 | Abstract: The view controller for hosting the UITextField features of this sample. 4 | Version: 2.9 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2011 Apple Inc. All Rights Reserved. 45 | 46 | */ 47 | 48 | #import 49 | 50 | @interface TextFieldController : UITableViewController 51 | { 52 | UITextField *textFieldNormal; 53 | UITextField *textFieldRounded; 54 | UITextField *textFieldSecure; 55 | UITextField *textFieldLeftView; 56 | 57 | NSArray *dataSourceArray; 58 | } 59 | 60 | @property (nonatomic, retain, readonly) UITextField *textFieldNormal; 61 | @property (nonatomic, retain, readonly) UITextField *textFieldRounded; 62 | @property (nonatomic, retain, readonly) UITextField *textFieldSecure; 63 | @property (nonatomic, retain, readonly) UITextField *textFieldLeftView; 64 | 65 | @property (nonatomic, retain) NSArray *dataSourceArray; 66 | 67 | @end 68 | -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | # Overview 2 | 3 | One of the neat parts about having a library, GAJavaScript, that makes it easier to access JavaScript is that using WebKit functionality becomes easier. One of those WebKit features is the CSS engine. GAViewStyling classes provide a means to drive UIView cosmetic properties via CSS declarations in an HTML document. 4 | 5 | ## How it works 6 | 7 | Using the UIWebView connected to a GAScriptEngine, load an HTML document that contains HTML markup and CSS. (The stylesheet could be embedded in the HTML, or external.) The HTML markup must provide one or more elements for each style that will be applied. The view styling engine does the following: 8 | 9 | 1. Starting with a UIView instance, determine the selector uses to query for a DOM element that represents the view. Currently, there are two kinds of selectors used. The class selector (e.g. .UITableView) is used when the view has no tag - the name of the Objective-C class is used as the "class" name. If the view has a nonzero tag, an ID selector (e.g. #tag-3000) is used. This allows you to create styles for specific UIViews. 10 | 2. Query the DOM for an element matching the selector. 11 | 3. If an element is found, call `window.getComputedStyle()` with that element. 12 | 4. Use the resulting CSSStyleDeclaration object to populate UIView properties such as backgroundColor, tintColor, font, etc. 13 | 5. Continue processing all of the view's subviews. 14 | 15 | GAViewStyling uses a category on UIView and many UIKit view classes. Your own custom view classes can implement methods in the category to change the behavior or apply CSS style information to your custom view properties. 16 | 17 | ## Example 18 | 19 | The "Theme Explorer" app in the /Samples folder shows how CSS can style various UIKit views and controls. It's built on the Apple "UICatalog" SDK sample, and it applies various (somewhat ugly) "themes" to the table views and various controls. It shows how you can change the overall styles "on the fly", while the app is running. 20 | 21 | In the "styles.html" file, notice how there are DIV tags in the body that have one or more classes set. This is essential so that the view styling code has an element to which styles can be applied. Also, you can just open the file in Safari to get a "preview" of what the styling will look like. 22 | 23 | When the Theme button changes from red to blue, it's just replacing the class on the BODY tag. This makes it easy to swap out entire style sets without having to write much code. 24 | 25 | ## Categories 26 | 27 | Even if the view styling code is not what you need, you might find some of the categories which can create colors, fonts and gradients from CSS-style strings. 28 | 29 | // Create a UIColor 30 | UIColor* color = [UIColor colorWithCSSColor:@"rgb(255, 128, 0)"]; 31 | 32 | // Create a UIFont 33 | NSDictionary* decl = [NSDictionary dictionaryWithObjectsAndKeys: 34 | @"Verdana", @"font-family", 35 | @"24px", @"font-size", 36 | @"bold", @"font-weight", nil]; 37 | UIFont* font = [UIFont fontWithCSSDeclaration:decl]; 38 | 39 | // Create a gradient layer 40 | NSString* cssGradient = @"-webkit-gradient(linear, 0% 0%, 0% 100%, from(rgba(217, 217, 217, 0)), to(rgba(0, 0, 0, 0.5)))"; 41 | 42 | CAGradientLayer* layer = [CAGradientLayer layer]; 43 | [layer setValuesWithCSSGradient:cssGradient]; 44 | 45 | The above code uses the categories defined in `GAViewStyling.h`. 46 | 47 | -------------------------------------------------------------------------------- /Samples/Theme Explorer/ControlsViewController.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: ControlsViewController.h 3 | Abstract: The view controller for hosting the UIControls features of this sample. 4 | Version: 2.9 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2011 Apple Inc. All Rights Reserved. 45 | 46 | */ 47 | 48 | #import 49 | 50 | @interface ControlsViewController : UITableViewController 51 | { 52 | UISwitch *switchCtl; 53 | UISlider *sliderCtl; 54 | UISlider *customSlider; 55 | UIPageControl *pageControl; 56 | UIActivityIndicatorView *progressInd; 57 | UIProgressView *progressBar; 58 | 59 | NSArray *dataSourceArray; 60 | } 61 | 62 | @property (nonatomic, retain, readonly) UISwitch *switchCtl; 63 | @property (nonatomic, retain, readonly) UISlider *sliderCtl; 64 | @property (nonatomic, retain, readonly) UISlider *customSlider; 65 | @property (nonatomic, retain, readonly) UIPageControl *pageControl; 66 | @property (nonatomic, retain, readonly) UIActivityIndicatorView *progressInd; 67 | @property (nonatomic, retain, readonly) UIProgressView *progressBar; 68 | 69 | @property (nonatomic, retain) NSArray *dataSourceArray; 70 | 71 | @end 72 | 73 | -------------------------------------------------------------------------------- /Classes/UIControl+GAViewStyling.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Andrew Goodale. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY ANDREW GOODALE "AS IS" AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Andrew Goodale. 27 | */ 28 | 29 | #import "UIControl+GAViewStyling.h" 30 | #import "GAViewStyling.h" 31 | #import "UIView+GAViewStyling.h" 32 | 33 | @implementation UIButton (GAViewStyling) 34 | 35 | - (void)applyComputedStyles:(id)cssDeclaration 36 | { 37 | UILabel* titleLabel = self.titleLabel; 38 | 39 | if (titleLabel) 40 | { 41 | [titleLabel applyComputedStyles:cssDeclaration]; 42 | } 43 | 44 | // Setting the background-color or background gradient image doesn't work 45 | // right with round rects. Need to figure out a better way 46 | } 47 | 48 | @end 49 | 50 | #pragma mark - 51 | 52 | @implementation UISegmentedControl (GAViewStyling) 53 | 54 | - (void)applyComputedStyles:(id)cssDeclaration 55 | { 56 | // It doesn't make sense to set self.backgroundColor for a segmented control. The tintColor is what matters. 57 | // 58 | NSString* backgroundColor = [cssDeclaration valueForKey:@"background-color"]; 59 | self.tintColor = [UIColor colorWithCSSColor:backgroundColor]; 60 | } 61 | 62 | @end 63 | 64 | #pragma mark - 65 | 66 | @implementation UITextField (GAViewStyling) 67 | 68 | - (void)applyComputedStyles:(id)cssDeclaration 69 | { 70 | // Text Font 71 | self.font = [UIFont fontWithCSSDeclaration:cssDeclaration]; 72 | 73 | // Text Color 74 | NSString* color = [cssDeclaration valueForKey:@"color"]; 75 | self.textColor = [UIColor colorWithCSSColor:color]; 76 | 77 | // Text Alignment 78 | // UIKit doesn't support "justified" and "inherit" is about the rule 79 | // 80 | NSString* textAlign = [cssDeclaration valueForKey:@"text-align"]; 81 | 82 | if ([textAlign isEqualToString:@"left"]) 83 | self.textAlignment = UITextAlignmentLeft; 84 | else if ([textAlign isEqualToString:@"center"]) 85 | self.textAlignment = UITextAlignmentCenter; 86 | else if ([textAlign isEqualToString:@"right"]) 87 | self.textAlignment = UITextAlignmentRight; 88 | } 89 | 90 | @end 91 | 92 | -------------------------------------------------------------------------------- /Samples/Theme Explorer/ButtonsViewController.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: ButtonsViewController.h 3 | Abstract: The table view controller for hosting the UIButton features of this sample. 4 | Version: 2.9 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2011 Apple Inc. All Rights Reserved. 45 | 46 | */ 47 | 48 | #import 49 | 50 | @interface ButtonsViewController : UITableViewController 51 | { 52 | UIButton *grayButton; 53 | UIButton *imageButton; 54 | UIButton *roundedButtonType; 55 | 56 | UIButton *detailDisclosureButtonType; 57 | 58 | UIButton *infoLightButtonType; 59 | UIButton *infoDarkButtonType; 60 | 61 | UIButton *contactAddButtonType; 62 | 63 | NSArray *dataSourceArray; 64 | } 65 | 66 | @property (nonatomic, retain, readonly) UIButton *grayButton; 67 | @property (nonatomic, retain, readonly) UIButton *imageButton; 68 | @property (nonatomic, retain, readonly) UIButton *roundedButtonType; 69 | 70 | @property (nonatomic, retain, readonly) UIButton *detailDisclosureButtonType; 71 | 72 | @property (nonatomic, retain, readonly) UIButton *infoLightButtonType; 73 | @property (nonatomic, retain, readonly) UIButton *infoDarkButtonType; 74 | 75 | @property (nonatomic, retain, readonly) UIButton *contactAddButtonType; 76 | 77 | @property (nonatomic, retain) NSArray *dataSourceArray; 78 | 79 | @end 80 | 81 | -------------------------------------------------------------------------------- /Samples/Theme Explorer/styles.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Theme Explorer 4 | 47 | 83 | 84 | 85 | 86 | 87 |
Navigation Bar
88 |   89 |
90 |
91 |
92 | Some label text in a table cell. 93 |
Label in a table view 94 |
95 |
96 |
97 |
98 |
99 |

Button Style:

100 | 101 | 102 | -------------------------------------------------------------------------------- /Samples/Theme Explorer/ToolbarViewController.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: ToolbarViewController.h 3 | Abstract: The view controller for hosting the UIToolbar and UIBarButtonItem features of this sample. 4 | Version: 2.9 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2011 Apple Inc. All Rights Reserved. 45 | 46 | */ 47 | 48 | #import 49 | 50 | @interface ToolbarViewController : UIViewController 51 | { 52 | UISegmentedControl *barStyleSegControl; 53 | UISwitch *tintSwitch; 54 | UISegmentedControl *buttonItemStyleSegControl; 55 | UIPickerView *systemButtonPicker; 56 | 57 | UIToolbar *toolbar; // created programmatically, not in IB 58 | NSArray *pickerViewArray; 59 | UIBarButtonSystemItem currentSystemItem; 60 | } 61 | 62 | @property (nonatomic, retain) IBOutlet UISegmentedControl *barStyleSegControl; 63 | @property (nonatomic, retain) IBOutlet UISwitch *tintSwitch; 64 | @property (nonatomic, retain) IBOutlet UISegmentedControl *buttonItemStyleSegControl; 65 | @property (nonatomic, retain) IBOutlet UIPickerView *systemButtonPicker; 66 | 67 | @property (nonatomic, retain) UIToolbar *toolbar; 68 | @property (nonatomic, retain) NSArray *pickerViewArray; 69 | 70 | - (IBAction)toggleStyle:(id)sender; 71 | - (IBAction)toggleBarStyle:(id)sender; 72 | - (IBAction)toggleTintColor:(id)sender; 73 | 74 | @end 75 | -------------------------------------------------------------------------------- /Samples/Theme Explorer/PickerViewController.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: PickerViewController.h 3 | Abstract: The view controller for hosting the UIPickerView of this sample. 4 | Version: 2.9 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2011 Apple Inc. All Rights Reserved. 45 | 46 | */ 47 | 48 | #import 49 | #import "CustomPickerDataSource.h" 50 | 51 | @interface PickerViewController : UIViewController 52 | { 53 | UIPickerView *myPickerView; 54 | UIDatePicker *datePickerView; 55 | NSArray *pickerViewArray; 56 | 57 | UILabel *label; 58 | 59 | UIPickerView *customPickerView; 60 | CustomPickerDataSource *customPickerDataSource; 61 | 62 | UIView *currentPicker; 63 | 64 | UISegmentedControl *buttonBarSegmentedControl; 65 | UISegmentedControl *pickerStyleSegmentedControl; 66 | UILabel *segmentLabel; 67 | } 68 | 69 | @property (nonatomic, retain) UIPickerView *myPickerView; 70 | @property (nonatomic, retain) UIDatePicker *datePickerView; 71 | @property (nonatomic, retain) NSArray *pickerViewArray; 72 | 73 | @property (nonatomic, retain) UILabel *label; 74 | 75 | @property (nonatomic, retain) UIPickerView *customPickerView; 76 | @property (nonatomic, retain) CustomPickerDataSource *customPickerDataSource; 77 | 78 | @property (nonatomic, retain) UIView *currentPicker; 79 | 80 | @property (nonatomic, retain) IBOutlet UISegmentedControl *buttonBarSegmentedControl; 81 | @property (nonatomic, retain) IBOutlet UISegmentedControl *pickerStyleSegmentedControl; 82 | @property (nonatomic, retain) IBOutlet UILabel *segmentLabel; 83 | 84 | 85 | - (IBAction)togglePickers:(id)sender; // for changing between UIPickerView, UIDatePickerView and custom picker 86 | - (IBAction)togglePickerStyle:(id)sender; // for changing the date picker's style 87 | 88 | @end 89 | -------------------------------------------------------------------------------- /Samples/Theme Explorer/SearchBarController.m: -------------------------------------------------------------------------------- 1 | /* 2 | File: SearchBarController.m 3 | Abstract: The view controller for hosting the UISearchBar features of this sample. 4 | Version: 2.9 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2011 Apple Inc. All Rights Reserved. 45 | 46 | */ 47 | 48 | #import "SearchBarController.h" 49 | 50 | @implementation SearchBarController 51 | 52 | @synthesize mySearchBar; 53 | 54 | - (void)dealloc 55 | { 56 | [mySearchBar release]; 57 | [super dealloc]; 58 | } 59 | 60 | - (void)viewDidLoad 61 | { 62 | [super viewDidLoad]; 63 | 64 | self.title = NSLocalizedString(@"SearchBarTitle", @""); 65 | 66 | self.view.backgroundColor = [UIColor groupTableViewBackgroundColor]; // use the table view background color 67 | 68 | self.mySearchBar = [[[UISearchBar alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.bounds.size.width, 44.0)] autorelease]; 69 | self.mySearchBar.delegate = self; 70 | self.mySearchBar.showsCancelButton = YES; 71 | 72 | // note: here you can also change its "tintColor" property to a different UIColor 73 | 74 | [self.view addSubview: self.mySearchBar]; 75 | } 76 | 77 | // called after the view controller's view is released and set to nil. 78 | // For example, a memory warning which causes the view to be purged. Not invoked as a result of -dealloc. 79 | // So release any properties that are loaded in viewDidLoad or can be recreated lazily. 80 | // 81 | - (void)viewDidUnload 82 | { 83 | [super viewDidUnload]; 84 | 85 | // release and set to nil 86 | self.mySearchBar = nil; 87 | } 88 | 89 | 90 | #pragma mark - 91 | #pragma mark UISearchBarDelegate 92 | 93 | // called when keyboard search button pressed 94 | - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar 95 | { 96 | [self.mySearchBar resignFirstResponder]; 97 | } 98 | 99 | // called when cancel button pressed 100 | - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar 101 | { 102 | [self.mySearchBar resignFirstResponder]; 103 | } 104 | 105 | @end 106 | -------------------------------------------------------------------------------- /Samples/Theme Explorer/Picker/CustomView.m: -------------------------------------------------------------------------------- 1 | /* 2 | File: CustomView.m 3 | Abstract: The custom view holding the image and title for the custom picker. 4 | Version: 2.9 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2011 Apple Inc. All Rights Reserved. 45 | 46 | */ 47 | 48 | #import "CustomView.h" 49 | 50 | #define MAIN_FONT_SIZE 18 51 | #define MIN_MAIN_FONT_SIZE 16 52 | 53 | @implementation CustomView 54 | 55 | @synthesize title, image; 56 | 57 | const CGFloat kViewWidth = 200; 58 | const CGFloat kViewHeight = 44; 59 | 60 | + (CGFloat)viewWidth 61 | { 62 | return kViewWidth; 63 | } 64 | 65 | + (CGFloat)viewHeight 66 | { 67 | return kViewHeight; 68 | } 69 | 70 | - (id)initWithFrame:(CGRect)frame 71 | { 72 | // use predetermined frame size 73 | self = [super initWithFrame:CGRectMake(0.0, 0.0, kViewWidth, kViewHeight)]; 74 | if (self) 75 | { 76 | self.backgroundColor = [UIColor clearColor]; // make the background transparent 77 | } 78 | return self; 79 | } 80 | 81 | - (void)drawRect:(CGRect)rect 82 | { 83 | // draw the image and title using their draw methods 84 | CGFloat yCoord = (self.bounds.size.height - self.image.size.height) / 2; 85 | CGPoint point = CGPointMake(10.0, yCoord); 86 | [self.image drawAtPoint:point]; 87 | 88 | yCoord = (self.bounds.size.height - MAIN_FONT_SIZE) / 2; 89 | point = CGPointMake(10.0 + self.image.size.width + 10.0, yCoord); 90 | [self.title drawAtPoint:point 91 | forWidth:self.bounds.size.width 92 | withFont:[UIFont systemFontOfSize:MAIN_FONT_SIZE] 93 | minFontSize:MIN_MAIN_FONT_SIZE 94 | actualFontSize:NULL 95 | lineBreakMode:UILineBreakModeTailTruncation 96 | baselineAdjustment:UIBaselineAdjustmentAlignBaselines]; 97 | } 98 | 99 | // Enable accessibility for this view. 100 | - (BOOL)isAccessibilityElement 101 | { 102 | return YES; 103 | } 104 | 105 | // Return a string that describes this view. 106 | - (NSString *)accessibilityLabel 107 | { 108 | return self.title; 109 | } 110 | 111 | - (void)dealloc 112 | { 113 | [title release]; 114 | [image release]; 115 | 116 | [super dealloc]; 117 | } 118 | 119 | @end 120 | -------------------------------------------------------------------------------- /Samples/Theme Explorer/Picker/CustomPickerDataSource.m: -------------------------------------------------------------------------------- 1 | /* 2 | File: CustomPickerDataSource.m 3 | Abstract: The data source for the Custom Picker that displays text and images. 4 | Version: 2.9 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2011 Apple Inc. All Rights Reserved. 45 | 46 | */ 47 | 48 | #import "CustomPickerDataSource.h" 49 | #import "CustomView.h" 50 | 51 | @implementation CustomPickerDataSource 52 | 53 | @synthesize customPickerArray; 54 | 55 | - (id)init 56 | { 57 | // use predetermined frame size 58 | self = [super init]; 59 | if (self) 60 | { 61 | // create the data source for this custom picker 62 | NSMutableArray *viewArray = [[NSMutableArray alloc] init]; 63 | 64 | CustomView *earlyMorningView = [[CustomView alloc] initWithFrame:CGRectZero]; 65 | earlyMorningView.title = @"Early Morning"; 66 | earlyMorningView.image = [UIImage imageNamed:@"12-6AM.png"]; 67 | [viewArray addObject:earlyMorningView]; 68 | [earlyMorningView release]; 69 | 70 | CustomView *lateMorningView = [[CustomView alloc] initWithFrame:CGRectZero]; 71 | lateMorningView.title = @"Late Morning"; 72 | lateMorningView.image = [UIImage imageNamed:@"6-12AM.png"]; 73 | [viewArray addObject:lateMorningView]; 74 | [lateMorningView release]; 75 | 76 | CustomView *afternoonView = [[CustomView alloc] initWithFrame:CGRectZero]; 77 | afternoonView.title = @"Afternoon"; 78 | afternoonView.image = [UIImage imageNamed:@"12-6PM.png"]; 79 | [viewArray addObject:afternoonView]; 80 | [afternoonView release]; 81 | 82 | CustomView *eveningView = [[CustomView alloc] initWithFrame:CGRectZero]; 83 | eveningView.title = @"Evening"; 84 | eveningView.image = [UIImage imageNamed:@"6-12PM.png"]; 85 | [viewArray addObject:eveningView]; 86 | [eveningView release]; 87 | 88 | self.customPickerArray = viewArray; 89 | [viewArray release]; 90 | } 91 | return self; 92 | } 93 | 94 | - (void)dealloc 95 | { 96 | [customPickerArray release]; 97 | [super dealloc]; 98 | } 99 | 100 | 101 | #pragma mark - 102 | #pragma mark UIPickerViewDataSource 103 | 104 | - (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component 105 | { 106 | return [CustomView viewWidth]; 107 | } 108 | 109 | - (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component 110 | { 111 | return [CustomView viewHeight]; 112 | } 113 | 114 | - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component 115 | { 116 | return [customPickerArray count]; 117 | } 118 | 119 | - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView 120 | { 121 | return 1; 122 | } 123 | 124 | 125 | #pragma mark - 126 | #pragma mark UIPickerViewDelegate 127 | 128 | // tell the picker which view to use for a given component and row, we have an array of views to show 129 | - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row 130 | forComponent:(NSInteger)component reusingView:(UIView *)view 131 | { 132 | return [customPickerArray objectAtIndex:row]; 133 | } 134 | 135 | @end 136 | -------------------------------------------------------------------------------- /Samples/Theme Explorer/ImagesViewController.m: -------------------------------------------------------------------------------- 1 | /* 2 | File: ImagesViewController.m 3 | Abstract: The view controller for hosting the UIImageView containing multiple images. 4 | Version: 2.9 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2011 Apple Inc. All Rights Reserved. 45 | 46 | */ 47 | 48 | #import "ImagesViewController.h" 49 | #import "Constants.h" 50 | 51 | #define kMinDuration 0.0 52 | #define kMaxDuration 10.0 53 | 54 | @implementation ImagesViewController 55 | 56 | @synthesize imageView, slider; 57 | 58 | - (void)dealloc 59 | { 60 | [imageView release]; 61 | [slider release]; 62 | 63 | [super dealloc]; 64 | } 65 | 66 | - (void)viewDidLoad 67 | { 68 | [super viewDidLoad]; 69 | 70 | self.title = NSLocalizedString(@"ImagesTitle", @""); 71 | 72 | // set up our UIImage with a group or array of images to animate (or in our case a slideshow) 73 | self.imageView.animationImages = [NSArray arrayWithObjects: 74 | [UIImage imageNamed:@"scene1.jpg"], 75 | [UIImage imageNamed:@"scene2.jpg"], 76 | [UIImage imageNamed:@"scene3.jpg"], 77 | [UIImage imageNamed:@"scene4.jpg"], 78 | [UIImage imageNamed:@"scene5.jpg"], 79 | nil]; 80 | imageView.animationDuration = 5.0; 81 | [self.imageView stopAnimating]; 82 | 83 | // Set the appropriate accessibility labels. 84 | [self.imageView setIsAccessibilityElement:YES]; 85 | [self.imageView setAccessibilityLabel:self.title]; 86 | [self.slider setAccessibilityLabel:NSLocalizedString(@"DurationSlider",@"")]; 87 | } 88 | 89 | // called after the view controller's view is released and set to nil. 90 | // For example, a memory warning which causes the view to be purged. Not invoked as a result of -dealloc. 91 | // So release any properties that are loaded in viewDidLoad or can be recreated lazily. 92 | // 93 | - (void)viewDidUnload 94 | { 95 | [super viewDidUnload]; 96 | 97 | self.imageView = nil; 98 | self.slider = nil; 99 | } 100 | 101 | // slown down or speed up the slide show as the slider is moved 102 | - (IBAction)sliderAction:(id)sender 103 | { 104 | UISlider* durationSlider = sender; 105 | self.imageView.animationDuration = [durationSlider value]; 106 | if (!self.imageView.isAnimating) 107 | [self.imageView startAnimating]; 108 | } 109 | 110 | 111 | #pragma mark - 112 | #pragma mark UIViewController delegate methods 113 | 114 | // called after this controller's view was dismissed, covered or otherwise hidden 115 | - (void)viewWillDisappear:(BOOL)animated 116 | { 117 | [self.imageView stopAnimating]; 118 | 119 | // restore the nav bar and status bar color to default 120 | self.navigationController.navigationBar.barStyle = UIBarStyleDefault; 121 | [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault; 122 | } 123 | 124 | // called after this controller's view will appear 125 | - (void)viewWillAppear:(BOOL)animated 126 | { 127 | [self.imageView startAnimating]; 128 | 129 | // for aesthetic reasons (the background is black), make the nav bar black for this particular page 130 | self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque; 131 | 132 | // match the status bar with the nav bar 133 | [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleBlackOpaque; 134 | } 135 | 136 | @end 137 | 138 | -------------------------------------------------------------------------------- /Samples/Theme Explorer/en.lproj/WebViewController.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 768 5 | 9G55 6 | 677 7 | 949.43 8 | 353.00 9 | 10 | YES 11 | 12 | 13 | YES 14 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 15 | 16 | 17 | YES 18 | 19 | YES 20 | 21 | 22 | YES 23 | 24 | 25 | 26 | YES 27 | 28 | IBFilesOwner 29 | 30 | 31 | IBFirstResponder 32 | 33 | 34 | 35 | 292 36 | {320, 460} 37 | 38 | 1 39 | MSAxIDEAA 40 | 41 | NO 42 | 43 | 44 | 45 | 46 | YES 47 | 48 | 49 | view 50 | 51 | 52 | 53 | 7 54 | 55 | 56 | 57 | 58 | YES 59 | 60 | 0 61 | 62 | YES 63 | 64 | 65 | 66 | 67 | 68 | -1 69 | 70 | 71 | RmlsZSdzIE93bmVyA 72 | 73 | 74 | -2 75 | 76 | 77 | 78 | 79 | 6 80 | 81 | 82 | 83 | 84 | 85 | 86 | YES 87 | 88 | YES 89 | -1.CustomClassName 90 | -2.CustomClassName 91 | 6.IBEditorWindowLastContentRect 92 | 6.IBPluginDependency 93 | 94 | 95 | YES 96 | WebViewController 97 | UIResponder 98 | {{0, 535}, {320, 460}} 99 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 100 | 101 | 102 | 103 | YES 104 | 105 | YES 106 | 107 | 108 | YES 109 | 110 | 111 | 112 | 113 | YES 114 | 115 | YES 116 | 117 | 118 | YES 119 | 120 | 121 | 122 | 7 123 | 124 | 125 | 126 | YES 127 | 128 | WebViewController 129 | UIViewController 130 | 131 | IBProjectSource 132 | WebViewController.h 133 | 134 | 135 | 136 | 137 | 0 138 | ../UICatalog.xcodeproj 139 | 3 140 | 141 | 142 | -------------------------------------------------------------------------------- /Samples/Theme Explorer/en.lproj/SearchBarController.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 768 5 | 9G55 6 | 677 7 | 949.43 8 | 353.00 9 | 10 | YES 11 | 12 | 13 | YES 14 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 15 | 16 | 17 | YES 18 | 19 | YES 20 | 21 | 22 | YES 23 | 24 | 25 | 26 | YES 27 | 28 | IBFilesOwner 29 | 30 | 31 | IBFirstResponder 32 | 33 | 34 | 35 | 292 36 | {{116, 125}, {320, 460}} 37 | 38 | 3 39 | MQA 40 | 41 | 2 42 | 43 | 44 | NO 45 | 46 | 47 | 48 | 49 | YES 50 | 51 | 52 | view 53 | 54 | 55 | 56 | 7 57 | 58 | 59 | 60 | 61 | YES 62 | 63 | 0 64 | 65 | YES 66 | 67 | 68 | 69 | 70 | 71 | -1 72 | 73 | 74 | RmlsZSdzIE93bmVyA 75 | 76 | 77 | -2 78 | 79 | 80 | 81 | 82 | 6 83 | 84 | 85 | 86 | 87 | 88 | 89 | YES 90 | 91 | YES 92 | -1.CustomClassName 93 | -2.CustomClassName 94 | 6.IBPluginDependency 95 | 96 | 97 | YES 98 | SearchBarController 99 | UIResponder 100 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 101 | 102 | 103 | 104 | YES 105 | 106 | YES 107 | 108 | 109 | YES 110 | 111 | 112 | 113 | 114 | YES 115 | 116 | YES 117 | 118 | 119 | YES 120 | 121 | 122 | 123 | 7 124 | 125 | 126 | 127 | YES 128 | 129 | SearchBarController 130 | UIViewController 131 | 132 | IBProjectSource 133 | SearchBarController.h 134 | 135 | 136 | 137 | 138 | 0 139 | ../UICatalog.xcodeproj 140 | 3 141 | 142 | 143 | -------------------------------------------------------------------------------- /Samples/Theme Explorer/en.lproj/SegmentViewController.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 768 5 | 9G55 6 | 677 7 | 949.43 8 | 353.00 9 | 10 | YES 11 | 12 | 13 | 14 | YES 15 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 16 | 17 | 18 | YES 19 | 20 | YES 21 | 22 | 23 | YES 24 | 25 | 26 | 27 | YES 28 | 29 | IBFilesOwner 30 | 31 | 32 | IBFirstResponder 33 | 34 | 35 | 36 | 292 37 | {320, 460} 38 | 39 | 40 | 1 41 | MSAxIDEAA 42 | 43 | NO 44 | 45 | 46 | 47 | 48 | YES 49 | 50 | 51 | view 52 | 53 | 54 | 55 | 7 56 | 57 | 58 | 59 | 60 | YES 61 | 62 | 0 63 | 64 | YES 65 | 66 | 67 | 68 | 69 | 70 | -1 71 | 72 | 73 | RmlsZSdzIE93bmVyA 74 | 75 | 76 | -2 77 | 78 | 79 | 80 | 81 | 6 82 | 83 | 84 | 85 | 86 | 87 | 88 | YES 89 | 90 | YES 91 | -1.CustomClassName 92 | -2.CustomClassName 93 | 6.IBEditorWindowLastContentRect 94 | 6.IBPluginDependency 95 | 96 | 97 | YES 98 | SegmentViewController 99 | UIResponder 100 | {{0, 535}, {320, 460}} 101 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 102 | 103 | 104 | 105 | YES 106 | 107 | YES 108 | 109 | 110 | YES 111 | 112 | 113 | 114 | 115 | YES 116 | 117 | YES 118 | 119 | 120 | YES 121 | 122 | 123 | 124 | 7 125 | 126 | 127 | 128 | YES 129 | 130 | SegmentViewController 131 | UIViewController 132 | 133 | IBProjectSource 134 | SegmentViewController.h 135 | 136 | 137 | 138 | 139 | 0 140 | ../UICatalog.xcodeproj 141 | 3 142 | 143 | 144 | -------------------------------------------------------------------------------- /Samples/Theme Explorer/en.lproj/AlertsViewController.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 768 5 | 9G55 6 | 677 7 | 949.43 8 | 353.00 9 | 10 | YES 11 | 12 | 13 | YES 14 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 15 | 16 | 17 | YES 18 | 19 | YES 20 | 21 | 22 | YES 23 | 24 | 25 | 26 | YES 27 | 28 | IBFilesOwner 29 | 30 | 31 | IBFirstResponder 32 | 33 | 34 | 35 | 274 36 | {320, 460} 37 | NO 38 | YES 39 | NO 40 | 1 41 | 1 42 | 0 43 | YES 44 | 4.400000e+01 45 | 1.000000e+01 46 | 1.000000e+01 47 | 48 | 49 | 50 | 51 | YES 52 | 53 | 54 | view 55 | 56 | 57 | 58 | 8 59 | 60 | 61 | 62 | 63 | YES 64 | 65 | 0 66 | 67 | YES 68 | 69 | 70 | 71 | 72 | 73 | -1 74 | 75 | 76 | RmlsZSdzIE93bmVyA 77 | 78 | 79 | -2 80 | 81 | 82 | 83 | 84 | 5 85 | 86 | 87 | 88 | 89 | 90 | 91 | YES 92 | 93 | YES 94 | -1.CustomClassName 95 | -2.CustomClassName 96 | 5.IBPluginDependency 97 | 98 | 99 | YES 100 | AlertsViewController 101 | UIResponder 102 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 103 | 104 | 105 | 106 | YES 107 | 108 | YES 109 | 110 | 111 | YES 112 | 113 | 114 | 115 | 116 | YES 117 | 118 | YES 119 | 120 | 121 | YES 122 | 123 | 124 | 125 | 8 126 | 127 | 128 | 129 | YES 130 | 131 | AlertsViewController 132 | UITableViewController 133 | 134 | IBProjectSource 135 | AlertsViewController.h 136 | 137 | 138 | 139 | 140 | 0 141 | ../UICatalog.xcodeproj 142 | 3 143 | 144 | 145 | -------------------------------------------------------------------------------- /Samples/Theme Explorer/ThemeAppDelegate.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Andrew Goodale. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY ANDREW GOODALE "AS IS" AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Andrew Goodale. 27 | */ 28 | 29 | #import "ThemeAppDelegate.h" 30 | #import "GAScriptEngine.h" 31 | #import "UIView+GAViewStyling.h" 32 | 33 | @implementation ThemeAppDelegate 34 | 35 | 36 | @synthesize window = _window; 37 | @synthesize navigationController = _navigationController; 38 | @synthesize scriptEngine = _scriptEngine; 39 | 40 | + (ThemeAppDelegate *)sharedAppDelegate 41 | { 42 | return (ThemeAppDelegate *) [[UIApplication sharedApplication] delegate]; 43 | } 44 | 45 | - (void)dealloc 46 | { 47 | [_window release]; 48 | [_navigationController release]; 49 | [_scriptEngine release]; 50 | 51 | [super dealloc]; 52 | } 53 | 54 | - (IBAction)changeTheme:(id)sender 55 | { 56 | if (_themeChanged) 57 | { 58 | // TODO: change the theme color 59 | NSString* curTheme = [_scriptEngine.documentObject valueForKeyPath:@"body.className"]; 60 | 61 | if ([curTheme isEqualToString:@"red_theme"]) 62 | curTheme = @"blue_theme"; 63 | else 64 | curTheme = @"red_theme"; 65 | 66 | [_scriptEngine.documentObject setValue:curTheme forKeyPath:@"body.className"]; 67 | } 68 | 69 | [_window applyStylesWithScriptEngine:_scriptEngine]; 70 | _themeChanged = YES; 71 | } 72 | 73 | - (void)applyStylesToView:(UIView *)view 74 | { 75 | if (_themeChanged) 76 | { 77 | [view applyStylesWithScriptEngine:_scriptEngine]; 78 | } 79 | } 80 | 81 | #pragma mark UIApplicationDelegate 82 | 83 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 84 | { 85 | // Override point for customization after application launch. 86 | // Add the navigation controller's view to the window and display. 87 | self.window.rootViewController = self.navigationController; 88 | [self.window makeKeyWindow]; 89 | 90 | _scriptEngine = [[GAScriptEngine alloc] initWithSuperview:self.window delegate:self]; 91 | 92 | NSURL* htmlUrl = [[NSBundle mainBundle] URLForResource:@"styles" withExtension:@"html"]; 93 | [_scriptEngine.webView loadRequest:[NSURLRequest requestWithURL:htmlUrl]]; 94 | 95 | _themeChanged = NO; 96 | 97 | return YES; 98 | } 99 | 100 | - (void)applicationWillResignActive:(UIApplication *)application 101 | { 102 | /* 103 | Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 104 | Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 105 | */ 106 | } 107 | 108 | - (void)applicationDidEnterBackground:(UIApplication *)application 109 | { 110 | /* 111 | Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 112 | If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 113 | */ 114 | } 115 | 116 | - (void)applicationWillEnterForeground:(UIApplication *)application 117 | { 118 | /* 119 | Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 120 | */ 121 | } 122 | 123 | - (void)applicationDidBecomeActive:(UIApplication *)application 124 | { 125 | /* 126 | Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 127 | */ 128 | } 129 | 130 | - (void)applicationWillTerminate:(UIApplication *)application 131 | { 132 | /* 133 | Called when the application is about to terminate. 134 | Save data if appropriate. 135 | See also applicationDidEnterBackground:. 136 | */ 137 | } 138 | 139 | #pragma mark UIWebViewDelegate 140 | 141 | - (void)webViewDidFinishLoad:(UIWebView *)webView 142 | { 143 | NSLog(@"WebView UA %@", [[_scriptEngine windowObject] valueForKeyPath:@"navigator.userAgent"]); 144 | } 145 | 146 | #pragma mark UINavigationControllerDelegate 147 | 148 | - (void)navigationController:(UINavigationController *)navigationController 149 | willShowViewController:(UIViewController *)viewController animated:(BOOL)animated 150 | { 151 | if (_themeChanged) 152 | { 153 | [viewController.view applyStylesWithScriptEngine:_scriptEngine]; 154 | } 155 | } 156 | 157 | @end 158 | 159 | /* 160 | 161 | NSString* curTheme = [_scriptEngine.documentObject valueForKeyPath:@"body.className"]; 162 | 163 | if ([curTheme isEqualToString:@"red_theme"]) 164 | curTheme = @"blue_theme"; 165 | else 166 | curTheme = @"red_theme"; 167 | 168 | [_scriptEngine.documentObject setValue:curTheme forKeyPath:@"body.className"]; 169 | 170 | */ 171 | -------------------------------------------------------------------------------- /Samples/Theme Explorer/en.lproj/TextViewController.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 768 5 | 9G55 6 | 677 7 | 949.43 8 | 353.00 9 | 10 | YES 11 | 12 | 13 | 14 | YES 15 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 16 | 17 | 18 | YES 19 | 20 | YES 21 | 22 | 23 | YES 24 | 25 | 26 | 27 | YES 28 | 29 | IBFilesOwner 30 | 31 | 32 | IBFirstResponder 33 | 34 | 35 | 36 | 292 37 | {320, 460} 38 | 39 | 40 | 3 41 | MQA 42 | 43 | 2 44 | 45 | 46 | NO 47 | 48 | 49 | 50 | 51 | YES 52 | 53 | 54 | view 55 | 56 | 57 | 58 | 7 59 | 60 | 61 | 62 | 63 | YES 64 | 65 | 0 66 | 67 | YES 68 | 69 | 70 | 71 | 72 | 73 | -1 74 | 75 | 76 | RmlsZSdzIE93bmVyA 77 | 78 | 79 | -2 80 | 81 | 82 | 83 | 84 | 6 85 | 86 | 87 | YES 88 | 89 | 90 | 91 | 92 | 93 | 94 | YES 95 | 96 | YES 97 | -1.CustomClassName 98 | -2.CustomClassName 99 | 6.IBEditorWindowLastContentRect 100 | 6.IBPluginDependency 101 | 102 | 103 | YES 104 | TextViewController 105 | UIResponder 106 | {{0, 535}, {320, 460}} 107 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 108 | 109 | 110 | 111 | YES 112 | 113 | YES 114 | 115 | 116 | YES 117 | 118 | 119 | 120 | 121 | YES 122 | 123 | YES 124 | 125 | 126 | YES 127 | 128 | 129 | 130 | 9 131 | 132 | 133 | 134 | YES 135 | 136 | TextViewController 137 | UIViewController 138 | 139 | IBProjectSource 140 | TextViewController.h 141 | 142 | 143 | 144 | 145 | 0 146 | ../UICatalog.xcodeproj 147 | 3 148 | 149 | 150 | -------------------------------------------------------------------------------- /Samples/Theme Explorer/en.lproj/ButtonsViewController.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 768 5 | 9G55 6 | 677 7 | 949.43 8 | 353.00 9 | 10 | YES 11 | 12 | 13 | YES 14 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 15 | 16 | 17 | YES 18 | 19 | YES 20 | 21 | 22 | YES 23 | 24 | 25 | 26 | YES 27 | 28 | IBFilesOwner 29 | 30 | 31 | IBFirstResponder 32 | 33 | 34 | 35 | 274 36 | {320, 247} 37 | NO 38 | YES 39 | NO 40 | NO 41 | 1 42 | 1 43 | 0 44 | YES 45 | 4.400000e+01 46 | 2.700000e+01 47 | 2.700000e+01 48 | 49 | 50 | 51 | 52 | YES 53 | 54 | 55 | view 56 | 57 | 58 | 59 | 3 60 | 61 | 62 | 63 | 64 | YES 65 | 66 | 0 67 | 68 | YES 69 | 70 | 71 | 72 | 73 | 74 | -1 75 | 76 | 77 | RmlsZSdzIE93bmVyA 78 | 79 | 80 | -2 81 | 82 | 83 | 84 | 85 | 2 86 | 87 | 88 | 89 | 90 | 91 | 92 | YES 93 | 94 | YES 95 | -1.CustomClassName 96 | -2.CustomClassName 97 | 2.IBEditorWindowLastContentRect 98 | 2.IBPluginDependency 99 | 100 | 101 | YES 102 | ButtonsViewController 103 | UIResponder 104 | {{0, 748}, {320, 247}} 105 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 106 | 107 | 108 | 109 | YES 110 | 111 | YES 112 | 113 | 114 | YES 115 | 116 | 117 | 118 | 119 | YES 120 | 121 | YES 122 | 123 | 124 | YES 125 | 126 | 127 | 128 | 3 129 | 130 | 131 | 132 | YES 133 | 134 | ButtonsViewController 135 | UITableViewController 136 | 137 | IBProjectSource 138 | ButtonsViewController.h 139 | 140 | 141 | 142 | 143 | 0 144 | ../UICatalog.xcodeproj 145 | 3 146 | 147 | 148 | -------------------------------------------------------------------------------- /Samples/Theme Explorer/en.lproj/ControlsViewController.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 768 5 | 9G55 6 | 677 7 | 949.43 8 | 353.00 9 | 10 | YES 11 | 12 | 13 | YES 14 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 15 | 16 | 17 | YES 18 | 19 | YES 20 | 21 | 22 | YES 23 | 24 | 25 | 26 | YES 27 | 28 | IBFilesOwner 29 | 30 | 31 | IBFirstResponder 32 | 33 | 34 | 35 | 274 36 | {320, 247} 37 | NO 38 | YES 39 | NO 40 | NO 41 | 1 42 | 1 43 | 0 44 | YES 45 | 4.400000e+01 46 | 2.700000e+01 47 | 2.700000e+01 48 | 49 | 50 | 51 | 52 | YES 53 | 54 | 55 | view 56 | 57 | 58 | 59 | 4 60 | 61 | 62 | 63 | 64 | YES 65 | 66 | 0 67 | 68 | YES 69 | 70 | 71 | 72 | 73 | 74 | -1 75 | 76 | 77 | RmlsZSdzIE93bmVyA 78 | 79 | 80 | -2 81 | 82 | 83 | 84 | 85 | 2 86 | 87 | 88 | 89 | 90 | 91 | 92 | YES 93 | 94 | YES 95 | -1.CustomClassName 96 | -2.CustomClassName 97 | 2.IBEditorWindowLastContentRect 98 | 2.IBPluginDependency 99 | 100 | 101 | YES 102 | ControlsViewController 103 | UIResponder 104 | {{0, 748}, {320, 247}} 105 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 106 | 107 | 108 | 109 | YES 110 | 111 | YES 112 | 113 | 114 | YES 115 | 116 | 117 | 118 | 119 | YES 120 | 121 | YES 122 | 123 | 124 | YES 125 | 126 | 127 | 128 | 4 129 | 130 | 131 | 132 | YES 133 | 134 | ControlsViewController 135 | UITableViewController 136 | 137 | IBProjectSource 138 | ControlsViewController.h 139 | 140 | 141 | 142 | 143 | 0 144 | ../UICatalog.xcodeproj 145 | 3 146 | 147 | 148 | -------------------------------------------------------------------------------- /Samples/Theme Explorer/TransitionViewController.m: -------------------------------------------------------------------------------- 1 | /* 2 | File: TransitionViewController.m 3 | Abstract: The view controller for showing transitions with UIView. 4 | Version: 2.9 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2011 Apple Inc. All Rights Reserved. 45 | 46 | */ 47 | 48 | #import "TransitionViewController.h" 49 | #import "Constants.h" 50 | 51 | #define kImageHeight 200.0 52 | #define kImageWidth 250.0 53 | #define kTransitionDuration 0.75 54 | #define kTopPlacement 80.0 // y coord for the images 55 | 56 | #pragma mark - 57 | 58 | @implementation TransitionsViewController 59 | 60 | @synthesize containerView, mainView, flipToView; 61 | 62 | - (void)dealloc 63 | { 64 | [mainView release]; 65 | [flipToView release]; 66 | [containerView release]; 67 | 68 | [super dealloc]; 69 | } 70 | 71 | - (void)viewDidLoad 72 | { 73 | [super viewDidLoad]; 74 | 75 | self.title = NSLocalizedString(@"TransitionsTitle", @""); 76 | 77 | // create the container view which we will use for transition animation (centered horizontally) 78 | CGRect frame = CGRectMake(round((self.view.bounds.size.width - kImageWidth) / 2.0), 79 | kTopPlacement, kImageWidth, kImageHeight); 80 | self.containerView = [[[UIView alloc] initWithFrame:frame] autorelease]; 81 | [self.view addSubview:self.containerView]; 82 | 83 | // The container view can represent the images for accessibility. 84 | [self.containerView setIsAccessibilityElement:YES]; 85 | [self.containerView setAccessibilityLabel:NSLocalizedString(@"ImagesTitle", @"")]; 86 | 87 | // create the initial image view 88 | frame = CGRectMake(0.0, 0.0, kImageWidth, kImageHeight); 89 | self.mainView = [[[UIImageView alloc] initWithFrame:frame] autorelease]; 90 | self.mainView.image = [UIImage imageNamed:@"scene1.jpg"]; 91 | [self.containerView addSubview:self.mainView]; 92 | 93 | // create the alternate image view (to transition between) 94 | CGRect imageFrame = CGRectMake(0.0, 0.0, kImageWidth, kImageHeight); 95 | self.flipToView = [[[UIImageView alloc] initWithFrame:imageFrame] autorelease]; 96 | self.flipToView.image = [UIImage imageNamed:@"scene2.jpg"]; 97 | } 98 | 99 | // called after the view controller's view is released and set to nil. 100 | // For example, a memory warning which causes the view to be purged. Not invoked as a result of -dealloc. 101 | // So release any properties that are loaded in viewDidLoad or can be recreated lazily. 102 | // 103 | - (void)viewDidUnload 104 | { 105 | [super viewDidUnload]; 106 | 107 | self.containerView = nil; 108 | self.flipToView = nil; 109 | self.mainView = nil; 110 | } 111 | 112 | - (IBAction)curlAction:(id)sender 113 | { 114 | [UIView beginAnimations:nil context:NULL]; 115 | [UIView setAnimationDuration:kTransitionDuration]; 116 | 117 | [UIView setAnimationTransition:([self.mainView superview] ? 118 | UIViewAnimationTransitionCurlUp : UIViewAnimationTransitionCurlDown) 119 | forView:self.containerView cache:YES]; 120 | if ([self.flipToView superview]) 121 | { 122 | [self.flipToView removeFromSuperview]; 123 | [self.containerView addSubview:self.mainView]; 124 | } 125 | else 126 | { 127 | [self.mainView removeFromSuperview]; 128 | [self.containerView addSubview:self.flipToView]; 129 | } 130 | 131 | [UIView commitAnimations]; 132 | } 133 | 134 | - (IBAction)flipAction:(id)sender 135 | { 136 | [UIView beginAnimations:nil context:NULL]; 137 | [UIView setAnimationDuration:kTransitionDuration]; 138 | 139 | [UIView setAnimationTransition:([self.mainView superview] ? 140 | UIViewAnimationTransitionFlipFromLeft : UIViewAnimationTransitionFlipFromRight) 141 | forView:self.containerView cache:YES]; 142 | if ([flipToView superview]) 143 | { 144 | [self.flipToView removeFromSuperview]; 145 | [self.containerView addSubview:mainView]; 146 | } 147 | else 148 | { 149 | [self.mainView removeFromSuperview]; 150 | [self.containerView addSubview:flipToView]; 151 | } 152 | 153 | [UIView commitAnimations]; 154 | } 155 | 156 | 157 | #pragma mark - 158 | #pragma mark UIViewController delegate methods 159 | 160 | // called after this controller's view was dismissed, covered or otherwise hidden 161 | - (void)viewWillDisappear:(BOOL)animated 162 | { 163 | // restore the nav bar and status bar color to default 164 | self.navigationController.navigationBar.barStyle = UIBarStyleDefault; 165 | [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault; 166 | } 167 | 168 | // called after this controller's view will appear 169 | - (void)viewWillAppear:(BOOL)animated 170 | { 171 | // for aesthetic reasons (the background is black), make the nav bar black for this particular page 172 | self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque; 173 | 174 | // match the status bar with the nav bar 175 | [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleBlackOpaque; 176 | } 177 | 178 | @end 179 | 180 | -------------------------------------------------------------------------------- /Samples/Theme Explorer/WebViewController.m: -------------------------------------------------------------------------------- 1 | /* 2 | File: WebViewController.m 3 | Abstract: The view controller for hosting the UIWebView feature of this sample. 4 | Version: 2.9 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2011 Apple Inc. All Rights Reserved. 45 | 46 | */ 47 | 48 | #import "WebViewController.h" 49 | #import "Constants.h" 50 | 51 | @implementation WebViewController 52 | 53 | @synthesize myWebView; 54 | 55 | - (void)dealloc 56 | { 57 | myWebView.delegate = nil; 58 | [myWebView release]; 59 | 60 | [super dealloc]; 61 | } 62 | 63 | - (void)viewDidLoad 64 | { 65 | [super viewDidLoad]; 66 | 67 | self.title = NSLocalizedString(@"WebTitle", @""); 68 | 69 | CGRect webFrame = [[UIScreen mainScreen] applicationFrame]; 70 | webFrame.origin.y += kTopMargin + 5.0; // leave from the URL input field and its label 71 | webFrame.size.height -= 40.0; 72 | self.myWebView = [[[UIWebView alloc] initWithFrame:webFrame] autorelease]; 73 | self.myWebView.backgroundColor = [UIColor whiteColor]; 74 | self.myWebView.scalesPageToFit = YES; 75 | self.myWebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); 76 | self.myWebView.delegate = self; 77 | [self.view addSubview:self.myWebView]; 78 | 79 | CGRect textFieldFrame = CGRectMake(kLeftMargin, kTweenMargin, 80 | self.view.bounds.size.width - (kLeftMargin * 2.0), kTextFieldHeight); 81 | UITextField *urlField = [[UITextField alloc] initWithFrame:textFieldFrame]; 82 | urlField.borderStyle = UITextBorderStyleBezel; 83 | urlField.textColor = [UIColor blackColor]; 84 | urlField.delegate = self; 85 | urlField.placeholder = @""; 86 | urlField.text = @"http://www.apple.com"; 87 | urlField.backgroundColor = [UIColor whiteColor]; 88 | urlField.autoresizingMask = UIViewAutoresizingFlexibleWidth; 89 | urlField.returnKeyType = UIReturnKeyGo; 90 | urlField.keyboardType = UIKeyboardTypeURL; // this makes the keyboard more friendly for typing URLs 91 | urlField.autocapitalizationType = UITextAutocapitalizationTypeNone; // don't capitalize 92 | urlField.autocorrectionType = UITextAutocorrectionTypeNo; // we don't like autocompletion while typing 93 | urlField.clearButtonMode = UITextFieldViewModeAlways; 94 | [urlField setAccessibilityLabel:NSLocalizedString(@"URLTextField", @"")]; 95 | [self.view addSubview:urlField]; 96 | [urlField release]; 97 | 98 | [self.myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.apple.com/"]]]; 99 | } 100 | 101 | // called after the view controller's view is released and set to nil. 102 | // For example, a memory warning which causes the view to be purged. Not invoked as a result of -dealloc. 103 | // So release any properties that are loaded in viewDidLoad or can be recreated lazily. 104 | // 105 | - (void)viewDidUnload 106 | { 107 | [super viewDidUnload]; 108 | 109 | // release and set to nil 110 | self.myWebView = nil; 111 | } 112 | 113 | 114 | #pragma mark - 115 | #pragma mark UIViewController delegate methods 116 | 117 | - (void)viewWillAppear:(BOOL)animated 118 | { 119 | self.myWebView.delegate = self; // setup the delegate as the web view is shown 120 | } 121 | 122 | - (void)viewWillDisappear:(BOOL)animated 123 | { 124 | [self.myWebView stopLoading]; // in case the web view is still loading its content 125 | self.myWebView.delegate = nil; // disconnect the delegate as the webview is hidden 126 | [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; 127 | } 128 | 129 | - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 130 | { 131 | // we support rotation in this view controller 132 | return YES; 133 | } 134 | 135 | // this helps dismiss the keyboard when the "Done" button is clicked 136 | - (BOOL)textFieldShouldReturn:(UITextField *)textField 137 | { 138 | [textField resignFirstResponder]; 139 | [self.myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[textField text]]]]; 140 | 141 | return YES; 142 | } 143 | 144 | 145 | #pragma mark - 146 | #pragma mark UIWebViewDelegate 147 | 148 | - (void)webViewDidStartLoad:(UIWebView *)webView 149 | { 150 | // starting the load, show the activity indicator in the status bar 151 | [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; 152 | } 153 | 154 | - (void)webViewDidFinishLoad:(UIWebView *)webView 155 | { 156 | // finished loading, hide the activity indicator in the status bar 157 | [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; 158 | } 159 | 160 | - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error 161 | { 162 | // load error, hide the activity indicator in the status bar 163 | [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; 164 | 165 | // report the error inside the webview 166 | NSString* errorString = [NSString stringWithFormat: 167 | @"
An error occurred:
%@
", 168 | error.localizedDescription]; 169 | [self.myWebView loadHTMLString:errorString baseURL:nil]; 170 | } 171 | 172 | @end 173 | 174 | -------------------------------------------------------------------------------- /Samples/Theme Explorer/en.lproj/TextFieldController.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 768 5 | 9G55 6 | 677 7 | 949.43 8 | 353.00 9 | 10 | YES 11 | 12 | 13 | YES 14 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 15 | 16 | 17 | YES 18 | 19 | YES 20 | 21 | 22 | YES 23 | 24 | 25 | 26 | YES 27 | 28 | IBFilesOwner 29 | 30 | 31 | IBFirstResponder 32 | 33 | 34 | 35 | 290 36 | {320, 416} 37 | NO 38 | YES 39 | NO 40 | NO 41 | 1 42 | 1 43 | 0 44 | YES 45 | 4.400000e+01 46 | 2.700000e+01 47 | 2.700000e+01 48 | 49 | 50 | 51 | 52 | YES 53 | 54 | 55 | view 56 | 57 | 58 | 59 | 20 60 | 61 | 62 | 63 | dataSource 64 | 65 | 66 | 67 | 21 68 | 69 | 70 | 71 | delegate 72 | 73 | 74 | 75 | 22 76 | 77 | 78 | 79 | 80 | YES 81 | 82 | 0 83 | 84 | YES 85 | 86 | 87 | 88 | 89 | 90 | -1 91 | 92 | 93 | RmlsZSdzIE93bmVyA 94 | 95 | 96 | -2 97 | 98 | 99 | 100 | 101 | 4 102 | 103 | 104 | 105 | 106 | 107 | 108 | YES 109 | 110 | YES 111 | -1.CustomClassName 112 | -2.CustomClassName 113 | 4.IBEditorWindowLastContentRect 114 | 4.IBPluginDependency 115 | 116 | 117 | YES 118 | TextFieldController 119 | UIResponder 120 | {{0, 748}, {320, 247}} 121 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 122 | 123 | 124 | 125 | YES 126 | 127 | YES 128 | 129 | 130 | YES 131 | 132 | 133 | 134 | 135 | YES 136 | 137 | YES 138 | 139 | 140 | YES 141 | 142 | 143 | 144 | 22 145 | 146 | 147 | 148 | YES 149 | 150 | TextFieldController 151 | UITableViewController 152 | 153 | toolbar 154 | UIToolbar 155 | 156 | 157 | IBProjectSource 158 | TextFieldController.h 159 | 160 | 161 | 162 | 163 | 0 164 | ../UICatalog.xcodeproj 165 | 3 166 | 167 | 168 | -------------------------------------------------------------------------------- /Samples/Theme Explorer/TextViewController.m: -------------------------------------------------------------------------------- 1 | /* 2 | File: TextViewController.m 3 | Abstract: The view controller for hosting the UITextView features of this sample. 4 | Version: 2.9 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2011 Apple Inc. All Rights Reserved. 45 | 46 | */ 47 | 48 | #import "TextViewController.h" 49 | 50 | @implementation TextViewController 51 | 52 | @synthesize textView; 53 | 54 | - (void)dealloc 55 | { 56 | [textView release]; 57 | [super dealloc]; 58 | } 59 | 60 | - (void)setupTextView 61 | { 62 | self.textView = [[[UITextView alloc] initWithFrame:self.view.frame] autorelease]; 63 | self.textView.textColor = [UIColor blackColor]; 64 | self.textView.font = [UIFont fontWithName:@"Arial" size:18.0]; 65 | self.textView.delegate = self; 66 | self.textView.backgroundColor = [UIColor whiteColor]; 67 | 68 | self.textView.text = @"Now is the time for all good developers to come to serve their country.\n\nNow is the time for all good developers to come to serve their country."; 69 | self.textView.returnKeyType = UIReturnKeyDefault; 70 | self.textView.keyboardType = UIKeyboardTypeDefault; // use the default type input method (entire keyboard) 71 | self.textView.scrollEnabled = YES; 72 | 73 | // this will cause automatic vertical resize when the table is resized 74 | self.textView.autoresizingMask = UIViewAutoresizingFlexibleHeight; 75 | 76 | // note: for UITextView, if you don't like autocompletion while typing use: 77 | // myTextView.autocorrectionType = UITextAutocorrectionTypeNo; 78 | 79 | [self.view addSubview: self.textView]; 80 | } 81 | 82 | - (void)viewDidLoad 83 | { 84 | [super viewDidLoad]; 85 | 86 | self.title = NSLocalizedString(@"TextViewTitle", @""); 87 | [self setupTextView]; 88 | } 89 | 90 | // called after the view controller's view is released and set to nil. 91 | // For example, a memory warning which causes the view to be purged. Not invoked as a result of -dealloc. 92 | // So release any properties that are loaded in viewDidLoad or can be recreated lazily. 93 | // 94 | - (void)viewDidUnload 95 | { 96 | [super viewDidUnload]; 97 | 98 | self.textView = nil; 99 | } 100 | 101 | - (void)keyboardWillShow:(NSNotification *)aNotification 102 | { 103 | // the keyboard is showing so resize the table's height 104 | CGRect keyboardRect = [[[aNotification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; 105 | NSTimeInterval animationDuration = 106 | [[[aNotification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]; 107 | CGRect frame = self.view.frame; 108 | frame.size.height -= keyboardRect.size.height; 109 | [UIView beginAnimations:@"ResizeForKeyboard" context:nil]; 110 | [UIView setAnimationDuration:animationDuration]; 111 | self.view.frame = frame; 112 | [UIView commitAnimations]; 113 | } 114 | 115 | - (void)keyboardWillHide:(NSNotification *)aNotification 116 | { 117 | // the keyboard is hiding reset the table's height 118 | CGRect keyboardRect = [[[aNotification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; 119 | NSTimeInterval animationDuration = 120 | [[[aNotification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]; 121 | CGRect frame = self.view.frame; 122 | frame.size.height += keyboardRect.size.height; 123 | [UIView beginAnimations:@"ResizeForKeyboard" context:nil]; 124 | [UIView setAnimationDuration:animationDuration]; 125 | self.view.frame = frame; 126 | [UIView commitAnimations]; 127 | } 128 | 129 | - (void)viewWillAppear:(BOOL)animated 130 | { 131 | [super viewWillAppear:animated]; 132 | 133 | // listen for keyboard hide/show notifications so we can properly adjust the table's height 134 | [[NSNotificationCenter defaultCenter] addObserver:self 135 | selector:@selector(keyboardWillShow:) 136 | name:UIKeyboardWillShowNotification 137 | object:nil]; 138 | [[NSNotificationCenter defaultCenter] addObserver:self 139 | selector:@selector(keyboardWillHide:) 140 | name:UIKeyboardWillHideNotification 141 | object:nil]; 142 | } 143 | 144 | - (void)viewDidDisappear:(BOOL)animated 145 | { 146 | [super viewDidDisappear:animated]; 147 | 148 | [[NSNotificationCenter defaultCenter] removeObserver:self 149 | name:UIKeyboardWillShowNotification 150 | object:nil]; 151 | [[NSNotificationCenter defaultCenter] removeObserver:self 152 | name:UIKeyboardWillHideNotification 153 | object:nil]; 154 | } 155 | 156 | #pragma mark - 157 | #pragma mark UITextViewDelegate 158 | 159 | - (void)saveAction:(id)sender 160 | { 161 | // finish typing text/dismiss the keyboard by removing it as the first responder 162 | // 163 | [self.textView resignFirstResponder]; 164 | self.navigationItem.rightBarButtonItem = nil; // this will remove the "save" button 165 | } 166 | 167 | - (void)textViewDidBeginEditing:(UITextView *)textView 168 | { 169 | // provide my own Save button to dismiss the keyboard 170 | UIBarButtonItem* saveItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone 171 | target:self 172 | action:@selector(saveAction:)]; 173 | self.navigationItem.rightBarButtonItem = saveItem; 174 | [saveItem release]; 175 | } 176 | 177 | @end 178 | 179 | -------------------------------------------------------------------------------- /Samples/Theme Explorer/SegmentViewController.m: -------------------------------------------------------------------------------- 1 | /* 2 | File: SegmentViewController.m 3 | Abstract: The view controller for hosting the UISegmentedControl features of this sample. 4 | Version: 2.9 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2011 Apple Inc. All Rights Reserved. 45 | 46 | */ 47 | 48 | #import "SegmentViewController.h" 49 | #import "Constants.h" 50 | 51 | #define kSegmentedControlHeight 40.0 52 | #define kLabelHeight 20.0 53 | 54 | @implementation SegmentViewController 55 | 56 | + (UILabel *)labelWithFrame:(CGRect)frame title:(NSString *)title 57 | { 58 | UILabel *label = [[[UILabel alloc] initWithFrame:frame] autorelease]; 59 | 60 | label.textAlignment = UITextAlignmentLeft; 61 | label.text = title; 62 | label.font = [UIFont boldSystemFontOfSize:17.0]; 63 | label.textColor = [UIColor colorWithRed:76.0/255.0 green:86.0/255.0 blue:108.0/255.0 alpha:1.0]; 64 | label.backgroundColor = [UIColor clearColor]; 65 | 66 | return label; 67 | } 68 | 69 | - (void)segmentAction:(id)sender 70 | { 71 | //NSLog(@"segmentAction: selected segment = %d", [sender selectedSegmentIndex]); 72 | } 73 | 74 | - (void)createControls 75 | { 76 | NSArray *segmentTextContent = [NSArray arrayWithObjects: @"Check", @"Search", @"Tools", nil]; 77 | 78 | // label 79 | CGFloat yPlacement = kTopMargin; 80 | CGRect frame = CGRectMake(kLeftMargin, yPlacement, self.view.bounds.size.width - (kRightMargin * 2.0), kLabelHeight); 81 | [self.view addSubview:[SegmentViewController labelWithFrame:frame title:@"UISegmentedControl:"]]; 82 | 83 | #pragma mark - 84 | #pragma mark UISegmentedControl 85 | UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems: 86 | [NSArray arrayWithObjects: 87 | [UIImage imageNamed:@"segment_check.png"], 88 | [UIImage imageNamed:@"segment_search.png"], 89 | [UIImage imageNamed:@"segment_tools.png"], 90 | nil]]; 91 | yPlacement += kTweenMargin + kLabelHeight; 92 | frame = CGRectMake( kLeftMargin, 93 | yPlacement, 94 | self.view.bounds.size.width - (kRightMargin * 2.0), 95 | kSegmentedControlHeight); 96 | segmentedControl.frame = frame; 97 | [segmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged]; 98 | segmentedControl.segmentedControlStyle = UISegmentedControlStylePlain; 99 | segmentedControl.selectedSegmentIndex = 1; 100 | [self.view addSubview:segmentedControl]; 101 | [segmentedControl release]; 102 | 103 | // Add the appropriate accessibility label to each image. 104 | [[segmentedControl imageForSegmentAtIndex:0] setAccessibilityLabel:NSLocalizedString(@"CheckMarkIcon", @"")]; 105 | [[segmentedControl imageForSegmentAtIndex:1] setAccessibilityLabel:NSLocalizedString(@"SearchIcon", @"")]; 106 | [[segmentedControl imageForSegmentAtIndex:2] setAccessibilityLabel:NSLocalizedString(@"ToolsIcon", @"")]; 107 | 108 | // label 109 | yPlacement += (kTweenMargin * 2.0) + kSegmentedControlHeight; 110 | frame = CGRectMake( kLeftMargin, 111 | yPlacement, 112 | self.view.bounds.size.width - (kRightMargin * 2.0), 113 | kLabelHeight); 114 | [self.view addSubview:[SegmentViewController labelWithFrame:frame title:@"UISegmentControlStyleBordered:"]]; 115 | 116 | #pragma mark - 117 | #pragma mark UISegmentControlStyleBordered 118 | segmentedControl = [[UISegmentedControl alloc] initWithItems:segmentTextContent]; 119 | yPlacement += kTweenMargin + kLabelHeight; 120 | frame = CGRectMake( kLeftMargin, 121 | yPlacement, 122 | self.view.bounds.size.width - (kRightMargin * 2.0), 123 | kSegmentedControlHeight); 124 | segmentedControl.frame = frame; 125 | [segmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged]; 126 | segmentedControl.segmentedControlStyle = UISegmentedControlStyleBordered; 127 | segmentedControl.selectedSegmentIndex = 1; 128 | 129 | [self.view addSubview:segmentedControl]; 130 | [segmentedControl release]; 131 | 132 | // label 133 | yPlacement += (kTweenMargin * 2.0) + kSegmentedControlHeight; 134 | frame = CGRectMake( kLeftMargin, 135 | yPlacement, 136 | self.view.bounds.size.width - (kRightMargin * 2.0), 137 | kLabelHeight); 138 | [self.view addSubview:[SegmentViewController labelWithFrame:frame title:@"UISegmentControlStyleBar:"]]; 139 | 140 | #pragma mark - 141 | #pragma mark UISegmentControlStyleBar 142 | yPlacement += kTweenMargin + kLabelHeight; 143 | segmentedControl = [[UISegmentedControl alloc] initWithItems:segmentTextContent]; 144 | frame = CGRectMake( kLeftMargin, 145 | yPlacement, 146 | self.view.bounds.size.width - (kRightMargin * 2.0), 147 | kSegmentedControlHeight); 148 | segmentedControl.frame = frame; 149 | [segmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged]; 150 | segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar; 151 | segmentedControl.selectedSegmentIndex = 1; 152 | 153 | [self.view addSubview:segmentedControl]; 154 | [segmentedControl release]; 155 | 156 | // label 157 | yPlacement += (kTweenMargin * 2.0) + kSegmentedControlHeight; 158 | frame = CGRectMake( kLeftMargin, 159 | yPlacement, 160 | self.view.bounds.size.width, 161 | kLabelHeight); 162 | [self.view addSubview:[SegmentViewController labelWithFrame:frame title:@"UISegmentControlStyleBar: (tinted)"]]; 163 | 164 | #pragma mark - 165 | #pragma mark UISegmentedControl (red-tinted) 166 | segmentedControl = [[UISegmentedControl alloc] initWithItems:segmentTextContent]; 167 | yPlacement += kTweenMargin + kLabelHeight; 168 | frame = CGRectMake( kLeftMargin, 169 | yPlacement, 170 | self.view.bounds.size.width - (kRightMargin * 2.0), 171 | kSegmentedControlHeight); 172 | segmentedControl.frame = frame; 173 | [segmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged]; 174 | segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar; 175 | segmentedControl.tintColor = [UIColor colorWithRed:0.70 green:0.171 blue:0.1 alpha:1.0]; 176 | segmentedControl.selectedSegmentIndex = 1; 177 | 178 | [self.view addSubview:segmentedControl]; 179 | [segmentedControl release]; 180 | #pragma mark - 181 | } 182 | 183 | - (void)viewDidLoad 184 | { 185 | [super viewDidLoad]; 186 | 187 | self.title = NSLocalizedString(@"SegmentTitle", @""); 188 | 189 | self.view.backgroundColor = [UIColor groupTableViewBackgroundColor]; // use the table view background color 190 | 191 | [self createControls]; // create the showcase of controls 192 | } 193 | 194 | @end 195 | 196 | -------------------------------------------------------------------------------- /Tests/TViewStyling.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Andrew Goodale. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY ANDREW GOODALE "AS IS" AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Andrew Goodale. 27 | */ 28 | 29 | #import "TViewStyling.h" 30 | #import 31 | #import "GAViewStyling.h" 32 | 33 | @implementation TViewStyling 34 | 35 | - (void)testColorFromCSSDeclaration 36 | { 37 | UIColor* color = [UIColor colorWithCSSColor:@"rgb(128, 128, 128)"]; 38 | 39 | NSString* testColor = [color description]; 40 | GHAssertTrue([testColor rangeOfString:@"0.501961 0.501961 0.501961"].location != NSNotFound, @"Color not converted"); 41 | 42 | color = [UIColor colorWithCSSColor:@"rgb(0, 0, 0)"]; 43 | 44 | testColor = [color description]; 45 | GHAssertTrue([testColor rangeOfString:@"UIDeviceWhiteColorSpace 0"].location != NSNotFound, @"Color not converted"); 46 | 47 | color = [UIColor colorWithCSSColor:@"rgba(0, 0, 0, 0)"]; 48 | 49 | testColor = [color description]; 50 | GHAssertTrue([testColor rangeOfString:@"UIDeviceWhiteColorSpace 0 0"].location != NSNotFound, @"Color not converted"); 51 | 52 | color = [UIColor colorWithCSSColor:@"rgb(240, 120, 0) 0px 1px"]; // Like a text-shadow decl 53 | 54 | testColor = [color description]; 55 | GHAssertTrue([testColor rangeOfString:@"0.941176 0.470588 0"].location != NSNotFound, @"Color not converted"); 56 | 57 | // Error handling... 58 | // 59 | color = [UIColor colorWithCSSColor:@"1, 2, 3, 4, 5"]; 60 | 61 | testColor = [color description]; 62 | GHAssertTrue([testColor rangeOfString:@"UIDeviceWhiteColorSpace 0 0"].location != NSNotFound, @"Color not converted"); 63 | 64 | color = [UIColor colorWithCSSColor:nil]; 65 | 66 | testColor = [color description]; 67 | GHAssertTrue([testColor rangeOfString:@"UIDeviceWhiteColorSpace 0 0"].location != NSNotFound, @"Color not converted"); 68 | } 69 | 70 | - (void)testFontFromCSSDeclaration 71 | { 72 | MockCSSDeclaration* decl = [[MockCSSDeclaration alloc] init]; 73 | decl.fontFamily = @"Verdana, sans-serif"; 74 | decl.fontSize = @"24px"; 75 | decl.fontStyle = @"normal"; 76 | decl.fontWeight = @"normal"; 77 | 78 | UIFont* font = [UIFont fontWithCSSDeclaration:decl]; 79 | GHAssertTrue([font.familyName isEqualToString:@"Verdana"], @"Wrong font family"); 80 | 81 | // Test that we can get the Bold font 82 | // 83 | decl.fontWeight = @"bold"; 84 | 85 | font = [UIFont fontWithCSSDeclaration:decl]; 86 | GHAssertTrue([font.familyName isEqualToString:@"Verdana"], @"Wrong font family"); 87 | GHAssertTrue([font.fontName isEqualToString:@"Verdana-Bold"], @"Wrong font name"); 88 | 89 | // Test that we skip over fonts that aren't installed 90 | // 91 | decl.fontFamily = @"MyFakeFont, Verdana, sans-serif"; 92 | 93 | font = [UIFont fontWithCSSDeclaration:decl]; 94 | GHAssertTrue([font.familyName isEqualToString:@"Verdana"], @"Wrong font family"); 95 | GHAssertTrue([font.fontName isEqualToString:@"Verdana-Bold"], @"Wrong font name"); 96 | 97 | // Test that we can get the Italic font 98 | // 99 | decl.fontWeight = @"normal"; 100 | decl.fontStyle = @"italic"; 101 | 102 | font = [UIFont fontWithCSSDeclaration:decl]; 103 | GHAssertTrue([font.familyName isEqualToString:@"Verdana"], @"Wrong font family"); 104 | GHAssertTrue([font.fontName isEqualToString:@"Verdana-Italic"], @"Wrong font name"); 105 | 106 | // Test that we can get the BoldItalic font 107 | // 108 | decl.fontWeight = @"bold"; 109 | decl.fontStyle = @"italic"; 110 | 111 | font = [UIFont fontWithCSSDeclaration:decl]; 112 | GHAssertTrue([font.familyName isEqualToString:@"Verdana"], @"Wrong font family"); 113 | GHAssertTrue([font.fontName isEqualToString:@"Verdana-BoldItalic"], @"Wrong font name"); 114 | 115 | // Test that we skip over fonts that aren't installed 116 | // 117 | decl.fontFamily = @"MyFakeFont, Verdannnnnna, sans-serif"; 118 | decl.fontStyle = @"normal"; 119 | 120 | font = [UIFont fontWithCSSDeclaration:decl]; 121 | GHAssertTrue([font.familyName isEqualToString:@"Helvetica"], @"Wrong font family"); 122 | GHAssertTrue([font.fontName isEqualToString:@"Helvetica-Bold"], @"Wrong font name"); 123 | 124 | [decl release]; 125 | } 126 | 127 | - (void)testSizeFromCSSLengths 128 | { 129 | NSString* lengths = @"100px 200px"; 130 | CGSize size = GASizeFromCSSLengths(lengths); 131 | GHAssertTrue(size.width == 100 && size.height == 200, @"Wrong width or height!"); 132 | 133 | lengths = @"10.5px 20.75px"; 134 | size = GASizeFromCSSLengths(lengths); 135 | GHAssertTrue(size.width == 10.5 && size.height == 20.75, @"Float values not handled!"); 136 | 137 | lengths = @"100 200"; 138 | size = GASizeFromCSSLengths(lengths); 139 | GHAssertTrue(size.width == 0 && size.height == 0, @"Bad string not handled!"); 140 | } 141 | 142 | - (void)testGradientLayer 143 | { 144 | NSString* cssGradient = @"-webkit-gradient(linear, 100% 0%, 0% 100%, color-stop(0.19, rgb(128, 22, 48)), color-stop(0.6, rgb(224, 36, 74)), color-stop(0.8, rgb(235, 52, 88)))"; 145 | 146 | CAGradientLayer* layer = [CAGradientLayer layer]; 147 | [layer setValuesWithCSSGradient:cssGradient]; 148 | 149 | GHAssertTrue([layer.colors count] == 3, @"Wrong number of colors"); 150 | 151 | CGColorRef color1 = (CGColorRef)[layer.colors objectAtIndex:0]; 152 | const CGFloat* pColors = CGColorGetComponents(color1); 153 | GHAssertTrue(pColors[0] == 128/255.f && pColors[1] == 22/255.f && pColors[2] == 48/255.f, @"Bad colors"); 154 | 155 | CGColorRef color2 = (CGColorRef)[layer.colors objectAtIndex:1]; 156 | pColors = CGColorGetComponents(color2); 157 | GHAssertTrue(pColors[0] == 224/255.f && pColors[1] == 36/255.f && pColors[2] == 74/255.f, @"Bad colors"); 158 | 159 | CGColorRef color3 = (CGColorRef)[layer.colors objectAtIndex:2]; 160 | pColors = CGColorGetComponents(color3); 161 | GHAssertTrue(pColors[0] == 235/255.f && pColors[1] == 52/255.f && pColors[2] == 88/255.f, @"Bad colors"); 162 | 163 | NSNumber* loc1 = [layer.locations objectAtIndex:0]; 164 | GHAssertTrue([loc1 floatValue] == 0.19f, @"Location wrong"); 165 | 166 | NSNumber* loc2 = [layer.locations objectAtIndex:1]; 167 | GHAssertTrue([loc2 floatValue] == 0.6f, @"Location wrong"); 168 | 169 | NSNumber* loc3 = [layer.locations objectAtIndex:2]; 170 | GHAssertTrue([loc3 floatValue] == 0.8f, @"Location wrong"); 171 | } 172 | 173 | - (void)testGradientToFromSyntax 174 | { 175 | NSString* cssGradient = @"-webkit-gradient(linear, 0% 0%, 0% 100%, from(rgba(217, 217, 217, 0)), to(rgba(0, 0, 0, 0.5)))"; 176 | 177 | CAGradientLayer* layer = [CAGradientLayer layer]; 178 | [layer setValuesWithCSSGradient:cssGradient]; 179 | 180 | GHAssertTrue([layer.colors count] == 2, @"Wrong number of colors"); 181 | 182 | CGColorRef color1 = (CGColorRef)[layer.colors objectAtIndex:0]; 183 | const CGFloat* pColors = CGColorGetComponents(color1); 184 | GHAssertTrue(pColors[0] == 0.850980401f && pColors[1] == 0.850980401f && pColors[2] == 0.850980401f, @"Bad colors"); 185 | 186 | CGColorRef color2 = (CGColorRef)[layer.colors objectAtIndex:1]; 187 | pColors = CGColorGetComponents(color2); 188 | GHAssertTrue(pColors[0] == 0.f && pColors[1] == 0.5f, @"Bad colors"); 189 | } 190 | 191 | - (void)testImageFromCSSURL 192 | { 193 | NSString* testUrl = @"url(file://blah/blah/logo.jpg)"; 194 | UIImage* testImage = [UIImage imageWithCSSURL:testUrl]; 195 | 196 | GHAssertNotNil(testImage, @"Could not load image from bundle"); 197 | 198 | testUrl = @"urrl(foo)"; 199 | testImage = [UIImage imageWithCSSURL:testUrl]; 200 | 201 | GHAssertNil(testImage, @"Should not have an image now."); 202 | 203 | testUrl = @"url(data:image/gif;base64,R0lGODlhEAAOALMAAOazToeHh0tLS/7LZv/0jvb29t/f3//Ub//ge8WSLf/rhf/3kdbW1mxsbP//mf///yH5BAAAAAAALAAAAAAQAA4AAARe8L1Ekyky67QZ1hLnjM5UUde0ECwLJoExKcppV0aCcGCmTIHEIUEqjgaORCMxIC6e0CcguWw6aFjsVMkkIr7g77ZKPJjPZqIyd7sJAgVGoEGv2xsBxqNgYPj/gAwXEQA7)"; 204 | testImage = [UIImage imageWithCSSURL:testUrl]; 205 | 206 | GHAssertNotNil(testImage, @"Could not load image from data URL"); 207 | } 208 | 209 | @end 210 | 211 | #pragma mark - 212 | 213 | @implementation MockCSSDeclaration 214 | 215 | @synthesize fontFamily = _fontFamily, fontSize = _fontSize, fontStyle = _fontStyle, fontWeight = _fontWeight; 216 | 217 | // Implement support for the real CSS property names, which would be supported by GAScriptObject 218 | // 219 | - (id)valueForKey:(NSString *)key 220 | { 221 | if ([key isEqualToString:@"font-family"]) 222 | return self.fontFamily; 223 | 224 | if ([key isEqualToString:@"font-size"]) 225 | return self.fontSize; 226 | 227 | if ([key isEqualToString:@"font-style"]) 228 | return self.fontStyle; 229 | 230 | if ([key isEqualToString:@"font-weight"]) 231 | return self.fontWeight; 232 | 233 | return [super valueForKey:key]; 234 | } 235 | 236 | @end -------------------------------------------------------------------------------- /Classes/GAViewStyling.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Andrew Goodale. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY ANDREW GOODALE "AS IS" AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Andrew Goodale. 27 | */ 28 | 29 | #import "GAViewStyling.h" 30 | 31 | static NSCharacterSet* kSkipSet; 32 | static dispatch_once_t s_onceToken; 33 | static void(^s_initBlock)(void) = ^(void) 34 | { 35 | kSkipSet = [[NSCharacterSet characterSetWithCharactersInString:@", %"] retain]; 36 | }; 37 | 38 | @implementation UIColor (GAViewStyling) 39 | 40 | + (UIColor *)colorWithCSSColor:(NSString *)cssColor 41 | { 42 | dispatch_once(&s_onceToken, s_initBlock); 43 | 44 | if (cssColor == nil || [cssColor length] == 0) 45 | return [UIColor clearColor]; 46 | 47 | // Look for "rgb[a](". If there's no match, just return a transparent color. 48 | // 49 | NSScanner* scanner = [NSScanner scannerWithString:cssColor]; 50 | [scanner setCharactersToBeSkipped:kSkipSet]; 51 | 52 | if (![scanner scanString:@"rgb(" intoString:NULL] && ![scanner scanString:@"rgba(" intoString:NULL]) 53 | return [UIColor clearColor]; 54 | 55 | CGFloat r, g, b, a; 56 | 57 | if ([scanner scanFloat:&r]) 58 | r /= 255.f; 59 | if ([scanner scanFloat:&g]) 60 | g /= 255.f; 61 | if ([scanner scanFloat:&b]) 62 | b /= 255.f; 63 | if (![scanner scanFloat:&a]) // Might have been rgba(...) 64 | a = 1.0f; 65 | 66 | // Optimize common colors (black, white, transparent) 67 | // 68 | if (r == 1.0f && g == 1.0f && b == 1.0f) 69 | return [UIColor colorWithWhite:1.0f alpha:a]; 70 | else if (r == 0.0f && g == 0.0f && b == 0.0f) 71 | return [UIColor colorWithWhite:0.0f alpha:a]; 72 | 73 | return [UIColor colorWithRed:r green:g blue:b alpha:a]; 74 | } 75 | 76 | @end 77 | 78 | #pragma mark - 79 | 80 | @implementation UIFont (GAViewStyling) 81 | 82 | + (UIFont *)fontWithCSSDeclaration:(id)cssDeclaration 83 | { 84 | NSString* cssFontFamily = [cssDeclaration valueForKey:@"font-family"]; 85 | NSString* cssFontWeight = [cssDeclaration valueForKey:@"font-weight"]; 86 | NSString* cssFontStyle = [cssDeclaration valueForKey:@"font-style"]; 87 | NSString* cssFontSize = [cssDeclaration valueForKey:@"font-size"]; 88 | 89 | BOOL wantBold = [cssFontWeight isEqualToString:@"bold"]; 90 | BOOL wantItalic = [cssFontStyle isEqualToString:@"italic"]; 91 | 92 | // Font size is in pixels, and we must convert to points. 93 | // 94 | CGFloat sizeInPoints = [cssFontSize integerValue] / [[UIScreen mainScreen] scale]; 95 | 96 | NSArray* families = [cssFontFamily componentsSeparatedByString:@", "]; 97 | NSArray* candidateFontNames = nil; 98 | 99 | // First, get the family we want... 100 | // 101 | for (NSString* family in families) 102 | { 103 | // Handle the mapping of generic family names 104 | // 105 | if ([family caseInsensitiveCompare:@"serif"] == NSOrderedSame) 106 | family = @"Times New Roman"; 107 | else if ([family caseInsensitiveCompare:@"sans-serif"] == NSOrderedSame) 108 | family = @"Helvetica"; 109 | 110 | candidateFontNames = [UIFont fontNamesForFamilyName:family]; 111 | 112 | if ([candidateFontNames count] > 0) 113 | break; 114 | } 115 | 116 | if ([candidateFontNames count] == 0) 117 | { 118 | return [UIFont systemFontOfSize:sizeInPoints]; 119 | } 120 | 121 | // Sort the array so the plain font is first 122 | // 123 | candidateFontNames = [candidateFontNames sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) 124 | { 125 | return [obj1 length] - [obj2 length]; 126 | }]; 127 | 128 | // Pick the first (plain) font to start with. 129 | // 130 | __block NSString* fontName = [candidateFontNames objectAtIndex:0]; 131 | 132 | if (wantBold || wantItalic) 133 | { 134 | __block NSString* marker = (wantBold && !wantItalic) ? @"-Bold" 135 | : (wantItalic && !wantBold) ? @"-Italic" : @"-BoldItalic"; 136 | 137 | [candidateFontNames enumerateObjectsUsingBlock:^void(id testFontName, NSUInteger idx, BOOL *stop) 138 | { 139 | if ([testFontName rangeOfString:marker].location != NSNotFound) 140 | { 141 | fontName = testFontName; 142 | *stop = YES; 143 | } 144 | }]; 145 | } 146 | 147 | return [UIFont fontWithName:fontName size:sizeInPoints]; 148 | } 149 | 150 | @end 151 | 152 | #pragma mark - 153 | 154 | @implementation UIImage (GAViewStyling) 155 | 156 | + (UIImage *)imageWithCSSURL:(NSString *)cssUrl 157 | { 158 | // Make a NSURL by using everything inside the "url(...)" string 159 | // 160 | NSRange urlRange = NSMakeRange(4, [cssUrl length] - 5); 161 | NSURL* theUrl = [NSURL URLWithString:[cssUrl substringWithRange:urlRange]]; 162 | 163 | if ([[theUrl scheme] isEqualToString:NSURLFileScheme]) 164 | { 165 | GADebugStr(@"Loading image named '%@'", [theUrl lastPathComponent]); 166 | 167 | return [UIImage imageNamed:[theUrl lastPathComponent]]; 168 | } 169 | else if ([[theUrl scheme] isEqualToString:@"data"]) 170 | { 171 | NSError* myErr = nil; 172 | NSData* imgData = [NSData dataWithContentsOfURL:theUrl options:0 error:&myErr]; 173 | 174 | if (myErr != nil) 175 | { 176 | NSLog(@"Could not make NSData from data URL: %@", myErr); 177 | return nil; 178 | } 179 | 180 | return [UIImage imageWithData:imgData]; 181 | } 182 | 183 | NSAssert(YES, @"Unsupported URL scheme for UIImage (GAViewStyling): %@", [theUrl scheme]); 184 | return nil; 185 | } 186 | 187 | @end 188 | /** 189 | * The input string will be something like "NNNpx NNNpx [other chars]" 190 | */ 191 | CGSize GASizeFromCSSLengths (NSString* cssString) 192 | { 193 | NSArray* lengths = [cssString componentsSeparatedByString:@"px "]; 194 | 195 | if ([lengths count] < 2) 196 | return CGSizeZero; 197 | 198 | CGFloat x = [[lengths objectAtIndex:0] floatValue]; 199 | CGFloat y = [[lengths objectAtIndex:1] floatValue]; 200 | 201 | return CGSizeMake(x, y); 202 | } 203 | 204 | #pragma mark - 205 | 206 | @implementation CAGradientLayer (GAViewStyling) 207 | 208 | /** 209 | * Creates a gradient layer using the CSS specification from WebKit. 210 | * 211 | * Example: -webkit-gradient(linear, 0% 100%, 0% 0%, 212 | * color-stop(0.19, rgb(128, 22, 48)), color-stop(0.6, rgb(224, 36, 74)), color-stop(0.8, rgb(235, 52, 88))) 213 | */ 214 | - (void)setValuesWithCSSGradient:(NSString *)cssGradient 215 | { 216 | dispatch_once(&s_onceToken, s_initBlock); 217 | 218 | if (cssGradient == nil || [cssGradient length] == 0) 219 | return; 220 | 221 | NSScanner* scanner = [NSScanner scannerWithString:cssGradient]; 222 | [scanner setCharactersToBeSkipped:kSkipSet]; 223 | 224 | if (![scanner scanString:@"-webkit-gradient(linear" intoString:NULL]) 225 | return; 226 | 227 | // The start and end points come out of WebKit as percentages 228 | // 229 | CGPoint start = { .5f, 0.0f }, end = { .5f, 1.0f }; 230 | 231 | if ([scanner scanFloat:&start.x]) 232 | start.x /= 100.0f; 233 | if ([scanner scanFloat:&start.y]) 234 | start.y /= 100.0f; 235 | if ([scanner scanFloat:&end.x]) 236 | end.x /= 100.0f; 237 | if ([scanner scanFloat:&end.y]) 238 | end.y /= 100.0f; 239 | 240 | [self setStartPoint:start]; 241 | [self setEndPoint:end]; 242 | 243 | NSMutableArray* colors = [[NSMutableArray alloc] initWithCapacity:4]; 244 | NSMutableArray* locations = [[NSMutableArray alloc] initWithCapacity:4]; 245 | 246 | while (![scanner isAtEnd]) 247 | { 248 | CGFloat location = 0.0f; 249 | NSString* colorStop = nil; 250 | 251 | if ([scanner scanString:@"from(" intoString:NULL]) 252 | { 253 | location = 0.0f; 254 | } 255 | else if ([scanner scanString:@"to(" intoString:NULL]) 256 | { 257 | location = 1.0f; 258 | } 259 | else if ([scanner scanString:@"color-stop(" intoString:NULL]) 260 | { 261 | [scanner scanFloat:&location]; 262 | } 263 | else 264 | { 265 | break; 266 | } 267 | 268 | if (![scanner scanUpToString:@"))" intoString:&colorStop]) 269 | break; 270 | 271 | // Keep the color and location arrays the same length 272 | // 273 | UIColor* color = [UIColor colorWithCSSColor:colorStop]; 274 | [colors addObject:(id)[color CGColor]]; 275 | [locations addObject:[NSNumber numberWithFloat:location]]; 276 | 277 | [scanner scanString:@"))" intoString:NULL]; 278 | } 279 | 280 | [self setColors:colors]; 281 | [self setLocations:locations]; 282 | [colors release]; 283 | [locations release]; 284 | } 285 | 286 | @end 287 | 288 | --------------------------------------------------------------------------------