├── Screenshots ├── 2colors.png ├── 3colors.png ├── purple.png ├── cyan-dashes.png ├── cyan-dottedlines.png ├── gradient-diagonal1.png ├── gradient-diagonal2.png └── gradient-horizontal.png ├── StyledTableViewCellDemo ├── StyledTableViewCellDemo │ ├── en.lproj │ │ └── InfoPlist.strings │ ├── StyledTableViewCellDemo-Prefix.pch │ ├── main.m │ ├── StyledTableViewCellDemo-Info.plist │ ├── StyleListTableViewController.h │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── DemoTableViewController.h │ ├── StyleListTableViewController.m │ └── DemoTableViewController.m └── StyledTableViewCellDemo.xcodeproj │ ├── project.xcworkspace │ └── contents.xcworkspacedata │ ├── xcuserdata │ └── honcheng.xcuserdatad │ │ └── xcschemes │ │ ├── xcschememanagement.plist │ │ └── StyledTableViewCellDemo.xcscheme │ └── project.pbxproj ├── LICENSE ├── StyledTableViewCell-for-iOS.podspec ├── StyledTableViewCell ├── StyledTableViewCell.h └── StyledTableViewCell.m └── README.md /Screenshots/2colors.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/honcheng/StyledTableViewCell-for-iOS/HEAD/Screenshots/2colors.png -------------------------------------------------------------------------------- /Screenshots/3colors.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/honcheng/StyledTableViewCell-for-iOS/HEAD/Screenshots/3colors.png -------------------------------------------------------------------------------- /Screenshots/purple.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/honcheng/StyledTableViewCell-for-iOS/HEAD/Screenshots/purple.png -------------------------------------------------------------------------------- /Screenshots/cyan-dashes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/honcheng/StyledTableViewCell-for-iOS/HEAD/Screenshots/cyan-dashes.png -------------------------------------------------------------------------------- /StyledTableViewCellDemo/StyledTableViewCellDemo/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Screenshots/cyan-dottedlines.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/honcheng/StyledTableViewCell-for-iOS/HEAD/Screenshots/cyan-dottedlines.png -------------------------------------------------------------------------------- /Screenshots/gradient-diagonal1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/honcheng/StyledTableViewCell-for-iOS/HEAD/Screenshots/gradient-diagonal1.png -------------------------------------------------------------------------------- /Screenshots/gradient-diagonal2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/honcheng/StyledTableViewCell-for-iOS/HEAD/Screenshots/gradient-diagonal2.png -------------------------------------------------------------------------------- /Screenshots/gradient-horizontal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/honcheng/StyledTableViewCell-for-iOS/HEAD/Screenshots/gradient-horizontal.png -------------------------------------------------------------------------------- /StyledTableViewCellDemo/StyledTableViewCellDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /StyledTableViewCellDemo/StyledTableViewCellDemo/StyledTableViewCellDemo-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'StyledTableViewCellDemo' target in the 'StyledTableViewCellDemo' project 3 | // 4 | 5 | #import 6 | 7 | #ifndef __IPHONE_3_0 8 | #warning "This project uses features only available in iOS SDK 3.0 and later." 9 | #endif 10 | 11 | #ifdef __OBJC__ 12 | #import 13 | #import 14 | #endif 15 | -------------------------------------------------------------------------------- /StyledTableViewCellDemo/StyledTableViewCellDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // StyledTableViewCellDemo 4 | // 5 | // Created by Hon Cheng Muh on 28/2/12. 6 | // Copyright (c) 2012 honcheng@gmail.com. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "AppDelegate.h" 12 | 13 | int main(int argc, char *argv[]) 14 | { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /StyledTableViewCellDemo/StyledTableViewCellDemo.xcodeproj/xcuserdata/honcheng.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | StyledTableViewCellDemo.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | F8DF552214FC78310086395D 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Muh Hon Cheng 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject 9 | to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT 15 | WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 16 | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR 18 | PURPOSE AND NONINFRINGEMENT. IN NO EVENT 19 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR 23 | IN CONNECTION WITH THE SOFTWARE OR 24 | THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | 26 | @author Muh Hon Cheng 27 | @copyright 2012 Muh Hon Cheng -------------------------------------------------------------------------------- /StyledTableViewCellDemo/StyledTableViewCellDemo/StyledTableViewCellDemo-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | com.honcheng.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /StyledTableViewCellDemo/StyledTableViewCellDemo/StyleListTableViewController.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2012 Muh Hon Cheng 3 | * Created by honcheng on 3/4/12. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining 6 | * a copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sublicense, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject 11 | * to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT 17 | * WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 18 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR 20 | * PURPOSE AND NONINFRINGEMENT. IN NO EVENT 21 | * SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 22 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 24 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR 25 | * IN CONNECTION WITH THE SOFTWARE OR 26 | * THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * @author Muh Hon Cheng 29 | * @copyright 2012 Muh Hon Cheng 30 | * @version 31 | * 32 | */ 33 | 34 | #import 35 | 36 | @interface StyleListTableViewController : UITableViewController 37 | @end 38 | -------------------------------------------------------------------------------- /StyledTableViewCellDemo/StyledTableViewCellDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2012 Muh Hon Cheng 3 | * Created by honcheng on 28/2/12. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining 6 | * a copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sublicense, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject 11 | * to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT 17 | * WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 18 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR 20 | * PURPOSE AND NONINFRINGEMENT. IN NO EVENT 21 | * SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 22 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 24 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR 25 | * IN CONNECTION WITH THE SOFTWARE OR 26 | * THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * @author Muh Hon Cheng 29 | * @copyright 2012 Muh Hon Cheng 30 | * @version 31 | * 32 | */ 33 | 34 | #import 35 | 36 | @interface AppDelegate : UIResponder 37 | @property (strong, nonatomic) UIWindow *window; 38 | @end 39 | -------------------------------------------------------------------------------- /StyledTableViewCell-for-iOS.podspec: -------------------------------------------------------------------------------- 1 | # 2 | # Be sure to run `pod spec lint StyledTableViewCell-for-iOS.podspec' to ensure this is a 3 | # valid spec and to remove all comments including this before submitting the spec. 4 | # 5 | # To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html 6 | # To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/ 7 | # 8 | 9 | Pod::Spec.new do |s| 10 | s.name = "StyledTableViewCell-for-iOS" 11 | s.version = "1.1" 12 | s.summary = "Customize table view cell border and highlights" 13 | 14 | s.description = <<-DESC 15 | A longer description of StyledTableViewCell-for-iOS in Markdown format. 16 | 17 | * Think: Why did you write this? What is the focus? What does it do? 18 | * CocoaPods will be using this to generate tags, and improve search results. 19 | * Try to keep it short, snappy and to the point. 20 | * Finally, don't worry about the indent, CocoaPods strips it! 21 | DESC 22 | 23 | s.homepage = "https://github.com/honcheng/StyledTableViewCell-for-iOS" 24 | s.license = "MIT (example)" 25 | s.license = { :type => 'MIT', :file => 'LICENSE' } 26 | s.author = { "Muh Hon Cheng" => "honcheng@gmail.com" } 27 | s.social_media_url = "http://twitter.com/honcheng" 28 | s.source = { :git => "https://github.com/honcheng/StyledTableViewCell-for-iOS.git", :tag => "1.1" } 29 | s.platform = :ios 30 | s.source_files = 'StyledTableViewCell/' 31 | s.framework = 'QuartzCore' 32 | s.requires_arc = true 33 | end 34 | -------------------------------------------------------------------------------- /StyledTableViewCellDemo/StyledTableViewCellDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2012 Muh Hon Cheng 3 | * Created by honcheng on 28/2/12. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining 6 | * a copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sublicense, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject 11 | * to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT 17 | * WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 18 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR 20 | * PURPOSE AND NONINFRINGEMENT. IN NO EVENT 21 | * SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 22 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 24 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR 25 | * IN CONNECTION WITH THE SOFTWARE OR 26 | * THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * @author Muh Hon Cheng 29 | * @copyright 2012 Muh Hon Cheng 30 | * @version 31 | * 32 | */ 33 | 34 | #import "AppDelegate.h" 35 | #import "StyleListTableViewController.h" 36 | 37 | @implementation AppDelegate 38 | 39 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 40 | { 41 | self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 42 | 43 | StyleListTableViewController *demo = [[StyleListTableViewController alloc] init]; 44 | UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:demo]; 45 | [self.window setRootViewController:navController]; 46 | 47 | self.window.backgroundColor = [UIColor whiteColor]; 48 | [self.window makeKeyAndVisible]; 49 | return YES; 50 | } 51 | 52 | 53 | @end 54 | -------------------------------------------------------------------------------- /StyledTableViewCellDemo/StyledTableViewCellDemo/DemoTableViewController.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2012 Muh Hon Cheng 3 | * Created by honcheng on 3/4/12. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining 6 | * a copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sublicense, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject 11 | * to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT 17 | * WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 18 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR 20 | * PURPOSE AND NONINFRINGEMENT. IN NO EVENT 21 | * SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 22 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 24 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR 25 | * IN CONNECTION WITH THE SOFTWARE OR 26 | * THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * @author Muh Hon Cheng 29 | * @copyright 2012 Muh Hon Cheng 30 | * @version 31 | * 32 | */ 33 | 34 | #import 35 | 36 | typedef enum 37 | { 38 | DemoTableViewStyle_Cyan = 0, 39 | DemoTableViewStyle_Green = 1, 40 | DemoTableViewStyle_Purple = 2, 41 | DemoTableViewStyle_Yellow = 3, 42 | DemoTableViewStyle_2Colors = 4, 43 | DemoTableViewStyle_3Colors = 5, 44 | DemoTableViewStyle_DottedLine = 6, 45 | DemoTableViewStyle_Dashes = 7, 46 | DemoTableViewStyle_GradientVertical = 8, 47 | DemoTableViewStyle_GradientHorizontal = 9, 48 | DemoTableViewStyle_GradientDiagonalTopLeftToBottomRight = 10, 49 | DemoTableViewStyle_GradientDiagonalBottomLeftToTopRight = 11, 50 | } DemoTableViewStyle; 51 | 52 | @interface DemoTableViewController : UITableViewController 53 | @property (assign, nonatomic) DemoTableViewStyle demoTableViewStyle; 54 | @end 55 | -------------------------------------------------------------------------------- /StyledTableViewCellDemo/StyledTableViewCellDemo.xcodeproj/xcuserdata/honcheng.xcuserdatad/xcschemes/StyledTableViewCellDemo.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 51 | 52 | 58 | 59 | 60 | 61 | 62 | 63 | 69 | 70 | 76 | 77 | 78 | 79 | 81 | 82 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /StyledTableViewCell/StyledTableViewCell.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2012 Muh Hon Cheng 3 | * Created by honcheng on 28/2/12. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining 6 | * a copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sublicense, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject 11 | * to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT 17 | * WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 18 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR 20 | * PURPOSE AND NONINFRINGEMENT. IN NO EVENT 21 | * SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 22 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 24 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR 25 | * IN CONNECTION WITH THE SOFTWARE OR 26 | * THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * @author Muh Hon Cheng 29 | * @copyright 2012 Muh Hon Cheng 30 | * @version 31 | * 32 | */ 33 | 34 | #import 35 | 36 | // available selection colors 37 | typedef enum 38 | { 39 | StyledTableViewCellSelectionStyleDefault = 0, 40 | StyledTableViewCellSelectionStyleCyan = 1, 41 | StyledTableViewCellSelectionStyleGreen = 2, 42 | StyledTableViewCellSelectionStyleYellow = 3, 43 | StyledTableViewCellSelectionStylePurple = 4, 44 | } StyledTableViewCellSelectionStyle; 45 | 46 | typedef enum 47 | { 48 | StyledTableViewCellSelectionGradientDirectionVertical = 0, 49 | StyledTableViewCellSelectionGradientDirectionHorizontal = 1, 50 | StyledTableViewCellSelectionGradientDirectionDiagonalTopLeftToBottomRight = 2, 51 | StyledTableViewCellSelectionGradientDirectionDiagonalBottomLeftToTopRight = 3, 52 | } StyledTableViewCellSelectionGradientDirection; 53 | 54 | // background view 55 | // use to draw separator line 56 | @interface StyledTableViewCellBackgroundView : UIView 57 | @property (nonatomic, strong) UIColor *separatorColor; 58 | @property (nonatomic, assign) int dashWidth, dashGap, dashStroke; 59 | @end 60 | 61 | // selected background view 62 | // subclass of background view, set the colors 63 | @interface StyledTableViewCellSelectedBackgroundView : StyledTableViewCellBackgroundView 64 | @property (nonatomic, strong) NSArray *selectedBackgroundGradientColors; 65 | @property (nonatomic, assign) StyledTableViewCellSelectionGradientDirection gradientDirection; 66 | @end 67 | 68 | @interface StyledTableViewCell : UITableViewCell 69 | 70 | // set the separator line property 71 | @property (nonatomic, assign) int dashWidth; 72 | @property (nonatomic, assign) int dashGap; 73 | @property (nonatomic, assign) int dashStroke; 74 | - (void)setDashWidth:(int)dashWidth dashGap:(int)dashGap dashStroke:(int)dashStroke; 75 | - (void)setSeparatorColor:(UIColor*)separatorColor; 76 | 77 | // set the selected background color by providing an array of colors 78 | // requires a list of CGColor 79 | - (void)setSelectedBackgroundViewGradientColors:(NSArray*)colors; 80 | // set the selected background color gradient direction 81 | - (void)setSelectionGradientDirection:(StyledTableViewCellSelectionGradientDirection)direction; 82 | 83 | // set the selected background color using style 84 | @property (nonatomic, assign, setter = setStyledTableViewCellSelectionStyle:) StyledTableViewCellSelectionStyle styledTableViewCellSelectionStyle; 85 | 86 | @end 87 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | StyledTableViewCell for iOS 3 | ================= 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | Customize table view cell border and highlight colors. 16 | Only supports UITableViewStylePlain 17 | 18 | Features 19 | ------- 20 | 21 | * Custom highlight colors for table view cells 22 | * Highlights supports gradient of multiple colors and directions 23 | 24 | Usage 25 | ----- 26 | 27 | 1) Subclass StyledTableViewCell 28 | 29 | 2) Set UITableView separator to none to hide the default separator 30 | 31 | [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone]; 32 | 33 | 3) Use setDashWidth:dashGap:dashStroke: to configure custom cell separators 34 | 35 | e.g. dashes for separators 36 | 37 | [self setDashWidth:5 dashGap:3 dashStroke:1]; 38 | 39 | 40 | 41 | e.g. dotted-lines for separators 42 | 43 | [self setDashWidth:1 dashGap:3 dashStroke:1]; 44 | 45 | 4) Set UITableView separator color to set the custom separator color 46 | 47 | [self.tableView setSeparatorColor:[UIColor colorWithWhite:0.7 alpha:1]]; 48 | 49 | 50 | 51 | 5) Use setStyledTableViewCellSelectionStyle: to set background colors of cell when selected, using preset colors 52 | 53 | [self setStyledTableViewCellSelectionStyle:StyledTableViewCellSelectionStylePurple]; 54 | 55 | 56 | 57 | 6) Use setSelectedBackgroundGradientColors: to set background colors of cell when selected, using custom gradients 58 | 59 | e.g. gradient of 2 colors 60 | 61 | NSMutableArray *colors = [NSMutableArray array]; 62 | [colors addObject:(id)[[UIColor colorWithRed:255/255.0 green:234/255.0 blue:0 alpha:1] CGColor]]; 63 | [colors addObject:(id)[[UIColor colorWithRed:255/255.0 green:174/255.0 blue:0 alpha:1] CGColor]]; 64 | [self setSelectedBackgroundViewGradientColors:colors]; 65 | 66 | 67 | 68 | e.g. gradient of 3 colors 69 | 70 | NSMutableArray *colors = [NSMutableArray array]; 71 | [colors addObject:(id)[[UIColor colorWithRed:255/255.0 green:174/255.0 blue:0 alpha:1] CGColor]]; 72 | [colors addObject:(id)[[UIColor colorWithRed:255/255.0 green:234/255.0 blue:0 alpha:1] CGColor]]; 73 | [colors addObject:(id)[[UIColor colorWithRed:255/255.0 green:174/255.0 blue:0 alpha:1] CGColor]]; 74 | [self setSelectedBackgroundViewGradientColors:colors]; 75 | 76 | 77 | 78 | 7) Use setSelectionGradientDirection: to set direction of gradient when cell is selected 79 | 80 | e.g. horizontal gradient 81 | 82 | [self setSelectionGradientDirection:StyledTableViewCellSelectionGradientDirectionHorizontal]; 83 | 84 | 85 | 86 | e.g. diagonally from bottom left to top right 87 | 88 | [self setSelectionGradientDirection:StyledTableViewCellSelectionGradientDirectionDiagonalBottomLeftToTopRight]; 89 | 90 | 91 | 92 | e.g. diagonally from top left to bottom right 93 | 94 | [self setSelectionGradientDirection:StyledTableViewCellSelectionGradientDirectionDiagonalTopLeftToBottomRight]; 95 | 96 | 97 | 98 | Supports 99 | -------- 100 | Only supports UITableViewStylePlain. 101 | 102 | Requirements 103 | ------------ 104 | 105 | * QuartzCore framework 106 | * This project uses ARC. If you are not using ARC in your project, add '-fobjc-arc' as a compiler flag for all the files in this project. 107 | * XCode 4.4 and newer (auto-synthesis required) 108 | 109 | Contact 110 | ------ 111 | 112 | [twitter.com/honcheng](http://twitter.com/honcheng) 113 | [honcheng.com](http://honcheng.com) 114 | 115 | ![](http://www.cocoacontrols.com/analytics/honcheng/styledtableviewcell-for-ios.png) 116 | -------------------------------------------------------------------------------- /StyledTableViewCellDemo/StyledTableViewCellDemo/StyleListTableViewController.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2012 Muh Hon Cheng 3 | * Created by honcheng on 3/4/12. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining 6 | * a copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sublicense, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject 11 | * to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT 17 | * WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 18 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR 20 | * PURPOSE AND NONINFRINGEMENT. IN NO EVENT 21 | * SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 22 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 24 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR 25 | * IN CONNECTION WITH THE SOFTWARE OR 26 | * THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * @author Muh Hon Cheng 29 | * @copyright 2012 Muh Hon Cheng 30 | * @version 31 | * 32 | */ 33 | 34 | #import "StyleListTableViewController.h" 35 | #import "DemoTableViewController.h" 36 | 37 | @implementation StyleListTableViewController 38 | 39 | - (id)initWithStyle:(UITableViewStyle)style 40 | { 41 | self = [super initWithStyle:style]; 42 | if (self) { 43 | [self setTitle:@"StyledTableViewCell Demo"]; 44 | [self.tableView setRowHeight:60.0]; 45 | } 46 | return self; 47 | } 48 | 49 | - (NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section 50 | { 51 | if (section==0) return @"Preset Selection Colors"; 52 | else if (section==1) return @"Custom Selection Colors"; 53 | else if (section==2) return @"Separator Lines"; 54 | else if (section==3) return @"Gradient Directions"; 55 | else return nil; 56 | } 57 | 58 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 59 | { 60 | return 4; 61 | } 62 | 63 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 64 | { 65 | if (section==0) return 4; 66 | else if (section==1) return 2; 67 | else if (section==2) return 2; 68 | else if (section==3) return 4; 69 | else return 0; 70 | } 71 | 72 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 73 | { 74 | static NSString *CellIdentifier = @"UITableViewCell"; 75 | UITableViewCell *cell = (UITableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 76 | if (!cell) 77 | { 78 | cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 79 | [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator]; 80 | [cell.textLabel setFont:[UIFont boldSystemFontOfSize:14]]; 81 | } 82 | 83 | if (indexPath.section==0) 84 | { 85 | if (indexPath.row==0) 86 | { 87 | [cell.textLabel setText:@"CYAN"]; 88 | } 89 | else if (indexPath.row==1) 90 | { 91 | [cell.textLabel setText:@"GREEN"]; 92 | } 93 | else if (indexPath.row==2) 94 | { 95 | [cell.textLabel setText:@"PURPLE"]; 96 | } 97 | else if (indexPath.row==3) 98 | { 99 | [cell.textLabel setText:@"YELLOW"]; 100 | } 101 | } 102 | else if (indexPath.section==1) 103 | { 104 | if (indexPath.row==0) 105 | { 106 | [cell.textLabel setText:@"CUSTOM - 2 colors"]; 107 | } 108 | else if (indexPath.row==1) 109 | { 110 | [cell.textLabel setText:@"CUSTOM - 3 colors"]; 111 | } 112 | } 113 | else if (indexPath.section==2) 114 | { 115 | if (indexPath.row==0) 116 | { 117 | [cell.textLabel setText:@"SEPARATOR - DOTTED LINE"]; 118 | } 119 | else if (indexPath.row>=1) 120 | { 121 | [cell.textLabel setText:@"SEPARATOR - DASHES"]; 122 | } 123 | } 124 | else if (indexPath.section==3) 125 | { 126 | if (indexPath.row==0) 127 | { 128 | [cell.textLabel setText:@"VERTICAL (DEFAULT)"]; 129 | } 130 | else if (indexPath.row==1) 131 | { 132 | [cell.textLabel setText:@"HORIZONTAL"]; 133 | } 134 | else if (indexPath.row==2) 135 | { 136 | [cell.textLabel setText:@"DIAGONAL - TOP LEFT TO BOTTOM RIGHT"]; 137 | } 138 | else if (indexPath.row==3) 139 | { 140 | [cell.textLabel setText:@"DIAGONAL - BOTTOM LEFT TO TOP RIGHT"]; 141 | } 142 | } 143 | 144 | 145 | return cell; 146 | } 147 | 148 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 149 | { 150 | DemoTableViewController *demo = [[DemoTableViewController alloc] initWithStyle:UITableViewStylePlain]; 151 | 152 | if (indexPath.section==0) 153 | { 154 | if (indexPath.row==0) 155 | { 156 | [demo setDemoTableViewStyle:DemoTableViewStyle_Cyan]; 157 | } 158 | else if (indexPath.row==1) 159 | { 160 | [demo setDemoTableViewStyle:DemoTableViewStyle_Green]; 161 | } 162 | else if (indexPath.row==2) 163 | { 164 | [demo setDemoTableViewStyle:DemoTableViewStyle_Purple]; 165 | } 166 | else if (indexPath.row==3) 167 | { 168 | [demo setDemoTableViewStyle:DemoTableViewStyle_Yellow]; 169 | } 170 | } 171 | else if (indexPath.section==1) 172 | { 173 | if (indexPath.row==0) 174 | { 175 | [demo setDemoTableViewStyle:DemoTableViewStyle_2Colors]; 176 | } 177 | else if (indexPath.row==1) 178 | { 179 | [demo setDemoTableViewStyle:DemoTableViewStyle_3Colors]; 180 | } 181 | } 182 | else if (indexPath.section==2) 183 | { 184 | if (indexPath.row==0) 185 | { 186 | [demo setDemoTableViewStyle:DemoTableViewStyle_DottedLine]; 187 | } 188 | else if (indexPath.row==1) 189 | { 190 | [demo setDemoTableViewStyle:DemoTableViewStyle_Dashes]; 191 | } 192 | } 193 | else if (indexPath.section==3) 194 | { 195 | if (indexPath.row==0) 196 | { 197 | [demo setDemoTableViewStyle:DemoTableViewStyle_GradientVertical]; 198 | } 199 | else if (indexPath.row==1) 200 | { 201 | [demo setDemoTableViewStyle:DemoTableViewStyle_GradientHorizontal]; 202 | } 203 | else if (indexPath.row==2) 204 | { 205 | [demo setDemoTableViewStyle:DemoTableViewStyle_GradientDiagonalTopLeftToBottomRight]; 206 | } 207 | else if (indexPath.row==3) 208 | { 209 | [demo setDemoTableViewStyle:DemoTableViewStyle_GradientDiagonalBottomLeftToTopRight]; 210 | } 211 | } 212 | 213 | UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 214 | [demo setTitle:[cell textLabel].text]; 215 | 216 | [self.navigationController pushViewController:demo animated:YES]; 217 | } 218 | 219 | @end 220 | -------------------------------------------------------------------------------- /StyledTableViewCell/StyledTableViewCell.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2012 Muh Hon Cheng 3 | * Created by honcheng on 28/2/12. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining 6 | * a copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sublicense, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject 11 | * to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT 17 | * WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 18 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR 20 | * PURPOSE AND NONINFRINGEMENT. IN NO EVENT 21 | * SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 22 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 24 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR 25 | * IN CONNECTION WITH THE SOFTWARE OR 26 | * THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * @author Muh Hon Cheng 29 | * @copyright 2012 Muh Hon Cheng 30 | * @version 31 | * 32 | */ 33 | 34 | #import "StyledTableViewCell.h" 35 | #import 36 | 37 | @implementation StyledTableViewCellBackgroundView 38 | 39 | - (BOOL) isOpaque 40 | { 41 | return YES; 42 | } 43 | 44 | - (id)initWithFrame:(CGRect)frame 45 | { 46 | if (self = [super initWithFrame:frame]) 47 | { 48 | [self setBackgroundColor:[UIColor whiteColor]]; 49 | } 50 | return self; 51 | } 52 | 53 | - (void)drawRect:(CGRect)rect 54 | { 55 | // if no separator color is set, use this 56 | if (!self.separatorColor) 57 | { 58 | [self setSeparatorColor:[UIColor colorWithRed:190/255.0 green:183/255.0 blue:145/255.0 alpha:1]]; 59 | } 60 | 61 | CGContextRef c = UIGraphicsGetCurrentContext(); 62 | CGContextSetStrokeColorWithColor(c, [_separatorColor CGColor]); 63 | CGContextSetLineWidth(c, self.dashStroke); 64 | 65 | // if gap==0, draw a continuous line 66 | if (self.dashGap>0) 67 | { 68 | const CGFloat dash[] = { self.dashWidth , self.dashGap}; 69 | // float dash[2] = { self.dashWidth , self.dashGap}; 70 | CGContextSetLineDash(c,0,dash,2); 71 | } 72 | 73 | CGContextBeginPath(c); 74 | CGContextMoveToPoint(c, 0.0f, rect.size.height-self.dashStroke/2); 75 | CGContextAddLineToPoint(c, rect.size.width, rect.size.height-self.dashStroke/2); 76 | CGContextStrokePath(c); 77 | } 78 | 79 | @end 80 | 81 | @interface StyledTableViewCellSelectedBackgroundView() 82 | @property (nonatomic, assign) float prevLayerHeight; 83 | @end 84 | 85 | @implementation StyledTableViewCellSelectedBackgroundView 86 | 87 | - (void)drawRect:(CGRect)rect 88 | { 89 | if (self.frame.size.height!=self.prevLayerHeight) 90 | { 91 | for (int i=0; i<[self.layer.sublayers count]; i++) 92 | { 93 | id layer = [self.layer.sublayers objectAtIndex:i]; 94 | if ([layer isKindOfClass:[CAGradientLayer class]]) 95 | { 96 | [layer removeFromSuperlayer]; 97 | } 98 | } 99 | } 100 | 101 | if (!self.selectedBackgroundGradientColors) 102 | { 103 | // use this color if no gradient color exists 104 | self.selectedBackgroundGradientColors = @[(id)[[UIColor colorWithWhite:0.9 alpha:1] CGColor],(id)[[UIColor colorWithWhite:0.95 alpha:1] CGColor]]; 105 | } 106 | else if ([self.selectedBackgroundGradientColors count]==1) 107 | { 108 | // at least 2 colors are required to set gradient 109 | // if only one color provided, use the same color for both extremes of the gradient 110 | self.selectedBackgroundGradientColors = @[[self.selectedBackgroundGradientColors objectAtIndex:0],[self.selectedBackgroundGradientColors objectAtIndex:0]]; 111 | } 112 | 113 | // draw the selected background gradient 114 | CAGradientLayer *gradient = [CAGradientLayer layer]; 115 | [gradient setFrame:CGRectMake(0,0,self.frame.size.width,self.frame.size.height-self.dashStroke)]; 116 | if (self.gradientDirection==StyledTableViewCellSelectionGradientDirectionVertical) 117 | { 118 | [gradient setStartPoint:CGPointMake(0, 0)]; 119 | [gradient setEndPoint:CGPointMake(0, 1)]; 120 | } 121 | else if (self.gradientDirection==StyledTableViewCellSelectionGradientDirectionHorizontal) 122 | { 123 | [gradient setStartPoint:CGPointMake(0, 0)]; 124 | [gradient setEndPoint:CGPointMake(1, 0)]; 125 | } 126 | else if (self.gradientDirection==StyledTableViewCellSelectionGradientDirectionDiagonalTopLeftToBottomRight) 127 | { 128 | [gradient setStartPoint:CGPointMake(0, 0)]; 129 | [gradient setEndPoint:CGPointMake(1, 1)]; 130 | } 131 | else if (self.gradientDirection==StyledTableViewCellSelectionGradientDirectionDiagonalBottomLeftToTopRight) 132 | { 133 | [gradient setStartPoint:CGPointMake(0, 1)]; 134 | [gradient setEndPoint:CGPointMake(1, 0)]; 135 | } 136 | [self.layer insertSublayer:gradient atIndex:0]; 137 | [gradient setColors:self.selectedBackgroundGradientColors]; 138 | 139 | [super drawRect:rect]; 140 | 141 | self.prevLayerHeight = self.frame.size.height; 142 | } 143 | 144 | @end 145 | 146 | @implementation StyledTableViewCell 147 | 148 | - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier 149 | { 150 | self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 151 | if (self) { 152 | 153 | // set the background view 154 | StyledTableViewCellBackgroundView *backgroundView = [[StyledTableViewCellBackgroundView alloc] initWithFrame:CGRectZero]; 155 | [self setBackgroundView:backgroundView]; 156 | 157 | // set the selected background view 158 | StyledTableViewCellSelectedBackgroundView *selectedBackgroundView = [[StyledTableViewCellSelectedBackgroundView alloc] initWithFrame:CGRectZero]; 159 | [self setSelectedBackgroundView:selectedBackgroundView]; 160 | 161 | // clear the background color of text label because text label background overlaps with separator 162 | [self.textLabel setBackgroundColor:[UIColor clearColor]]; 163 | 164 | [self setDashWidth:1 dashGap:0 dashStroke:1]; 165 | } 166 | return self; 167 | } 168 | 169 | - (void)layoutSubviews 170 | { 171 | [super layoutSubviews]; 172 | [self.selectedBackgroundView setNeedsDisplay]; 173 | } 174 | 175 | // set the selected background color by providing an array of colors 176 | // requires a list of CGColor 177 | - (void)setSelectedBackgroundViewGradientColors:(NSArray*)colors 178 | { 179 | [(StyledTableViewCellSelectedBackgroundView*)self.selectedBackgroundView setSelectedBackgroundGradientColors:colors]; 180 | } 181 | 182 | // set the selected background color using style 183 | - (void)setStyledTableViewCellSelectionStyle:(StyledTableViewCellSelectionStyle)style 184 | { 185 | _styledTableViewCellSelectionStyle = style; 186 | 187 | NSMutableArray *colors = [NSMutableArray array]; 188 | if (_styledTableViewCellSelectionStyle==StyledTableViewCellSelectionStyleCyan) 189 | { 190 | [colors addObject:(id)[[UIColor colorWithRed:134/255.0 green:214/255.0 blue:231/255.0 alpha:1] CGColor]]; 191 | [colors addObject:(id)[[UIColor colorWithRed:111/255.0 green:198/255.0 blue:217/255.0 alpha:1] CGColor]]; 192 | } 193 | else if (_styledTableViewCellSelectionStyle==StyledTableViewCellSelectionStyleGreen) 194 | { 195 | [colors addObject:(id)[[UIColor colorWithRed:124/255.0 green:243/255.0 blue:127/255.0 alpha:1] CGColor]]; 196 | [colors addObject:(id)[[UIColor colorWithRed:111/255.0 green:222/255.0 blue:114/255.0 alpha:1] CGColor]]; 197 | } 198 | else if (_styledTableViewCellSelectionStyle==StyledTableViewCellSelectionStyleYellow) 199 | { 200 | [colors addObject:(id)[[UIColor colorWithRed:248/255.0 green:242/255.0 blue:145/255.0 alpha:1] CGColor]]; 201 | [colors addObject:(id)[[UIColor colorWithRed:243/255.0 green:236/255.0 blue:124/255.0 alpha:1] CGColor]]; 202 | } 203 | else if (_styledTableViewCellSelectionStyle==StyledTableViewCellSelectionStylePurple) 204 | { 205 | [colors addObject:(id)[[UIColor colorWithRed:217/255.0 green:143/255.0 blue:230/255.0 alpha:1] CGColor]]; 206 | [colors addObject:(id)[[UIColor colorWithRed:190/255.0 green:110/255.0 blue:204/255.0 alpha:1] CGColor]]; 207 | } 208 | else 209 | { 210 | [colors addObject:(id)[[UIColor colorWithWhite:0.95 alpha:1] CGColor]]; 211 | [colors addObject:(id)[[UIColor colorWithWhite:0.9 alpha:1] CGColor]]; 212 | } 213 | [self setSelectedBackgroundViewGradientColors:colors]; 214 | } 215 | 216 | // set the selected background color gradient direction 217 | - (void)setSelectionGradientDirection:(StyledTableViewCellSelectionGradientDirection)direction 218 | { 219 | [(StyledTableViewCellSelectedBackgroundView*)self.selectedBackgroundView setGradientDirection:direction]; 220 | } 221 | 222 | // overrides the method that changes the cell separator color 223 | // there is no need to call this method 224 | - (void)setSeparatorColor:(UIColor*)separatorColor 225 | { 226 | [(StyledTableViewCellSelectedBackgroundView*)self.selectedBackgroundView setSeparatorColor:separatorColor]; 227 | [(StyledTableViewCellBackgroundView*)self.backgroundView setSeparatorColor:separatorColor]; 228 | } 229 | 230 | // set the separator property including width, gap and stroke width 231 | - (void)setDashWidth:(int)dashWidth dashGap:(int)dashGap dashStroke:(int)dashStroke 232 | { 233 | [self setDashWidth:dashWidth]; 234 | [self setDashGap:dashGap]; 235 | [self setDashStroke:dashStroke]; 236 | } 237 | 238 | // set the separator dash gap 239 | // separator is a continuous line if gap is 0 240 | - (void)setDashGap:(int)dashGap 241 | { 242 | _dashGap = dashGap; 243 | [(StyledTableViewCellSelectedBackgroundView*)self.selectedBackgroundView setDashGap:self.dashGap]; 244 | [(StyledTableViewCellBackgroundView*)self.backgroundView setDashGap:self.dashGap]; 245 | } 246 | 247 | // set the separator stroke width 248 | - (void)setDashStroke:(int)dashStroke 249 | { 250 | _dashStroke = dashStroke; 251 | [(StyledTableViewCellSelectedBackgroundView*)self.selectedBackgroundView setDashStroke:self.dashStroke]; 252 | [(StyledTableViewCellBackgroundView*)self.backgroundView setDashStroke:self.dashStroke]; 253 | } 254 | 255 | // set the separator dash width 256 | - (void)setDashWidth:(int)dashWidth 257 | { 258 | _dashWidth = dashWidth; 259 | [(StyledTableViewCellSelectedBackgroundView*)self.selectedBackgroundView setDashWidth:self.dashWidth]; 260 | [(StyledTableViewCellBackgroundView*)self.backgroundView setDashWidth:self.dashWidth]; 261 | } 262 | 263 | @end 264 | -------------------------------------------------------------------------------- /StyledTableViewCellDemo/StyledTableViewCellDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | F8DF552814FC78310086395D /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F8DF552714FC78310086395D /* UIKit.framework */; }; 11 | F8DF552A14FC78310086395D /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F8DF552914FC78310086395D /* Foundation.framework */; }; 12 | F8DF552C14FC78310086395D /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F8DF552B14FC78310086395D /* CoreGraphics.framework */; }; 13 | F8DF553214FC78310086395D /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = F8DF553014FC78310086395D /* InfoPlist.strings */; }; 14 | F8DF553414FC78320086395D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = F8DF553314FC78320086395D /* main.m */; }; 15 | F8DF553814FC78320086395D /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = F8DF553714FC78320086395D /* AppDelegate.m */; }; 16 | F8DF554114FC78C80086395D /* DemoTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F8DF554014FC78C80086395D /* DemoTableViewController.m */; }; 17 | F8DF554414FC799B0086395D /* StyledTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = F8DF554314FC799B0086395D /* StyledTableViewCell.m */; }; 18 | F8DF554A14FC79CB0086395D /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F8DF554914FC79CB0086395D /* QuartzCore.framework */; }; 19 | F8E5A7B4152A9D1F002ABE23 /* StyleListTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F8E5A7B3152A9D1F002ABE23 /* StyleListTableViewController.m */; }; 20 | /* End PBXBuildFile section */ 21 | 22 | /* Begin PBXFileReference section */ 23 | F8DF552314FC78310086395D /* StyledTableViewCellDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = StyledTableViewCellDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 24 | F8DF552714FC78310086395D /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 25 | F8DF552914FC78310086395D /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 26 | F8DF552B14FC78310086395D /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; 27 | F8DF552F14FC78310086395D /* StyledTableViewCellDemo-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "StyledTableViewCellDemo-Info.plist"; sourceTree = ""; }; 28 | F8DF553114FC78310086395D /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 29 | F8DF553314FC78320086395D /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 30 | F8DF553514FC78320086395D /* StyledTableViewCellDemo-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "StyledTableViewCellDemo-Prefix.pch"; sourceTree = ""; }; 31 | F8DF553614FC78320086395D /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 32 | F8DF553714FC78320086395D /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 33 | F8DF553F14FC78C80086395D /* DemoTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DemoTableViewController.h; sourceTree = ""; }; 34 | F8DF554014FC78C80086395D /* DemoTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DemoTableViewController.m; sourceTree = ""; }; 35 | F8DF554214FC799B0086395D /* StyledTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StyledTableViewCell.h; sourceTree = ""; }; 36 | F8DF554314FC799B0086395D /* StyledTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = StyledTableViewCell.m; sourceTree = ""; }; 37 | F8DF554914FC79CB0086395D /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; 38 | F8E5A7B2152A9D1F002ABE23 /* StyleListTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StyleListTableViewController.h; sourceTree = ""; }; 39 | F8E5A7B3152A9D1F002ABE23 /* StyleListTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = StyleListTableViewController.m; sourceTree = ""; }; 40 | /* End PBXFileReference section */ 41 | 42 | /* Begin PBXFrameworksBuildPhase section */ 43 | F8DF552014FC78310086395D /* Frameworks */ = { 44 | isa = PBXFrameworksBuildPhase; 45 | buildActionMask = 2147483647; 46 | files = ( 47 | F8DF554A14FC79CB0086395D /* QuartzCore.framework in Frameworks */, 48 | F8DF552814FC78310086395D /* UIKit.framework in Frameworks */, 49 | F8DF552A14FC78310086395D /* Foundation.framework in Frameworks */, 50 | F8DF552C14FC78310086395D /* CoreGraphics.framework in Frameworks */, 51 | ); 52 | runOnlyForDeploymentPostprocessing = 0; 53 | }; 54 | /* End PBXFrameworksBuildPhase section */ 55 | 56 | /* Begin PBXGroup section */ 57 | F8DF551814FC78310086395D = { 58 | isa = PBXGroup; 59 | children = ( 60 | F8DF552D14FC78310086395D /* StyledTableViewCellDemo */, 61 | F8DF552614FC78310086395D /* Frameworks */, 62 | F8DF552414FC78310086395D /* Products */, 63 | ); 64 | sourceTree = ""; 65 | }; 66 | F8DF552414FC78310086395D /* Products */ = { 67 | isa = PBXGroup; 68 | children = ( 69 | F8DF552314FC78310086395D /* StyledTableViewCellDemo.app */, 70 | ); 71 | name = Products; 72 | sourceTree = ""; 73 | }; 74 | F8DF552614FC78310086395D /* Frameworks */ = { 75 | isa = PBXGroup; 76 | children = ( 77 | F8DF554914FC79CB0086395D /* QuartzCore.framework */, 78 | F8DF552714FC78310086395D /* UIKit.framework */, 79 | F8DF552914FC78310086395D /* Foundation.framework */, 80 | F8DF552B14FC78310086395D /* CoreGraphics.framework */, 81 | ); 82 | name = Frameworks; 83 | sourceTree = ""; 84 | }; 85 | F8DF552D14FC78310086395D /* StyledTableViewCellDemo */ = { 86 | isa = PBXGroup; 87 | children = ( 88 | F8DF553614FC78320086395D /* AppDelegate.h */, 89 | F8DF553714FC78320086395D /* AppDelegate.m */, 90 | F8DF553F14FC78C80086395D /* DemoTableViewController.h */, 91 | F8DF554014FC78C80086395D /* DemoTableViewController.m */, 92 | F8E5A7B2152A9D1F002ABE23 /* StyleListTableViewController.h */, 93 | F8E5A7B3152A9D1F002ABE23 /* StyleListTableViewController.m */, 94 | F8DF553E14FC78600086395D /* StyledTableViewCell */, 95 | F8DF552E14FC78310086395D /* Supporting Files */, 96 | ); 97 | path = StyledTableViewCellDemo; 98 | sourceTree = ""; 99 | }; 100 | F8DF552E14FC78310086395D /* Supporting Files */ = { 101 | isa = PBXGroup; 102 | children = ( 103 | F8DF552F14FC78310086395D /* StyledTableViewCellDemo-Info.plist */, 104 | F8DF553014FC78310086395D /* InfoPlist.strings */, 105 | F8DF553314FC78320086395D /* main.m */, 106 | F8DF553514FC78320086395D /* StyledTableViewCellDemo-Prefix.pch */, 107 | ); 108 | name = "Supporting Files"; 109 | sourceTree = ""; 110 | }; 111 | F8DF553E14FC78600086395D /* StyledTableViewCell */ = { 112 | isa = PBXGroup; 113 | children = ( 114 | F8DF554214FC799B0086395D /* StyledTableViewCell.h */, 115 | F8DF554314FC799B0086395D /* StyledTableViewCell.m */, 116 | ); 117 | name = StyledTableViewCell; 118 | path = ../../StyledTableViewCell; 119 | sourceTree = ""; 120 | }; 121 | /* End PBXGroup section */ 122 | 123 | /* Begin PBXNativeTarget section */ 124 | F8DF552214FC78310086395D /* StyledTableViewCellDemo */ = { 125 | isa = PBXNativeTarget; 126 | buildConfigurationList = F8DF553B14FC78320086395D /* Build configuration list for PBXNativeTarget "StyledTableViewCellDemo" */; 127 | buildPhases = ( 128 | F8DF551F14FC78310086395D /* Sources */, 129 | F8DF552014FC78310086395D /* Frameworks */, 130 | F8DF552114FC78310086395D /* Resources */, 131 | ); 132 | buildRules = ( 133 | ); 134 | dependencies = ( 135 | ); 136 | name = StyledTableViewCellDemo; 137 | productName = StyledTableViewCellDemo; 138 | productReference = F8DF552314FC78310086395D /* StyledTableViewCellDemo.app */; 139 | productType = "com.apple.product-type.application"; 140 | }; 141 | /* End PBXNativeTarget section */ 142 | 143 | /* Begin PBXProject section */ 144 | F8DF551A14FC78310086395D /* Project object */ = { 145 | isa = PBXProject; 146 | attributes = { 147 | LastUpgradeCheck = 0430; 148 | ORGANIZATIONNAME = "honcheng@gmail.com"; 149 | }; 150 | buildConfigurationList = F8DF551D14FC78310086395D /* Build configuration list for PBXProject "StyledTableViewCellDemo" */; 151 | compatibilityVersion = "Xcode 3.2"; 152 | developmentRegion = English; 153 | hasScannedForEncodings = 0; 154 | knownRegions = ( 155 | en, 156 | ); 157 | mainGroup = F8DF551814FC78310086395D; 158 | productRefGroup = F8DF552414FC78310086395D /* Products */; 159 | projectDirPath = ""; 160 | projectRoot = ""; 161 | targets = ( 162 | F8DF552214FC78310086395D /* StyledTableViewCellDemo */, 163 | ); 164 | }; 165 | /* End PBXProject section */ 166 | 167 | /* Begin PBXResourcesBuildPhase section */ 168 | F8DF552114FC78310086395D /* Resources */ = { 169 | isa = PBXResourcesBuildPhase; 170 | buildActionMask = 2147483647; 171 | files = ( 172 | F8DF553214FC78310086395D /* InfoPlist.strings in Resources */, 173 | ); 174 | runOnlyForDeploymentPostprocessing = 0; 175 | }; 176 | /* End PBXResourcesBuildPhase section */ 177 | 178 | /* Begin PBXSourcesBuildPhase section */ 179 | F8DF551F14FC78310086395D /* Sources */ = { 180 | isa = PBXSourcesBuildPhase; 181 | buildActionMask = 2147483647; 182 | files = ( 183 | F8DF553414FC78320086395D /* main.m in Sources */, 184 | F8DF553814FC78320086395D /* AppDelegate.m in Sources */, 185 | F8DF554114FC78C80086395D /* DemoTableViewController.m in Sources */, 186 | F8DF554414FC799B0086395D /* StyledTableViewCell.m in Sources */, 187 | F8E5A7B4152A9D1F002ABE23 /* StyleListTableViewController.m in Sources */, 188 | ); 189 | runOnlyForDeploymentPostprocessing = 0; 190 | }; 191 | /* End PBXSourcesBuildPhase section */ 192 | 193 | /* Begin PBXVariantGroup section */ 194 | F8DF553014FC78310086395D /* InfoPlist.strings */ = { 195 | isa = PBXVariantGroup; 196 | children = ( 197 | F8DF553114FC78310086395D /* en */, 198 | ); 199 | name = InfoPlist.strings; 200 | sourceTree = ""; 201 | }; 202 | /* End PBXVariantGroup section */ 203 | 204 | /* Begin XCBuildConfiguration section */ 205 | F8DF553914FC78320086395D /* Debug */ = { 206 | isa = XCBuildConfiguration; 207 | buildSettings = { 208 | ALWAYS_SEARCH_USER_PATHS = NO; 209 | ARCHS = "$(ARCHS_STANDARD_32_BIT)"; 210 | CLANG_ENABLE_OBJC_ARC = YES; 211 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 212 | COPY_PHASE_STRIP = NO; 213 | GCC_C_LANGUAGE_STANDARD = gnu99; 214 | GCC_DYNAMIC_NO_PIC = NO; 215 | GCC_OPTIMIZATION_LEVEL = 0; 216 | GCC_PREPROCESSOR_DEFINITIONS = ( 217 | "DEBUG=1", 218 | "$(inherited)", 219 | ); 220 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 221 | GCC_VERSION = com.apple.compilers.llvm.clang.1_0; 222 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 223 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 224 | GCC_WARN_UNUSED_VARIABLE = YES; 225 | IPHONEOS_DEPLOYMENT_TARGET = 5.0; 226 | SDKROOT = iphoneos; 227 | }; 228 | name = Debug; 229 | }; 230 | F8DF553A14FC78320086395D /* Release */ = { 231 | isa = XCBuildConfiguration; 232 | buildSettings = { 233 | ALWAYS_SEARCH_USER_PATHS = NO; 234 | ARCHS = "$(ARCHS_STANDARD_32_BIT)"; 235 | CLANG_ENABLE_OBJC_ARC = YES; 236 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 237 | COPY_PHASE_STRIP = YES; 238 | GCC_C_LANGUAGE_STANDARD = gnu99; 239 | GCC_VERSION = com.apple.compilers.llvm.clang.1_0; 240 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 241 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 242 | GCC_WARN_UNUSED_VARIABLE = YES; 243 | IPHONEOS_DEPLOYMENT_TARGET = 5.0; 244 | OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1"; 245 | SDKROOT = iphoneos; 246 | VALIDATE_PRODUCT = YES; 247 | }; 248 | name = Release; 249 | }; 250 | F8DF553C14FC78320086395D /* Debug */ = { 251 | isa = XCBuildConfiguration; 252 | buildSettings = { 253 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 254 | GCC_PREFIX_HEADER = "StyledTableViewCellDemo/StyledTableViewCellDemo-Prefix.pch"; 255 | INFOPLIST_FILE = "StyledTableViewCellDemo/StyledTableViewCellDemo-Info.plist"; 256 | PRODUCT_NAME = "$(TARGET_NAME)"; 257 | WRAPPER_EXTENSION = app; 258 | }; 259 | name = Debug; 260 | }; 261 | F8DF553D14FC78320086395D /* Release */ = { 262 | isa = XCBuildConfiguration; 263 | buildSettings = { 264 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 265 | GCC_PREFIX_HEADER = "StyledTableViewCellDemo/StyledTableViewCellDemo-Prefix.pch"; 266 | INFOPLIST_FILE = "StyledTableViewCellDemo/StyledTableViewCellDemo-Info.plist"; 267 | PRODUCT_NAME = "$(TARGET_NAME)"; 268 | WRAPPER_EXTENSION = app; 269 | }; 270 | name = Release; 271 | }; 272 | /* End XCBuildConfiguration section */ 273 | 274 | /* Begin XCConfigurationList section */ 275 | F8DF551D14FC78310086395D /* Build configuration list for PBXProject "StyledTableViewCellDemo" */ = { 276 | isa = XCConfigurationList; 277 | buildConfigurations = ( 278 | F8DF553914FC78320086395D /* Debug */, 279 | F8DF553A14FC78320086395D /* Release */, 280 | ); 281 | defaultConfigurationIsVisible = 0; 282 | defaultConfigurationName = Release; 283 | }; 284 | F8DF553B14FC78320086395D /* Build configuration list for PBXNativeTarget "StyledTableViewCellDemo" */ = { 285 | isa = XCConfigurationList; 286 | buildConfigurations = ( 287 | F8DF553C14FC78320086395D /* Debug */, 288 | F8DF553D14FC78320086395D /* Release */, 289 | ); 290 | defaultConfigurationIsVisible = 0; 291 | defaultConfigurationName = Release; 292 | }; 293 | /* End XCConfigurationList section */ 294 | }; 295 | rootObject = F8DF551A14FC78310086395D /* Project object */; 296 | } 297 | -------------------------------------------------------------------------------- /StyledTableViewCellDemo/StyledTableViewCellDemo/DemoTableViewController.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2012 Muh Hon Cheng 3 | * Created by honcheng on 3/4/12. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining 6 | * a copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sublicense, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject 11 | * to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT 17 | * WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 18 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR 20 | * PURPOSE AND NONINFRINGEMENT. IN NO EVENT 21 | * SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 22 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 24 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR 25 | * IN CONNECTION WITH THE SOFTWARE OR 26 | * THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | * 28 | * @author Muh Hon Cheng 29 | * @copyright 2012 Muh Hon Cheng 30 | * @version 31 | * 32 | */ 33 | 34 | #import "DemoTableViewController.h" 35 | #import "StyledTableViewCell.h" 36 | 37 | @implementation DemoTableViewController 38 | 39 | - (id)initWithStyle:(UITableViewStyle)style 40 | { 41 | self = [super initWithStyle:style]; 42 | if (self) { 43 | [self.tableView setRowHeight:60.0]; 44 | [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone]; 45 | [self.tableView setSeparatorColor:[UIColor colorWithWhite:0.7 alpha:1]]; 46 | } 47 | return self; 48 | } 49 | 50 | 51 | #pragma mark - Table view data source 52 | 53 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 54 | { 55 | return 1; 56 | } 57 | 58 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 59 | { 60 | return 10; 61 | } 62 | 63 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 64 | { 65 | if (_demoTableViewStyle==DemoTableViewStyle_Cyan) 66 | { 67 | static NSString *CellIdentifier = @"CYAN"; 68 | StyledTableViewCell *cell = (StyledTableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 69 | if (!cell) 70 | { 71 | cell = [[StyledTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 72 | [cell.textLabel setTextColor:[UIColor grayColor]]; 73 | [cell.textLabel setFont:[UIFont boldSystemFontOfSize:14]]; 74 | [cell.textLabel setHighlightedTextColor:[UIColor whiteColor]]; 75 | [cell setStyledTableViewCellSelectionStyle:StyledTableViewCellSelectionStyleCyan]; 76 | 77 | } 78 | [cell.textLabel setText:@"CYAN"]; 79 | return cell; 80 | } 81 | else if (_demoTableViewStyle==DemoTableViewStyle_Green) 82 | { 83 | static NSString *CellIdentifier = @"GREEN"; 84 | StyledTableViewCell *cell = (StyledTableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 85 | if (!cell) 86 | { 87 | cell = [[StyledTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 88 | [cell.textLabel setTextColor:[UIColor grayColor]]; 89 | [cell.textLabel setFont:[UIFont boldSystemFontOfSize:14]]; 90 | [cell.textLabel setHighlightedTextColor:[UIColor whiteColor]]; 91 | [cell setStyledTableViewCellSelectionStyle:StyledTableViewCellSelectionStyleGreen]; 92 | 93 | } 94 | [cell.textLabel setText:@"GREEN"]; 95 | return cell; 96 | } 97 | else if (_demoTableViewStyle==DemoTableViewStyle_Purple) 98 | { 99 | static NSString *CellIdentifier = @"PURPLE"; 100 | StyledTableViewCell *cell = (StyledTableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 101 | if (!cell) 102 | { 103 | cell = [[StyledTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 104 | [cell.textLabel setTextColor:[UIColor grayColor]]; 105 | [cell.textLabel setFont:[UIFont boldSystemFontOfSize:14]]; 106 | [cell.textLabel setHighlightedTextColor:[UIColor whiteColor]]; 107 | [cell setStyledTableViewCellSelectionStyle:StyledTableViewCellSelectionStylePurple]; 108 | 109 | } 110 | [cell.textLabel setText:@"PURPLE"]; 111 | return cell; 112 | } 113 | else if (_demoTableViewStyle==DemoTableViewStyle_Yellow) 114 | { 115 | static NSString *CellIdentifier = @"YELLOW"; 116 | StyledTableViewCell *cell = (StyledTableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 117 | if (!cell) 118 | { 119 | cell = [[StyledTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 120 | [cell.textLabel setTextColor:[UIColor grayColor]]; 121 | [cell.textLabel setFont:[UIFont boldSystemFontOfSize:14]]; 122 | [cell.textLabel setHighlightedTextColor:[UIColor whiteColor]]; 123 | [cell setStyledTableViewCellSelectionStyle:StyledTableViewCellSelectionStyleYellow]; 124 | 125 | } 126 | [cell.textLabel setText:@"YELLOW"]; 127 | return cell; 128 | } 129 | else if (_demoTableViewStyle==DemoTableViewStyle_2Colors) 130 | { 131 | static NSString *CellIdentifier = @"CUSTOM2"; 132 | StyledTableViewCell *cell = (StyledTableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 133 | if (!cell) 134 | { 135 | cell = [[StyledTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 136 | [cell.textLabel setTextColor:[UIColor grayColor]]; 137 | [cell.textLabel setFont:[UIFont boldSystemFontOfSize:14]]; 138 | [cell.textLabel setHighlightedTextColor:[UIColor whiteColor]]; 139 | 140 | NSMutableArray *colors = [NSMutableArray array]; 141 | [colors addObject:(id)[[UIColor colorWithRed:255/255.0 green:234/255.0 blue:0 alpha:1] CGColor]]; 142 | [colors addObject:(id)[[UIColor colorWithRed:255/255.0 green:174/255.0 blue:0 alpha:1] CGColor]]; 143 | [cell setSelectedBackgroundViewGradientColors:colors]; 144 | 145 | } 146 | [cell.textLabel setText:@"CUSTOM - 2 colors"]; 147 | return cell; 148 | } 149 | else if (_demoTableViewStyle==DemoTableViewStyle_3Colors) 150 | { 151 | static NSString *CellIdentifier = @"CUSTOM3"; 152 | StyledTableViewCell *cell = (StyledTableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 153 | if (!cell) 154 | { 155 | cell = [[StyledTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 156 | [cell.textLabel setTextColor:[UIColor grayColor]]; 157 | [cell.textLabel setFont:[UIFont boldSystemFontOfSize:14]]; 158 | [cell.textLabel setHighlightedTextColor:[UIColor whiteColor]]; 159 | 160 | NSMutableArray *colors = [NSMutableArray array]; 161 | [colors addObject:(id)[[UIColor colorWithRed:255/255.0 green:174/255.0 blue:0 alpha:1] CGColor]]; 162 | [colors addObject:(id)[[UIColor colorWithRed:255/255.0 green:234/255.0 blue:0 alpha:1] CGColor]]; 163 | [colors addObject:(id)[[UIColor colorWithRed:255/255.0 green:174/255.0 blue:0 alpha:1] CGColor]]; 164 | [cell setSelectedBackgroundViewGradientColors:colors]; 165 | 166 | } 167 | [cell.textLabel setText:@"CUSTOM - 3 colors"]; 168 | return cell; 169 | } 170 | else if (_demoTableViewStyle==DemoTableViewStyle_DottedLine) 171 | { 172 | static NSString *CellIdentifier = @"DOTTED_LINE"; 173 | StyledTableViewCell *cell = (StyledTableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 174 | if (!cell) 175 | { 176 | cell = [[StyledTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 177 | [cell.textLabel setTextColor:[UIColor grayColor]]; 178 | [cell.textLabel setFont:[UIFont boldSystemFontOfSize:14]]; 179 | [cell.textLabel setHighlightedTextColor:[UIColor whiteColor]]; 180 | [cell setStyledTableViewCellSelectionStyle:StyledTableViewCellSelectionStyleCyan]; 181 | [cell setDashWidth:1 dashGap:3 dashStroke:1]; 182 | } 183 | [cell.textLabel setText:@"SEPARATOR - DOTTED LINE"]; 184 | return cell; 185 | } 186 | else if (_demoTableViewStyle==DemoTableViewStyle_Dashes) 187 | { 188 | static NSString *CellIdentifier = @"DASH"; 189 | StyledTableViewCell *cell = (StyledTableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 190 | if (!cell) 191 | { 192 | cell = [[StyledTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 193 | [cell.textLabel setTextColor:[UIColor grayColor]]; 194 | [cell.textLabel setFont:[UIFont boldSystemFontOfSize:14]]; 195 | [cell.textLabel setHighlightedTextColor:[UIColor whiteColor]]; 196 | [cell setStyledTableViewCellSelectionStyle:StyledTableViewCellSelectionStyleCyan]; 197 | [cell setDashWidth:5 dashGap:3 dashStroke:1]; 198 | } 199 | [cell.textLabel setText:@"SEPARATOR - DASHES"]; 200 | return cell; 201 | } 202 | else if (_demoTableViewStyle==DemoTableViewStyle_GradientVertical) 203 | { 204 | NSMutableArray *colors = [NSMutableArray array]; 205 | //[colors addObject:(id)[[UIColor colorWithRed:255/255.0 green:174/255.0 blue:0 alpha:1] CGColor]]; 206 | [colors addObject:(id)[[UIColor colorWithRed:255/255.0 green:234/255.0 blue:0 alpha:1] CGColor]]; 207 | [colors addObject:(id)[[UIColor colorWithRed:255/255.0 green:174/255.0 blue:0 alpha:1] CGColor]]; 208 | 209 | static NSString *CellIdentifier = @"VERTICAL"; 210 | StyledTableViewCell *cell = (StyledTableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 211 | if (!cell) 212 | { 213 | cell = [[StyledTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 214 | [cell.textLabel setTextColor:[UIColor grayColor]]; 215 | [cell.textLabel setFont:[UIFont boldSystemFontOfSize:14]]; 216 | [cell.textLabel setHighlightedTextColor:[UIColor whiteColor]]; 217 | [cell setDashWidth:1 dashGap:3 dashStroke:1]; 218 | [cell setSelectedBackgroundViewGradientColors:colors]; 219 | [cell setSelectionGradientDirection:StyledTableViewCellSelectionGradientDirectionVertical]; 220 | } 221 | [cell.textLabel setText:@"VERTICAL (DEFAULT)"]; 222 | return cell; 223 | } 224 | else if (_demoTableViewStyle==DemoTableViewStyle_GradientHorizontal) 225 | { 226 | NSMutableArray *colors = [NSMutableArray array]; 227 | //[colors addObject:(id)[[UIColor colorWithRed:255/255.0 green:174/255.0 blue:0 alpha:1] CGColor]]; 228 | [colors addObject:(id)[[UIColor colorWithRed:255/255.0 green:234/255.0 blue:0 alpha:1] CGColor]]; 229 | [colors addObject:(id)[[UIColor colorWithRed:255/255.0 green:174/255.0 blue:0 alpha:1] CGColor]]; 230 | 231 | static NSString *CellIdentifier = @"HORIZONTAL"; 232 | StyledTableViewCell *cell = (StyledTableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 233 | if (!cell) 234 | { 235 | cell = [[StyledTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 236 | [cell.textLabel setTextColor:[UIColor grayColor]]; 237 | [cell.textLabel setFont:[UIFont boldSystemFontOfSize:14]]; 238 | [cell.textLabel setHighlightedTextColor:[UIColor whiteColor]]; 239 | [cell setDashWidth:1 dashGap:3 dashStroke:1]; 240 | [cell setSelectedBackgroundViewGradientColors:colors]; 241 | [cell setSelectionGradientDirection:StyledTableViewCellSelectionGradientDirectionHorizontal]; 242 | } 243 | [cell.textLabel setText:@"HORIZONTAL"]; 244 | return cell; 245 | } 246 | else if (_demoTableViewStyle==DemoTableViewStyle_GradientDiagonalTopLeftToBottomRight) 247 | { 248 | NSMutableArray *colors = [NSMutableArray array]; 249 | //[colors addObject:(id)[[UIColor colorWithRed:255/255.0 green:174/255.0 blue:0 alpha:1] CGColor]]; 250 | [colors addObject:(id)[[UIColor colorWithRed:255/255.0 green:234/255.0 blue:0 alpha:1] CGColor]]; 251 | [colors addObject:(id)[[UIColor colorWithRed:255/255.0 green:174/255.0 blue:0 alpha:1] CGColor]]; 252 | 253 | static NSString *CellIdentifier = @"DIAGONAL1"; 254 | StyledTableViewCell *cell = (StyledTableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 255 | if (!cell) 256 | { 257 | cell = [[StyledTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 258 | [cell.textLabel setTextColor:[UIColor grayColor]]; 259 | [cell.textLabel setFont:[UIFont boldSystemFontOfSize:14]]; 260 | [cell.textLabel setHighlightedTextColor:[UIColor whiteColor]]; 261 | [cell setDashWidth:1 dashGap:3 dashStroke:1]; 262 | [cell setSelectedBackgroundViewGradientColors:colors]; 263 | [cell setSelectionGradientDirection:StyledTableViewCellSelectionGradientDirectionDiagonalTopLeftToBottomRight]; 264 | } 265 | [cell.textLabel setText:@"DIAGONAL - TOP LEFT TO BOTTOM RIGHT"]; 266 | return cell; 267 | } 268 | else if (_demoTableViewStyle==DemoTableViewStyle_GradientDiagonalBottomLeftToTopRight) 269 | { 270 | NSMutableArray *colors = [NSMutableArray array]; 271 | //[colors addObject:(id)[[UIColor colorWithRed:255/255.0 green:174/255.0 blue:0 alpha:1] CGColor]]; 272 | [colors addObject:(id)[[UIColor colorWithRed:255/255.0 green:234/255.0 blue:0 alpha:1] CGColor]]; 273 | [colors addObject:(id)[[UIColor colorWithRed:255/255.0 green:174/255.0 blue:0 alpha:1] CGColor]]; 274 | 275 | static NSString *CellIdentifier = @"DIAGONAL2"; 276 | StyledTableViewCell *cell = (StyledTableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 277 | if (!cell) 278 | { 279 | cell = [[StyledTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 280 | [cell.textLabel setTextColor:[UIColor grayColor]]; 281 | [cell.textLabel setFont:[UIFont boldSystemFontOfSize:14]]; 282 | [cell.textLabel setHighlightedTextColor:[UIColor whiteColor]]; 283 | [cell setDashWidth:1 dashGap:3 dashStroke:1]; 284 | [cell setSelectedBackgroundViewGradientColors:colors]; 285 | [cell setSelectionGradientDirection:StyledTableViewCellSelectionGradientDirectionDiagonalBottomLeftToTopRight]; 286 | } 287 | [cell.textLabel setText:@"DIAGONAL - BOTTOM LEFT TO TOP RIGHT"]; 288 | return cell; 289 | } 290 | else return nil; 291 | } 292 | 293 | #pragma mark - Table view delegate 294 | 295 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 296 | { 297 | //[tableView deselectRowAtIndexPath:indexPath animated:YES]; 298 | } 299 | 300 | @end 301 | 302 | --------------------------------------------------------------------------------