├── CGContextRef.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ └── byy5983.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── byy5983.xcuserdatad │ └── xcschemes │ ├── CGContextRef.xcscheme │ └── xcschememanagement.plist ├── CGContextRef ├── AppDelegate.h ├── AppDelegate.m ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── CustomView.h ├── CustomView.m ├── Info.plist ├── ViewController.h ├── ViewController.m └── main.m └── README.md /CGContextRef.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | F30036491DF9383800600F18 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = F30036481DF9383800600F18 /* main.m */; }; 11 | F300364C1DF9383800600F18 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = F300364B1DF9383800600F18 /* AppDelegate.m */; }; 12 | F300364F1DF9383800600F18 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F300364E1DF9383800600F18 /* ViewController.m */; }; 13 | F30036521DF9383800600F18 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F30036501DF9383800600F18 /* Main.storyboard */; }; 14 | F30036541DF9383800600F18 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F30036531DF9383800600F18 /* Assets.xcassets */; }; 15 | F30036571DF9383800600F18 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F30036551DF9383800600F18 /* LaunchScreen.storyboard */; }; 16 | F30036601DF9384700600F18 /* CustomView.m in Sources */ = {isa = PBXBuildFile; fileRef = F300365F1DF9384700600F18 /* CustomView.m */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXFileReference section */ 20 | F30036441DF9383800600F18 /* CGContextRef.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CGContextRef.app; sourceTree = BUILT_PRODUCTS_DIR; }; 21 | F30036481DF9383800600F18 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 22 | F300364A1DF9383800600F18 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 23 | F300364B1DF9383800600F18 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 24 | F300364D1DF9383800600F18 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 25 | F300364E1DF9383800600F18 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 26 | F30036511DF9383800600F18 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 27 | F30036531DF9383800600F18 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 28 | F30036561DF9383800600F18 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 29 | F30036581DF9383800600F18 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 30 | F300365E1DF9384700600F18 /* CustomView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomView.h; sourceTree = ""; }; 31 | F300365F1DF9384700600F18 /* CustomView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CustomView.m; sourceTree = ""; }; 32 | /* End PBXFileReference section */ 33 | 34 | /* Begin PBXFrameworksBuildPhase section */ 35 | F30036411DF9383800600F18 /* Frameworks */ = { 36 | isa = PBXFrameworksBuildPhase; 37 | buildActionMask = 2147483647; 38 | files = ( 39 | ); 40 | runOnlyForDeploymentPostprocessing = 0; 41 | }; 42 | /* End PBXFrameworksBuildPhase section */ 43 | 44 | /* Begin PBXGroup section */ 45 | F300363B1DF9383800600F18 = { 46 | isa = PBXGroup; 47 | children = ( 48 | F30036461DF9383800600F18 /* CGContextRef */, 49 | F30036451DF9383800600F18 /* Products */, 50 | ); 51 | sourceTree = ""; 52 | }; 53 | F30036451DF9383800600F18 /* Products */ = { 54 | isa = PBXGroup; 55 | children = ( 56 | F30036441DF9383800600F18 /* CGContextRef.app */, 57 | ); 58 | name = Products; 59 | sourceTree = ""; 60 | }; 61 | F30036461DF9383800600F18 /* CGContextRef */ = { 62 | isa = PBXGroup; 63 | children = ( 64 | F300364A1DF9383800600F18 /* AppDelegate.h */, 65 | F300364B1DF9383800600F18 /* AppDelegate.m */, 66 | F300364D1DF9383800600F18 /* ViewController.h */, 67 | F300364E1DF9383800600F18 /* ViewController.m */, 68 | F30036501DF9383800600F18 /* Main.storyboard */, 69 | F30036531DF9383800600F18 /* Assets.xcassets */, 70 | F30036551DF9383800600F18 /* LaunchScreen.storyboard */, 71 | F30036581DF9383800600F18 /* Info.plist */, 72 | F30036471DF9383800600F18 /* Supporting Files */, 73 | F300365E1DF9384700600F18 /* CustomView.h */, 74 | F300365F1DF9384700600F18 /* CustomView.m */, 75 | ); 76 | path = CGContextRef; 77 | sourceTree = ""; 78 | }; 79 | F30036471DF9383800600F18 /* Supporting Files */ = { 80 | isa = PBXGroup; 81 | children = ( 82 | F30036481DF9383800600F18 /* main.m */, 83 | ); 84 | name = "Supporting Files"; 85 | sourceTree = ""; 86 | }; 87 | /* End PBXGroup section */ 88 | 89 | /* Begin PBXNativeTarget section */ 90 | F30036431DF9383800600F18 /* CGContextRef */ = { 91 | isa = PBXNativeTarget; 92 | buildConfigurationList = F300365B1DF9383800600F18 /* Build configuration list for PBXNativeTarget "CGContextRef" */; 93 | buildPhases = ( 94 | F30036401DF9383800600F18 /* Sources */, 95 | F30036411DF9383800600F18 /* Frameworks */, 96 | F30036421DF9383800600F18 /* Resources */, 97 | ); 98 | buildRules = ( 99 | ); 100 | dependencies = ( 101 | ); 102 | name = CGContextRef; 103 | productName = CGContextRef; 104 | productReference = F30036441DF9383800600F18 /* CGContextRef.app */; 105 | productType = "com.apple.product-type.application"; 106 | }; 107 | /* End PBXNativeTarget section */ 108 | 109 | /* Begin PBXProject section */ 110 | F300363C1DF9383800600F18 /* Project object */ = { 111 | isa = PBXProject; 112 | attributes = { 113 | LastUpgradeCheck = 0810; 114 | ORGANIZATIONNAME = YongyuBai; 115 | TargetAttributes = { 116 | F30036431DF9383800600F18 = { 117 | CreatedOnToolsVersion = 8.1; 118 | DevelopmentTeam = KK59AKUJZC; 119 | ProvisioningStyle = Automatic; 120 | }; 121 | }; 122 | }; 123 | buildConfigurationList = F300363F1DF9383800600F18 /* Build configuration list for PBXProject "CGContextRef" */; 124 | compatibilityVersion = "Xcode 3.2"; 125 | developmentRegion = English; 126 | hasScannedForEncodings = 0; 127 | knownRegions = ( 128 | en, 129 | Base, 130 | ); 131 | mainGroup = F300363B1DF9383800600F18; 132 | productRefGroup = F30036451DF9383800600F18 /* Products */; 133 | projectDirPath = ""; 134 | projectRoot = ""; 135 | targets = ( 136 | F30036431DF9383800600F18 /* CGContextRef */, 137 | ); 138 | }; 139 | /* End PBXProject section */ 140 | 141 | /* Begin PBXResourcesBuildPhase section */ 142 | F30036421DF9383800600F18 /* Resources */ = { 143 | isa = PBXResourcesBuildPhase; 144 | buildActionMask = 2147483647; 145 | files = ( 146 | F30036571DF9383800600F18 /* LaunchScreen.storyboard in Resources */, 147 | F30036541DF9383800600F18 /* Assets.xcassets in Resources */, 148 | F30036521DF9383800600F18 /* Main.storyboard in Resources */, 149 | ); 150 | runOnlyForDeploymentPostprocessing = 0; 151 | }; 152 | /* End PBXResourcesBuildPhase section */ 153 | 154 | /* Begin PBXSourcesBuildPhase section */ 155 | F30036401DF9383800600F18 /* Sources */ = { 156 | isa = PBXSourcesBuildPhase; 157 | buildActionMask = 2147483647; 158 | files = ( 159 | F300364F1DF9383800600F18 /* ViewController.m in Sources */, 160 | F30036601DF9384700600F18 /* CustomView.m in Sources */, 161 | F300364C1DF9383800600F18 /* AppDelegate.m in Sources */, 162 | F30036491DF9383800600F18 /* main.m in Sources */, 163 | ); 164 | runOnlyForDeploymentPostprocessing = 0; 165 | }; 166 | /* End PBXSourcesBuildPhase section */ 167 | 168 | /* Begin PBXVariantGroup section */ 169 | F30036501DF9383800600F18 /* Main.storyboard */ = { 170 | isa = PBXVariantGroup; 171 | children = ( 172 | F30036511DF9383800600F18 /* Base */, 173 | ); 174 | name = Main.storyboard; 175 | sourceTree = ""; 176 | }; 177 | F30036551DF9383800600F18 /* LaunchScreen.storyboard */ = { 178 | isa = PBXVariantGroup; 179 | children = ( 180 | F30036561DF9383800600F18 /* Base */, 181 | ); 182 | name = LaunchScreen.storyboard; 183 | sourceTree = ""; 184 | }; 185 | /* End PBXVariantGroup section */ 186 | 187 | /* Begin XCBuildConfiguration section */ 188 | F30036591DF9383800600F18 /* Debug */ = { 189 | isa = XCBuildConfiguration; 190 | buildSettings = { 191 | ALWAYS_SEARCH_USER_PATHS = NO; 192 | CLANG_ANALYZER_NONNULL = YES; 193 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 194 | CLANG_CXX_LIBRARY = "libc++"; 195 | CLANG_ENABLE_MODULES = YES; 196 | CLANG_ENABLE_OBJC_ARC = YES; 197 | CLANG_WARN_BOOL_CONVERSION = YES; 198 | CLANG_WARN_CONSTANT_CONVERSION = YES; 199 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 200 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 201 | CLANG_WARN_EMPTY_BODY = YES; 202 | CLANG_WARN_ENUM_CONVERSION = YES; 203 | CLANG_WARN_INFINITE_RECURSION = YES; 204 | CLANG_WARN_INT_CONVERSION = YES; 205 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 206 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 207 | CLANG_WARN_UNREACHABLE_CODE = YES; 208 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 209 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 210 | COPY_PHASE_STRIP = NO; 211 | DEBUG_INFORMATION_FORMAT = dwarf; 212 | ENABLE_STRICT_OBJC_MSGSEND = YES; 213 | ENABLE_TESTABILITY = YES; 214 | GCC_C_LANGUAGE_STANDARD = gnu99; 215 | GCC_DYNAMIC_NO_PIC = NO; 216 | GCC_NO_COMMON_BLOCKS = YES; 217 | GCC_OPTIMIZATION_LEVEL = 0; 218 | GCC_PREPROCESSOR_DEFINITIONS = ( 219 | "DEBUG=1", 220 | "$(inherited)", 221 | ); 222 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 223 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 224 | GCC_WARN_UNDECLARED_SELECTOR = YES; 225 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 226 | GCC_WARN_UNUSED_FUNCTION = YES; 227 | GCC_WARN_UNUSED_VARIABLE = YES; 228 | IPHONEOS_DEPLOYMENT_TARGET = 10.1; 229 | MTL_ENABLE_DEBUG_INFO = YES; 230 | ONLY_ACTIVE_ARCH = YES; 231 | SDKROOT = iphoneos; 232 | }; 233 | name = Debug; 234 | }; 235 | F300365A1DF9383800600F18 /* Release */ = { 236 | isa = XCBuildConfiguration; 237 | buildSettings = { 238 | ALWAYS_SEARCH_USER_PATHS = NO; 239 | CLANG_ANALYZER_NONNULL = YES; 240 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 241 | CLANG_CXX_LIBRARY = "libc++"; 242 | CLANG_ENABLE_MODULES = YES; 243 | CLANG_ENABLE_OBJC_ARC = YES; 244 | CLANG_WARN_BOOL_CONVERSION = YES; 245 | CLANG_WARN_CONSTANT_CONVERSION = YES; 246 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 247 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 248 | CLANG_WARN_EMPTY_BODY = YES; 249 | CLANG_WARN_ENUM_CONVERSION = YES; 250 | CLANG_WARN_INFINITE_RECURSION = YES; 251 | CLANG_WARN_INT_CONVERSION = YES; 252 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 253 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 254 | CLANG_WARN_UNREACHABLE_CODE = YES; 255 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 256 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 257 | COPY_PHASE_STRIP = NO; 258 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 259 | ENABLE_NS_ASSERTIONS = NO; 260 | ENABLE_STRICT_OBJC_MSGSEND = YES; 261 | GCC_C_LANGUAGE_STANDARD = gnu99; 262 | GCC_NO_COMMON_BLOCKS = YES; 263 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 264 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 265 | GCC_WARN_UNDECLARED_SELECTOR = YES; 266 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 267 | GCC_WARN_UNUSED_FUNCTION = YES; 268 | GCC_WARN_UNUSED_VARIABLE = YES; 269 | IPHONEOS_DEPLOYMENT_TARGET = 10.1; 270 | MTL_ENABLE_DEBUG_INFO = NO; 271 | SDKROOT = iphoneos; 272 | VALIDATE_PRODUCT = YES; 273 | }; 274 | name = Release; 275 | }; 276 | F300365C1DF9383800600F18 /* Debug */ = { 277 | isa = XCBuildConfiguration; 278 | buildSettings = { 279 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 280 | DEVELOPMENT_TEAM = KK59AKUJZC; 281 | INFOPLIST_FILE = CGContextRef/Info.plist; 282 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 283 | PRODUCT_BUNDLE_IDENTIFIER = com.byy.CGContextRef; 284 | PRODUCT_NAME = "$(TARGET_NAME)"; 285 | }; 286 | name = Debug; 287 | }; 288 | F300365D1DF9383800600F18 /* Release */ = { 289 | isa = XCBuildConfiguration; 290 | buildSettings = { 291 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 292 | DEVELOPMENT_TEAM = KK59AKUJZC; 293 | INFOPLIST_FILE = CGContextRef/Info.plist; 294 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 295 | PRODUCT_BUNDLE_IDENTIFIER = com.byy.CGContextRef; 296 | PRODUCT_NAME = "$(TARGET_NAME)"; 297 | }; 298 | name = Release; 299 | }; 300 | /* End XCBuildConfiguration section */ 301 | 302 | /* Begin XCConfigurationList section */ 303 | F300363F1DF9383800600F18 /* Build configuration list for PBXProject "CGContextRef" */ = { 304 | isa = XCConfigurationList; 305 | buildConfigurations = ( 306 | F30036591DF9383800600F18 /* Debug */, 307 | F300365A1DF9383800600F18 /* Release */, 308 | ); 309 | defaultConfigurationIsVisible = 0; 310 | defaultConfigurationName = Release; 311 | }; 312 | F300365B1DF9383800600F18 /* Build configuration list for PBXNativeTarget "CGContextRef" */ = { 313 | isa = XCConfigurationList; 314 | buildConfigurations = ( 315 | F300365C1DF9383800600F18 /* Debug */, 316 | F300365D1DF9383800600F18 /* Release */, 317 | ); 318 | defaultConfigurationIsVisible = 0; 319 | }; 320 | /* End XCConfigurationList section */ 321 | }; 322 | rootObject = F300363C1DF9383800600F18 /* Project object */; 323 | } 324 | -------------------------------------------------------------------------------- /CGContextRef.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /CGContextRef.xcodeproj/project.xcworkspace/xcuserdata/byy5983.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Baiyongyu/CGContextRef/6ef6cabe3499f64df6ed8849e5ee7920fa19c083/CGContextRef.xcodeproj/project.xcworkspace/xcuserdata/byy5983.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /CGContextRef.xcodeproj/xcuserdata/byy5983.xcuserdatad/xcschemes/CGContextRef.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /CGContextRef.xcodeproj/xcuserdata/byy5983.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | CGContextRef.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | F30036431DF9383800600F18 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /CGContextRef/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // CGContextRef 4 | // 5 | // Created by 宇玄丶 on 2016/12/8. 6 | // Copyright © 2016年 YongyuBai. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /CGContextRef/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // CGContextRef 4 | // 5 | // Created by 宇玄丶 on 2016/12/8. 6 | // Copyright © 2016年 YongyuBai. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | 24 | - (void)applicationWillResignActive:(UIApplication *)application { 25 | // 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. 26 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 27 | } 28 | 29 | 30 | - (void)applicationDidEnterBackground:(UIApplication *)application { 31 | // 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. 32 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 33 | } 34 | 35 | 36 | - (void)applicationWillEnterForeground:(UIApplication *)application { 37 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 38 | } 39 | 40 | 41 | - (void)applicationDidBecomeActive:(UIApplication *)application { 42 | // 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. 43 | } 44 | 45 | 46 | - (void)applicationWillTerminate:(UIApplication *)application { 47 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 48 | } 49 | 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /CGContextRef/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /CGContextRef/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /CGContextRef/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /CGContextRef/CustomView.h: -------------------------------------------------------------------------------- 1 | // 2 | // CustomView.h 3 | // CGContextRef 4 | // 5 | // Created by 宇玄丶 on 2016/12/8. 6 | // Copyright © 2016年 YongyuBai. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CustomView : UIView 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /CGContextRef/CustomView.m: -------------------------------------------------------------------------------- 1 | // 2 | // CustomView.m 3 | // CGContextRef 4 | // 5 | // Created by 宇玄丶 on 2016/12/8. 6 | // Copyright © 2016年 YongyuBai. All rights reserved. 7 | // 8 | 9 | #import "CustomView.h" 10 | #import 11 | #define PI 3.14159265358979323846 12 | 13 | @implementation CustomView 14 | 15 | - (id)initWithFrame:(CGRect)frame 16 | { 17 | self = [super initWithFrame:frame]; 18 | if (self) { 19 | } 20 | return self; 21 | } 22 | 23 | // 覆盖drawRect方法,你可以在此自定义绘画和动画 24 | - (void)drawRect:(CGRect)rect 25 | { 26 | //An opaque type that represents a Quartz 2D drawing environment. 27 | //一个不透明类型的Quartz 2D绘画环境,相当于一个画布,你可以在上面任意绘画 28 | CGContextRef context = UIGraphicsGetCurrentContext(); 29 | 30 | /*写文字*/ 31 | CGContextSetRGBFillColor (context, 1, 0, 0, 1.0);//设置填充颜色 32 | UIFont *font = [UIFont boldSystemFontOfSize:15.0];//设置 33 | [@"画圆:" drawInRect:CGRectMake(10, 20, 80, 20) withFont:font]; 34 | [@"画线及孤线:" drawInRect:CGRectMake(10, 80, 100, 20) withFont:font]; 35 | [@"画矩形:" drawInRect:CGRectMake(10, 120, 80, 20) withFont:font]; 36 | [@"画扇形和椭圆:" drawInRect:CGRectMake(10, 160, 110, 20) withFont:font]; 37 | [@"画三角形:" drawInRect:CGRectMake(10, 220, 80, 20) withFont:font]; 38 | [@"画圆角矩形:" drawInRect:CGRectMake(10, 260, 100, 20) withFont:font]; 39 | [@"画贝塞尔曲线:" drawInRect:CGRectMake(10, 300, 100, 20) withFont:font]; 40 | [@"图片:" drawInRect:CGRectMake(10, 340, 80, 20) withFont:font]; 41 | 42 | /*画圆*/ 43 | //边框圆 44 | CGContextSetRGBStrokeColor(context,1,1,1,1.0);//画笔线的颜色 45 | CGContextSetLineWidth(context, 1.0);//线的宽度 46 | //void CGContextAddArc(CGContextRef c,CGFloat x, CGFloat y,CGFloat radius,CGFloat startAngle,CGFloat endAngle, int clockwise)1弧度=180°/π (≈57.3°) 度=弧度×180°/π 360°=360×π/180 =2π 弧度 47 | // x,y为圆点坐标,radius半径,startAngle为开始的弧度,endAngle为 结束的弧度,clockwise 0为顺时针,1为逆时针。 48 | CGContextAddArc(context, 100, 20, 15, 0, 2*PI, 0); //添加一个圆 49 | CGContextDrawPath(context, kCGPathStroke); //绘制路径 50 | 51 | //填充圆,无边框 52 | CGContextAddArc(context, 150, 30, 30, 0, 2*PI, 0); //添加一个圆 53 | CGContextDrawPath(context, kCGPathFill);//绘制填充 54 | 55 | //画大圆并填充颜 56 | UIColor*aColor = [UIColor colorWithRed:1 green:0.0 blue:0 alpha:1]; 57 | CGContextSetFillColorWithColor(context, aColor.CGColor);//填充颜色 58 | CGContextSetLineWidth(context, 3.0);//线的宽度 59 | CGContextAddArc(context, 250, 40, 40, 0, 2*PI, 0); //添加一个圆 60 | //kCGPathFill填充非零绕数规则,kCGPathEOFill表示用奇偶规则,kCGPathStroke路径,kCGPathFillStroke路径填充,kCGPathEOFillStroke表示描线,不是填充 61 | CGContextDrawPath(context, kCGPathFillStroke); //绘制路径加填充 62 | 63 | /*画线及孤线*/ 64 | //画线 65 | CGPoint aPoints[2];//坐标点 66 | aPoints[0] =CGPointMake(100, 80);//坐标1 67 | aPoints[1] =CGPointMake(130, 80);//坐标2 68 | //CGContextAddLines(CGContextRef c, const CGPoint points[],size_t count) 69 | //points[]坐标数组,和count大小 70 | CGContextAddLines(context, aPoints, 2);//添加线 71 | CGContextDrawPath(context, kCGPathStroke); //根据坐标绘制路径 72 | 73 | //画笑脸弧线 74 | //左 75 | CGContextSetRGBStrokeColor(context, 0, 0, 1, 1);//改变画笔颜色 76 | CGContextMoveToPoint(context, 140, 80);//开始坐标p1 77 | //CGContextAddArcToPoint(CGContextRef c, CGFloat x1, CGFloat y1,CGFloat x2, CGFloat y2, CGFloat radius) 78 | //x1,y1跟p1形成一条线的坐标p2,x2,y2结束坐标跟p3形成一条线的p3,radius半径,注意, 需要算好半径的长度, 79 | CGContextAddArcToPoint(context, 148, 68, 156, 80, 10); 80 | CGContextStrokePath(context);//绘画路径 81 | 82 | //右 83 | CGContextMoveToPoint(context, 160, 80);//开始坐标p1 84 | //CGContextAddArcToPoint(CGContextRef c, CGFloat x1, CGFloat y1,CGFloat x2, CGFloat y2, CGFloat radius) 85 | //x1,y1跟p1形成一条线的坐标p2,x2,y2结束坐标跟p3形成一条线的p3,radius半径,注意, 需要算好半径的长度, 86 | CGContextAddArcToPoint(context, 168, 68, 176, 80, 10); 87 | CGContextStrokePath(context);//绘画路径 88 | 89 | //右 90 | CGContextMoveToPoint(context, 150, 90);//开始坐标p1 91 | //CGContextAddArcToPoint(CGContextRef c, CGFloat x1, CGFloat y1,CGFloat x2, CGFloat y2, CGFloat radius) 92 | //x1,y1跟p1形成一条线的坐标p2,x2,y2结束坐标跟p3形成一条线的p3,radius半径,注意, 需要算好半径的长度, 93 | CGContextAddArcToPoint(context, 158, 102, 166, 90, 10); 94 | CGContextStrokePath(context);//绘画路径 95 | //注,如果还是没弄明白怎么回事,请参考:http://donbe.blog.163.com/blog/static/138048021201052093633776/ 96 | 97 | /*画矩形*/ 98 | CGContextStrokeRect(context,CGRectMake(100, 120, 10, 10));//画方框 99 | CGContextFillRect(context,CGRectMake(120, 120, 10, 10));//填充框 100 | //矩形,并填弃颜色 101 | CGContextSetLineWidth(context, 2.0);//线的宽度 102 | aColor = [UIColor blueColor];//blue蓝色 103 | CGContextSetFillColorWithColor(context, aColor.CGColor);//填充颜色 104 | aColor = [UIColor yellowColor]; 105 | CGContextSetStrokeColorWithColor(context, aColor.CGColor);//线框颜色 106 | CGContextAddRect(context,CGRectMake(140, 120, 60, 30));//画方框 107 | CGContextDrawPath(context, kCGPathFillStroke);//绘画路径 108 | 109 | //矩形,并填弃渐变颜色 110 | //关于颜色参考http://blog.sina.com.cn/s/blog_6ec3c9ce01015v3c.html 111 | //http://blog.csdn.net/reylen/article/details/8622932 112 | //第一种填充方式,第一种方式必须导入类库quartcore并#import ,这个就不属于在context上画,而是将层插入到view层上面。那么这里就设计到Quartz Core 图层编程了。 113 | CAGradientLayer *gradient1 = [CAGradientLayer layer]; 114 | gradient1.frame = CGRectMake(240, 120, 60, 30); 115 | gradient1.colors = [NSArray arrayWithObjects:(id)[UIColor whiteColor].CGColor, 116 | (id)[UIColor grayColor].CGColor, 117 | (id)[UIColor blackColor].CGColor, 118 | (id)[UIColor yellowColor].CGColor, 119 | (id)[UIColor blueColor].CGColor, 120 | (id)[UIColor redColor].CGColor, 121 | (id)[UIColor greenColor].CGColor, 122 | (id)[UIColor orangeColor].CGColor, 123 | (id)[UIColor brownColor].CGColor,nil]; 124 | [self.layer insertSublayer:gradient1 atIndex:0]; 125 | //第二种填充方式 126 | CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB(); 127 | CGFloat colors[] = 128 | { 129 | 1,1,1, 1.00, 130 | 1,1,0, 1.00, 131 | 1,0,0, 1.00, 132 | 1,0,1, 1.00, 133 | 0,1,1, 1.00, 134 | 0,1,0, 1.00, 135 | 0,0,1, 1.00, 136 | 0,0,0, 1.00, 137 | }; 138 | CGGradientRef gradient = CGGradientCreateWithColorComponents 139 | (rgb, colors, NULL, sizeof(colors)/(sizeof(colors[0])*4));//形成梯形,渐变的效果 140 | CGColorSpaceRelease(rgb); 141 | //画线形成一个矩形 142 | //CGContextSaveGState与CGContextRestoreGState的作用 143 | /* 144 | CGContextSaveGState函数的作用是将当前图形状态推入堆栈。之后,您对图形状态所做的修改会影响随后的描画操作,但不影响存储在堆栈中的拷贝。在修改完成后,您可以通过CGContextRestoreGState函数把堆栈顶部的状态弹出,返回到之前的图形状态。这种推入和弹出的方式是回到之前图形状态的快速方法,避免逐个撤消所有的状态修改;这也是将某些状态(比如裁剪路径)恢复到原有设置的唯一方式。 145 | */ 146 | CGContextSaveGState(context); 147 | CGContextMoveToPoint(context, 220, 90); 148 | CGContextAddLineToPoint(context, 240, 90); 149 | CGContextAddLineToPoint(context, 240, 110); 150 | CGContextAddLineToPoint(context, 220, 110); 151 | CGContextClip(context);//context裁剪路径,后续操作的路径 152 | //CGContextDrawLinearGradient(CGContextRef context,CGGradientRef gradient, CGPoint startPoint, CGPoint endPoint,CGGradientDrawingOptions options) 153 | //gradient渐变颜色,startPoint开始渐变的起始位置,endPoint结束坐标,options开始坐标之前or开始之后开始渐变 154 | CGContextDrawLinearGradient(context, gradient,CGPointMake 155 | (220,90) ,CGPointMake(240,110), 156 | kCGGradientDrawsAfterEndLocation); 157 | CGContextRestoreGState(context);// 恢复到之前的context 158 | 159 | //再写一个看看效果 160 | CGContextSaveGState(context); 161 | CGContextMoveToPoint(context, 260, 90); 162 | CGContextAddLineToPoint(context, 280, 90); 163 | CGContextAddLineToPoint(context, 280, 100); 164 | CGContextAddLineToPoint(context, 260, 100); 165 | CGContextClip(context);//裁剪路径 166 | //说白了,开始坐标和结束坐标是控制渐变的方向和形状 167 | CGContextDrawLinearGradient(context, gradient,CGPointMake 168 | (260, 90) ,CGPointMake(260, 100), 169 | kCGGradientDrawsAfterEndLocation); 170 | CGContextRestoreGState(context);// 恢复到之前的context 171 | 172 | //下面再看一个颜色渐变的圆 173 | CGContextDrawRadialGradient(context, gradient, CGPointMake(300, 100), 0.0, CGPointMake(300, 100), 10, kCGGradientDrawsBeforeStartLocation); 174 | 175 | /*画扇形和椭圆*/ 176 | //画扇形,也就画圆,只不过是设置角度的大小,形成一个扇形 177 | aColor = [UIColor colorWithRed:0 green:1 blue:1 alpha:1]; 178 | CGContextSetFillColorWithColor(context, aColor.CGColor);//填充颜色 179 | //以10为半径围绕圆心画指定角度扇形 180 | CGContextMoveToPoint(context, 160, 180); 181 | CGContextAddArc(context, 160, 180, 30, -60 * PI / 180, -120 * PI / 180, 1); 182 | CGContextClosePath(context); 183 | CGContextDrawPath(context, kCGPathFillStroke); //绘制路径 184 | 185 | //画椭圆 186 | CGContextAddEllipseInRect(context, CGRectMake(160, 180, 20, 8)); //椭圆 187 | CGContextDrawPath(context, kCGPathFillStroke); 188 | 189 | /*画三角形*/ 190 | //只要三个点就行跟画一条线方式一样,把三点连接起来 191 | CGPoint sPoints[3];//坐标点 192 | sPoints[0] =CGPointMake(100, 220);//坐标1 193 | sPoints[1] =CGPointMake(130, 220);//坐标2 194 | sPoints[2] =CGPointMake(130, 160);//坐标3 195 | CGContextAddLines(context, sPoints, 3);//添加线 196 | CGContextClosePath(context);//封起来 197 | CGContextDrawPath(context, kCGPathFillStroke); //根据坐标绘制路径 198 | 199 | /*画圆角矩形*/ 200 | float fw = 180; 201 | float fh = 280; 202 | 203 | CGContextMoveToPoint(context, fw, fh-20); // 开始坐标右边开始 204 | CGContextAddArcToPoint(context, fw, fh, fw-20, fh, 10); // 右下角角度 205 | CGContextAddArcToPoint(context, 120, fh, 120, fh-20, 10); // 左下角角度 206 | CGContextAddArcToPoint(context, 120, 250, fw-20, 250, 10); // 左上角 207 | CGContextAddArcToPoint(context, fw, 250, fw, fh-20, 10); // 右上角 208 | CGContextClosePath(context); 209 | CGContextDrawPath(context, kCGPathFillStroke); //根据坐标绘制路径 210 | 211 | /*画贝塞尔曲线*/ 212 | //二次曲线 213 | CGContextMoveToPoint(context, 120, 300);//设置Path的起点 214 | CGContextAddQuadCurveToPoint(context,190, 310, 120, 390);//设置贝塞尔曲线的控制点坐标和终点坐标 215 | CGContextStrokePath(context); 216 | //三次曲线函数 217 | CGContextMoveToPoint(context, 200, 300);//设置Path的起点 218 | CGContextAddCurveToPoint(context,250, 280, 250, 400, 280, 300);//设置贝塞尔曲线的控制点坐标和控制点坐标终点坐标 219 | CGContextStrokePath(context); 220 | 221 | 222 | /*图片*/ 223 | UIImage *image = [UIImage imageNamed:@"apple.jpg"]; 224 | [image drawInRect:CGRectMake(60, 340, 20, 20)];//在坐标中画出图片 225 | // [image drawAtPoint:CGPointMake(100, 340)];//保持图片大小在point点开始画图片,可以把注释去掉看看 226 | CGContextDrawImage(context, CGRectMake(100, 340, 20, 20), image.CGImage);//使用这个使图片上下颠倒了,参考http://blog.csdn.net/koupoo/article/details/8670024 227 | 228 | // CGContextDrawTiledImage(context, CGRectMake(0, 0, 20, 20), image.CGImage);//平铺图 229 | 230 | } 231 | 232 | 233 | @end 234 | -------------------------------------------------------------------------------- /CGContextRef/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /CGContextRef/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // CGContextRef 4 | // 5 | // Created by 宇玄丶 on 2016/12/8. 6 | // Copyright © 2016年 YongyuBai. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /CGContextRef/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // CGContextRef 4 | // 5 | // Created by 宇玄丶 on 2016/12/8. 6 | // Copyright © 2016年 YongyuBai. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "CustomView.h" 11 | 12 | @interface ViewController () 13 | 14 | @end 15 | 16 | @implementation ViewController 17 | 18 | - (void)viewDidLoad { 19 | [super viewDidLoad]; 20 | // Do any additional setup after loading the view, typically from a nib. 21 | 22 | CustomView *customView = [[CustomView alloc]initWithFrame:CGRectMake(0, 100, self.view.frame.size.width, self.view.frame.size.height)]; 23 | [self.view addSubview:customView]; 24 | } 25 | 26 | 27 | - (void)didReceiveMemoryWarning { 28 | [super didReceiveMemoryWarning]; 29 | // Dispose of any resources that can be recreated. 30 | } 31 | 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /CGContextRef/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // CGContextRef 4 | // 5 | // Created by 宇玄丶 on 2016/12/8. 6 | // Copyright © 2016年 YongyuBai. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CGContextRef 2 | IOS用CGContextRef画各种图形(文字、圆、直线、弧线、矩形、扇形、椭圆、三角形、圆角矩形、贝塞尔曲线、图片) 3 | --------------------------------------------------------------------------------