├── .gitignore ├── DLAutoresizeMaskPlugin.xcodeproj └── project.pbxproj ├── README.md ├── ViewAutoresize ├── DLAutoresizeMaskPlugin-Info.plist ├── DLAutoresizeMaskPlugin-Prefix.pch ├── DLMaskHelper.h ├── DLMaskHelper.m ├── DLMaskView.h ├── DLMaskView.m ├── DLSpringsStrutsView.h ├── DLSpringsStrutsView.m ├── en.lproj │ └── InfoPlist.strings └── types.h └── example.png /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | .DS_Store 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | *.xcworkspace 13 | !default.xcworkspace 14 | xcuserdata 15 | profile 16 | *.moved-aside 17 | DerivedData 18 | .idea/ 19 | -------------------------------------------------------------------------------- /DLAutoresizeMaskPlugin.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 1D1BBDCB1687770300505A33 /* DLSpringsStrutsView.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D1BBDCA1687770300505A33 /* DLSpringsStrutsView.m */; }; 11 | 1D3CE1CE1687746000B27C5B /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D3CE1CD1687746000B27C5B /* QuartzCore.framework */; }; 12 | 1D8289F416876D5D00EE4BBA /* DLMaskView.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D8289F316876D5D00EE4BBA /* DLMaskView.m */; }; 13 | 1D8289F616876DC900EE4BBA /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D97E6631687685100468E02 /* AppKit.framework */; }; 14 | 1D97E6611687685100468E02 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D97E6601687685100468E02 /* Cocoa.framework */; }; 15 | 1D97E66B1687685100468E02 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 1D97E6691687685100468E02 /* InfoPlist.strings */; }; 16 | 1D97E6771687695800468E02 /* DLMaskHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D97E6761687695800468E02 /* DLMaskHelper.m */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXFileReference section */ 20 | 1D1BBDC91687770300505A33 /* DLSpringsStrutsView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DLSpringsStrutsView.h; sourceTree = ""; }; 21 | 1D1BBDCA1687770300505A33 /* DLSpringsStrutsView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DLSpringsStrutsView.m; sourceTree = ""; }; 22 | 1D3CE1CD1687746000B27C5B /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; 23 | 1D711A201687838F000FC786 /* types.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = types.h; sourceTree = ""; }; 24 | 1D8289F216876D5D00EE4BBA /* DLMaskView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DLMaskView.h; sourceTree = ""; }; 25 | 1D8289F316876D5D00EE4BBA /* DLMaskView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DLMaskView.m; sourceTree = ""; }; 26 | 1D97E65D1687685100468E02 /* DLAutoresizeMaskPlugin.xcplugin */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = DLAutoresizeMaskPlugin.xcplugin; sourceTree = BUILT_PRODUCTS_DIR; }; 27 | 1D97E6601687685100468E02 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; }; 28 | 1D97E6631687685100468E02 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; }; 29 | 1D97E6641687685100468E02 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; }; 30 | 1D97E6651687685100468E02 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 31 | 1D97E6681687685100468E02 /* DLAutoresizeMaskPlugin-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "DLAutoresizeMaskPlugin-Info.plist"; sourceTree = ""; }; 32 | 1D97E66A1687685100468E02 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 33 | 1D97E66C1687685100468E02 /* DLAutoresizeMaskPlugin-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "DLAutoresizeMaskPlugin-Prefix.pch"; sourceTree = ""; }; 34 | 1D97E6751687695800468E02 /* DLMaskHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DLMaskHelper.h; sourceTree = ""; }; 35 | 1D97E6761687695800468E02 /* DLMaskHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DLMaskHelper.m; sourceTree = ""; }; 36 | /* End PBXFileReference section */ 37 | 38 | /* Begin PBXFrameworksBuildPhase section */ 39 | 1D97E65A1687685100468E02 /* Frameworks */ = { 40 | isa = PBXFrameworksBuildPhase; 41 | buildActionMask = 2147483647; 42 | files = ( 43 | 1D3CE1CE1687746000B27C5B /* QuartzCore.framework in Frameworks */, 44 | 1D8289F616876DC900EE4BBA /* AppKit.framework in Frameworks */, 45 | 1D97E6611687685100468E02 /* Cocoa.framework in Frameworks */, 46 | ); 47 | runOnlyForDeploymentPostprocessing = 0; 48 | }; 49 | /* End PBXFrameworksBuildPhase section */ 50 | 51 | /* Begin PBXGroup section */ 52 | 1D97E6521687685100468E02 = { 53 | isa = PBXGroup; 54 | children = ( 55 | 1D97E6661687685100468E02 /* ViewAutoresize */, 56 | 1D97E65F1687685100468E02 /* Frameworks */, 57 | 1D97E65E1687685100468E02 /* Products */, 58 | ); 59 | sourceTree = ""; 60 | }; 61 | 1D97E65E1687685100468E02 /* Products */ = { 62 | isa = PBXGroup; 63 | children = ( 64 | 1D97E65D1687685100468E02 /* DLAutoresizeMaskPlugin.xcplugin */, 65 | ); 66 | name = Products; 67 | sourceTree = ""; 68 | }; 69 | 1D97E65F1687685100468E02 /* Frameworks */ = { 70 | isa = PBXGroup; 71 | children = ( 72 | 1D3CE1CD1687746000B27C5B /* QuartzCore.framework */, 73 | 1D97E6601687685100468E02 /* Cocoa.framework */, 74 | 1D97E6621687685100468E02 /* Other Frameworks */, 75 | ); 76 | name = Frameworks; 77 | sourceTree = ""; 78 | }; 79 | 1D97E6621687685100468E02 /* Other Frameworks */ = { 80 | isa = PBXGroup; 81 | children = ( 82 | 1D97E6631687685100468E02 /* AppKit.framework */, 83 | 1D97E6641687685100468E02 /* CoreData.framework */, 84 | 1D97E6651687685100468E02 /* Foundation.framework */, 85 | ); 86 | name = "Other Frameworks"; 87 | sourceTree = ""; 88 | }; 89 | 1D97E6661687685100468E02 /* ViewAutoresize */ = { 90 | isa = PBXGroup; 91 | children = ( 92 | 1D8289F216876D5D00EE4BBA /* DLMaskView.h */, 93 | 1D8289F316876D5D00EE4BBA /* DLMaskView.m */, 94 | 1D1BBDC91687770300505A33 /* DLSpringsStrutsView.h */, 95 | 1D1BBDCA1687770300505A33 /* DLSpringsStrutsView.m */, 96 | 1D97E6751687695800468E02 /* DLMaskHelper.h */, 97 | 1D97E6761687695800468E02 /* DLMaskHelper.m */, 98 | 1D711A201687838F000FC786 /* types.h */, 99 | 1D97E6671687685100468E02 /* Supporting Files */, 100 | ); 101 | path = ViewAutoresize; 102 | sourceTree = ""; 103 | }; 104 | 1D97E6671687685100468E02 /* Supporting Files */ = { 105 | isa = PBXGroup; 106 | children = ( 107 | 1D97E6681687685100468E02 /* DLAutoresizeMaskPlugin-Info.plist */, 108 | 1D97E6691687685100468E02 /* InfoPlist.strings */, 109 | 1D97E66C1687685100468E02 /* DLAutoresizeMaskPlugin-Prefix.pch */, 110 | ); 111 | name = "Supporting Files"; 112 | sourceTree = ""; 113 | }; 114 | /* End PBXGroup section */ 115 | 116 | /* Begin PBXNativeTarget section */ 117 | 1D97E65C1687685100468E02 /* DLAutoresizeMaskPlugin */ = { 118 | isa = PBXNativeTarget; 119 | buildConfigurationList = 1D97E66F1687685100468E02 /* Build configuration list for PBXNativeTarget "DLAutoresizeMaskPlugin" */; 120 | buildPhases = ( 121 | 1D97E6591687685100468E02 /* Sources */, 122 | 1D97E65A1687685100468E02 /* Frameworks */, 123 | 1D97E65B1687685100468E02 /* Resources */, 124 | ); 125 | buildRules = ( 126 | ); 127 | dependencies = ( 128 | ); 129 | name = DLAutoresizeMaskPlugin; 130 | productName = ViewAutoresize; 131 | productReference = 1D97E65D1687685100468E02 /* DLAutoresizeMaskPlugin.xcplugin */; 132 | productType = "com.apple.product-type.bundle"; 133 | }; 134 | /* End PBXNativeTarget section */ 135 | 136 | /* Begin PBXProject section */ 137 | 1D97E6541687685100468E02 /* Project object */ = { 138 | isa = PBXProject; 139 | attributes = { 140 | LastUpgradeCheck = 0450; 141 | ORGANIZATIONNAME = "Denis Lebedev"; 142 | }; 143 | buildConfigurationList = 1D97E6571687685100468E02 /* Build configuration list for PBXProject "DLAutoresizeMaskPlugin" */; 144 | compatibilityVersion = "Xcode 3.2"; 145 | developmentRegion = English; 146 | hasScannedForEncodings = 0; 147 | knownRegions = ( 148 | en, 149 | ); 150 | mainGroup = 1D97E6521687685100468E02; 151 | productRefGroup = 1D97E65E1687685100468E02 /* Products */; 152 | projectDirPath = ""; 153 | projectRoot = ""; 154 | targets = ( 155 | 1D97E65C1687685100468E02 /* DLAutoresizeMaskPlugin */, 156 | ); 157 | }; 158 | /* End PBXProject section */ 159 | 160 | /* Begin PBXResourcesBuildPhase section */ 161 | 1D97E65B1687685100468E02 /* Resources */ = { 162 | isa = PBXResourcesBuildPhase; 163 | buildActionMask = 2147483647; 164 | files = ( 165 | 1D97E66B1687685100468E02 /* InfoPlist.strings in Resources */, 166 | ); 167 | runOnlyForDeploymentPostprocessing = 0; 168 | }; 169 | /* End PBXResourcesBuildPhase section */ 170 | 171 | /* Begin PBXSourcesBuildPhase section */ 172 | 1D97E6591687685100468E02 /* Sources */ = { 173 | isa = PBXSourcesBuildPhase; 174 | buildActionMask = 2147483647; 175 | files = ( 176 | 1D97E6771687695800468E02 /* DLMaskHelper.m in Sources */, 177 | 1D8289F416876D5D00EE4BBA /* DLMaskView.m in Sources */, 178 | 1D1BBDCB1687770300505A33 /* DLSpringsStrutsView.m in Sources */, 179 | ); 180 | runOnlyForDeploymentPostprocessing = 0; 181 | }; 182 | /* End PBXSourcesBuildPhase section */ 183 | 184 | /* Begin PBXVariantGroup section */ 185 | 1D97E6691687685100468E02 /* InfoPlist.strings */ = { 186 | isa = PBXVariantGroup; 187 | children = ( 188 | 1D97E66A1687685100468E02 /* en */, 189 | ); 190 | name = InfoPlist.strings; 191 | sourceTree = ""; 192 | }; 193 | /* End PBXVariantGroup section */ 194 | 195 | /* Begin XCBuildConfiguration section */ 196 | 1D97E66D1687685100468E02 /* Debug */ = { 197 | isa = XCBuildConfiguration; 198 | buildSettings = { 199 | ALWAYS_SEARCH_USER_PATHS = NO; 200 | ARCHS = "$(ARCHS_STANDARD_64_BIT)"; 201 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 202 | CLANG_CXX_LIBRARY = "libc++"; 203 | CLANG_WARN_EMPTY_BODY = YES; 204 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 205 | COPY_PHASE_STRIP = NO; 206 | GCC_C_LANGUAGE_STANDARD = gnu99; 207 | GCC_DYNAMIC_NO_PIC = NO; 208 | GCC_ENABLE_OBJC_EXCEPTIONS = YES; 209 | GCC_OPTIMIZATION_LEVEL = 0; 210 | GCC_PREPROCESSOR_DEFINITIONS = ( 211 | "DEBUG=1", 212 | "$(inherited)", 213 | ); 214 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 215 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 216 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 217 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 218 | GCC_WARN_UNUSED_VARIABLE = YES; 219 | MACOSX_DEPLOYMENT_TARGET = 10.8; 220 | ONLY_ACTIVE_ARCH = YES; 221 | SDKROOT = macosx; 222 | }; 223 | name = Debug; 224 | }; 225 | 1D97E66E1687685100468E02 /* Release */ = { 226 | isa = XCBuildConfiguration; 227 | buildSettings = { 228 | ALWAYS_SEARCH_USER_PATHS = NO; 229 | ARCHS = "$(ARCHS_STANDARD_64_BIT)"; 230 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 231 | CLANG_CXX_LIBRARY = "libc++"; 232 | CLANG_WARN_EMPTY_BODY = YES; 233 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 234 | COPY_PHASE_STRIP = YES; 235 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 236 | GCC_C_LANGUAGE_STANDARD = gnu99; 237 | GCC_ENABLE_OBJC_EXCEPTIONS = YES; 238 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 239 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 240 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 241 | GCC_WARN_UNUSED_VARIABLE = YES; 242 | MACOSX_DEPLOYMENT_TARGET = 10.8; 243 | SDKROOT = macosx; 244 | }; 245 | name = Release; 246 | }; 247 | 1D97E6701687685100468E02 /* Debug */ = { 248 | isa = XCBuildConfiguration; 249 | buildSettings = { 250 | COMBINE_HIDPI_IMAGES = YES; 251 | DEPLOYMENT_LOCATION = YES; 252 | DSTROOT = "${HOME}"; 253 | GCC_ENABLE_OBJC_GC = supported; 254 | GCC_MODEL_TUNING = G5; 255 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 256 | GCC_PREFIX_HEADER = "ViewAutoresize/DLAutoresizeMaskPlugin-Prefix.pch"; 257 | INFOPLIST_FILE = "ViewAutoresize/DLAutoresizeMaskPlugin-Info.plist"; 258 | INSTALL_PATH = "/Library/Application Support/Developer/Shared/Xcode/Plug-ins"; 259 | PRODUCT_NAME = DLAutoresizeMaskPlugin; 260 | WRAPPER_EXTENSION = xcplugin; 261 | }; 262 | name = Debug; 263 | }; 264 | 1D97E6711687685100468E02 /* Release */ = { 265 | isa = XCBuildConfiguration; 266 | buildSettings = { 267 | COMBINE_HIDPI_IMAGES = YES; 268 | DEPLOYMENT_LOCATION = YES; 269 | DSTROOT = "${HOME}"; 270 | GCC_ENABLE_OBJC_GC = supported; 271 | GCC_MODEL_TUNING = G5; 272 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 273 | GCC_PREFIX_HEADER = "ViewAutoresize/DLAutoresizeMaskPlugin-Prefix.pch"; 274 | INFOPLIST_FILE = "ViewAutoresize/DLAutoresizeMaskPlugin-Info.plist"; 275 | INSTALL_PATH = "/Library/Application Support/Developer/Shared/Xcode/Plug-ins"; 276 | PRODUCT_NAME = DLAutoresizeMaskPlugin; 277 | WRAPPER_EXTENSION = xcplugin; 278 | }; 279 | name = Release; 280 | }; 281 | /* End XCBuildConfiguration section */ 282 | 283 | /* Begin XCConfigurationList section */ 284 | 1D97E6571687685100468E02 /* Build configuration list for PBXProject "DLAutoresizeMaskPlugin" */ = { 285 | isa = XCConfigurationList; 286 | buildConfigurations = ( 287 | 1D97E66D1687685100468E02 /* Debug */, 288 | 1D97E66E1687685100468E02 /* Release */, 289 | ); 290 | defaultConfigurationIsVisible = 0; 291 | defaultConfigurationName = Release; 292 | }; 293 | 1D97E66F1687685100468E02 /* Build configuration list for PBXNativeTarget "DLAutoresizeMaskPlugin" */ = { 294 | isa = XCConfigurationList; 295 | buildConfigurations = ( 296 | 1D97E6701687685100468E02 /* Debug */, 297 | 1D97E6711687685100468E02 /* Release */, 298 | ); 299 | defaultConfigurationIsVisible = 0; 300 | defaultConfigurationName = Release; 301 | }; 302 | /* End XCConfigurationList section */ 303 | }; 304 | rootObject = 1D97E6541687685100468E02 /* Project object */; 305 | } 306 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## AutoresizeMask-for-Xcode 2 | 3 | Simple xCode plugin to visualize view autoresizing if it's set from code 4 | 5 | ![Settings Window](https://raw.github.com/garnett/AutoresizeMask-for-Xcode/master/example.png) 6 | 7 | ## Installation 8 | 9 | Simply build the Xcode project and restart Xcode. The plugin will automatically be installed in ~/Library/Application Support/Developer/Shared/Xcode/Plug-ins. To uninstall, just remove the plugin from there (and restart Xcode). 10 | 11 | This is tested on OS X 10.8 with Xcode 4.5. 12 | 13 | ## Usage 14 | 15 | Just set the cursor to line with mask code: the popup showing spring and struts will be displayed. You can enable/disable plugin in Edit menu ("Show autoresizing masks" option). 16 | 17 | ## License 18 | 19 | Copyright (c) 2012, Denis Lebedev 20 | All rights reserved. 21 | 22 | Redistribution and use in source and binary forms, with or without 23 | modification, are permitted provided that the following conditions are met: 24 | 25 | * Redistributions of source code must retain the above copyright notice, this 26 | list of conditions and the following disclaimer. 27 | 28 | * Redistributions in binary form must reproduce the above copyright notice, 29 | this list of conditions and the following disclaimer in the documentation 30 | and/or other materials provided with the distribution. 31 | 32 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 33 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 34 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 35 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 36 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 37 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 38 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 39 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 40 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 41 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 42 | -------------------------------------------------------------------------------- /ViewAutoresize/DLAutoresizeMaskPlugin-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | Home.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | BNDL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | NSHumanReadableCopyright 26 | Copyright © 2012 Denis Lebedev. All rights reserved. 27 | NSPrincipalClass 28 | DLMaskHelper 29 | XC4Compatible 30 | 31 | XCGCReady 32 | 33 | XCPluginHasUI 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /ViewAutoresize/DLAutoresizeMaskPlugin-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'ViewAutoresize' target in the 'ViewAutoresize' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /ViewAutoresize/DLMaskHelper.h: -------------------------------------------------------------------------------- 1 | // 2 | // DLViewMask.h 3 | // ViewAutoresize 4 | // 5 | // Created by Denis Lebedev on 12/23/12. 6 | // Copyright (c) 2012 Denis Lebedev. All rights reserved. 7 | // 8 | 9 | @class DLMaskView; 10 | @class DLSpringsStrutsView; 11 | 12 | @interface DLMaskHelper : NSObject 13 | 14 | @property (retain) DLMaskView *maskView; 15 | @property (retain) DLSpringsStrutsView *sizingView; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /ViewAutoresize/DLMaskHelper.m: -------------------------------------------------------------------------------- 1 | // 2 | // DLViewMask.m 3 | // ViewAutoresize 4 | // 5 | // Created by Denis Lebedev on 12/23/12. 6 | // Copyright (c) 2012 Denis Lebedev. All rights reserved. 7 | // 8 | 9 | #import "DLMaskHelper.h" 10 | #import "DLMaskView.h" 11 | #import "DLSpringsStrutsView.h" 12 | 13 | static CGFloat const kViewSize = 50.f; 14 | static NSString *const kDLShowSizingsPreferencesKey = @"kDLShowSizingsPreferencesKey"; 15 | 16 | @interface DLMaskHelper () 17 | 18 | @end 19 | 20 | @implementation DLMaskHelper 21 | 22 | + (void) pluginDidLoad:(NSBundle *)plugin { 23 | static id sharedPlugin = nil; 24 | static dispatch_once_t once; 25 | dispatch_once(&once, ^{ 26 | sharedPlugin = [[self alloc] init]; 27 | }); 28 | } 29 | 30 | - (id)init { 31 | if (self = [super init]) { 32 | [[NSNotificationCenter defaultCenter] addObserver:self 33 | selector:@selector(applicationDidFinishLaunching:) 34 | name:NSApplicationDidFinishLaunchingNotification 35 | object:nil]; 36 | } 37 | return self; 38 | } 39 | 40 | - (void)applicationDidFinishLaunching:(NSNotification*)notification { 41 | [[NSNotificationCenter defaultCenter] addObserver:self 42 | selector:@selector(selectionDidChange:) 43 | name:NSTextViewDidChangeSelectionNotification 44 | object:nil]; 45 | 46 | 47 | NSMenuItem* editMenuItem = [[NSApp mainMenu] itemWithTitle:@"Edit"]; 48 | if (editMenuItem) { 49 | [[editMenuItem submenu] addItem:[NSMenuItem separatorItem]]; 50 | 51 | NSMenuItem* newMenuItem = [[NSMenuItem alloc] initWithTitle:@"Show autoresizing masks" 52 | action:@selector(toggleMasks:) 53 | keyEquivalent:@"m"]; 54 | [newMenuItem setTarget:self]; 55 | [newMenuItem setKeyEquivalentModifierMask:NSAlternateKeyMask]; 56 | [[editMenuItem submenu] addItem:newMenuItem]; 57 | [newMenuItem release]; 58 | } 59 | } 60 | 61 | - (void)selectionDidChange:(NSNotification*)notification { 62 | if ([[notification object] isKindOfClass:[NSTextView class]]) { 63 | NSTextView* textView = (NSTextView *)[notification object]; 64 | 65 | if (![[NSUserDefaults standardUserDefaults] boolForKey:kDLShowSizingsPreferencesKey]) { 66 | return; 67 | } 68 | 69 | NSArray* selectedRanges = [textView selectedRanges]; 70 | if (selectedRanges.count >= 1) { 71 | NSRange selectedRange = [[selectedRanges objectAtIndex:0] rangeValue]; 72 | NSString *text = textView.textStorage.string; 73 | NSRange lineRange = [text lineRangeForRange:selectedRange]; 74 | NSString *line = [text substringWithRange:lineRange]; 75 | 76 | NSRange colorRange = [line rangeOfString:@"autoresizingmask" options:NSCaseInsensitiveSearch]; 77 | if (colorRange.location != NSNotFound) { 78 | NSRange selectedColorRange = NSMakeRange(colorRange.location + lineRange.location, colorRange.length); 79 | NSRect selectionRectOnScreen = [textView firstRectForCharacterRange:selectedColorRange]; 80 | NSRect selectionRectInWindow = [textView.window convertRectFromScreen:selectionRectOnScreen]; 81 | NSRect selectionRectInView = [textView convertRect:selectionRectInWindow fromView:nil]; 82 | 83 | self.maskView.frame = NSInsetRect(NSIntegralRect(selectionRectInView), -1, -1); 84 | self.sizingView.frame = NSMakeRect(CGRectGetMaxX(selectionRectInView) - kViewSize + 1, 85 | CGRectGetMinY(selectionRectInView) - kViewSize - 1, 86 | kViewSize, 87 | kViewSize); 88 | [textView addSubview:self.maskView]; 89 | [textView addSubview:self.sizingView]; 90 | 91 | /*enum { 92 | NSViewNotSizable = 0, 93 | NSViewMinXMargin = 1, 94 | NSViewWidthSizable = 2, 95 | NSViewMaxXMargin = 4, 96 | NSViewMinYMargin = 8, 97 | NSViewHeightSizable = 16, 98 | NSViewMaxYMargin = 32 99 | };*/ 100 | 101 | NSArray *masks = @[@"UIViewAutoresizingFlexibleLeftMargin", 102 | @"UIViewAutoresizingFlexibleWidth", 103 | @"UIViewAutoresizingFlexibleRightMargin", 104 | @"UIViewAutoresizingFlexibleTopMargin", 105 | @"UIViewAutoresizingFlexibleHeight", 106 | @"UIViewAutoresizingFlexibleBottomMargin"]; 107 | 108 | UIViewAutoresizing sizing = UIViewAutoresizingNone; 109 | for (int i = 0; i < [masks count]; i++) { 110 | if ([line rangeOfString:masks[i]].location != NSNotFound) { 111 | sizing = sizing | (1 << i); 112 | // NSAlert *alert = [[[NSAlert alloc] init] autorelease]; 113 | // [alert setMessageText:masks[i]]; 114 | // [alert runModal]; 115 | } 116 | } 117 | self.sizingView.mask = sizing; 118 | } 119 | else { 120 | [self dismissViews]; 121 | } 122 | } else { 123 | [self dismissViews]; 124 | } 125 | } 126 | } 127 | 128 | - (void)dismissViews { 129 | [self.maskView removeFromSuperview]; 130 | [self.sizingView removeFromSuperview]; 131 | } 132 | 133 | - (BOOL)validateMenuItem:(NSMenuItem *)menuItem { 134 | if ([menuItem action] == @selector(insertColor:)) { 135 | NSResponder *firstResponder = [[NSApp keyWindow] firstResponder]; 136 | return ([firstResponder isKindOfClass:NSClassFromString(@"DVTSourceTextView")] && [firstResponder isKindOfClass:[NSTextView class]]); 137 | } else if ([menuItem action] == @selector(toggleMasks:)) { 138 | BOOL enabled = [[NSUserDefaults standardUserDefaults] boolForKey:kDLShowSizingsPreferencesKey]; 139 | [menuItem setState:enabled ? NSOnState : NSOffState]; 140 | return YES; 141 | } 142 | return YES; 143 | } 144 | 145 | - (void)toggleMasks:(id)sender { 146 | BOOL enabled = [[NSUserDefaults standardUserDefaults] boolForKey:kDLShowSizingsPreferencesKey]; 147 | if (enabled) { 148 | [self dismissViews]; 149 | } 150 | [[NSUserDefaults standardUserDefaults] setBool:!enabled forKey:kDLShowSizingsPreferencesKey]; 151 | } 152 | 153 | #pragma mark - Getters 154 | 155 | - (DLMaskView *)maskView { 156 | if (!_maskView) { 157 | self.maskView = [[[DLMaskView alloc] initWithFrame:NSZeroRect] autorelease]; 158 | } 159 | return _maskView; 160 | } 161 | 162 | - (DLSpringsStrutsView *)sizingView { 163 | if (!_sizingView) { 164 | self.sizingView = [[[DLSpringsStrutsView alloc] initWithFrame:NSZeroRect] autorelease]; 165 | } 166 | return _sizingView; 167 | } 168 | 169 | - (void)dealloc { 170 | self.sizingView = nil; 171 | self.maskView = nil; 172 | [super dealloc]; 173 | } 174 | @end 175 | -------------------------------------------------------------------------------- /ViewAutoresize/DLMaskView.h: -------------------------------------------------------------------------------- 1 | // 2 | // DLMaskView.h 3 | // ViewAutoresize 4 | // 5 | // Created by Denis Lebedev on 12/23/12. 6 | // Copyright (c) 2012 Denis Lebedev. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface DLMaskView : NSView 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /ViewAutoresize/DLMaskView.m: -------------------------------------------------------------------------------- 1 | // 2 | // DLMaskView.m 3 | // ViewAutoresize 4 | // 5 | // Created by Denis Lebedev on 12/23/12. 6 | // Copyright (c) 2012 Denis Lebedev. All rights reserved. 7 | // 8 | 9 | #import "DLMaskView.h" 10 | 11 | @implementation DLMaskView 12 | 13 | - (void)drawRect:(NSRect)dirtyRect { 14 | CGContextRef context = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort]; 15 | CGContextSetStrokeColorWithColor(context, [NSColor greenColor].CGColor); 16 | CGContextStrokeRect(context, NSRectToCGRect(dirtyRect)); 17 | } 18 | 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /ViewAutoresize/DLSpringsStrutsView.h: -------------------------------------------------------------------------------- 1 | // 2 | // DLAnimatedView.h 3 | // ViewAutoresize 4 | // 5 | // Created by Denis Lebedev on 12/23/12. 6 | // Copyright (c) 2012 Denis Lebedev. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "types.h" 11 | 12 | @interface DLSpringsStrutsView : NSView 13 | 14 | @property (assign) UIViewAutoresizing mask; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /ViewAutoresize/DLSpringsStrutsView.m: -------------------------------------------------------------------------------- 1 | // 2 | // DLAnimatedView.m 3 | // ViewAutoresize 4 | // 5 | // Created by Denis Lebedev on 12/23/12. 6 | // Copyright (c) 2012 Denis Lebedev. All rights reserved. 7 | // 8 | 9 | #import "DLSpringsStrutsView.h" 10 | 11 | const CGFloat offset = 14.f; 12 | const CGFloat lineCrop = 3.f; 13 | 14 | @implementation DLSpringsStrutsView 15 | 16 | - (void)setMask:(UIViewAutoresizing)mask { 17 | if (mask != _mask) { 18 | _mask = mask; 19 | [self setNeedsDisplay:YES]; 20 | } 21 | } 22 | 23 | - (void)drawRect:(NSRect)dirtyRect { 24 | CGContextRef context = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort]; 25 | CGContextSetShouldAntialias(context, false); 26 | CGContextSetFillColorWithColor(context, [NSColor lightGrayColor].CGColor); 27 | CGContextFillRect(context, NSRectToCGRect(dirtyRect)); 28 | 29 | CGContextSetStrokeColorWithColor(context, [NSColor darkGrayColor].CGColor); 30 | CGContextStrokeRect(context, dirtyRect); 31 | CGContextStrokeRect(context, CGRectInset(dirtyRect, offset, offset)); 32 | 33 | CGContextSetStrokeColorWithColor(context, [NSColor redColor].CGColor); 34 | 35 | if (self.mask == UIViewAutoresizingNone) { 36 | [self addRightStrutInRect:dirtyRect context:context]; 37 | [self addLeftStrutInRect:dirtyRect context:context]; 38 | [self addTopStrutInRect:dirtyRect context:context]; 39 | [self addBottomStrutInRect:dirtyRect context:context]; 40 | CGContextStrokePath(context); 41 | return; 42 | } 43 | 44 | if (!(self.mask & UIViewAutoresizingFlexibleLeftMargin)) { 45 | [self addLeftStrutInRect:dirtyRect context:context]; 46 | } 47 | 48 | if (!(self.mask & UIViewAutoresizingFlexibleRightMargin)) { 49 | [self addRightStrutInRect:dirtyRect context:context]; 50 | } 51 | 52 | if (!(self.mask & UIViewAutoresizingFlexibleBottomMargin)) { 53 | [self addBottomStrutInRect:dirtyRect context:context]; 54 | } 55 | 56 | if (!(self.mask & UIViewAutoresizingFlexibleTopMargin)) { 57 | [self addTopStrutInRect:dirtyRect context:context]; 58 | } 59 | 60 | if (self.mask & UIViewAutoresizingFlexibleWidth) { 61 | CGContextMoveToPoint (context, offset + lineCrop, dirtyRect.size.height /2); 62 | CGContextAddLineToPoint(context, dirtyRect.size.width - offset - lineCrop, dirtyRect.size.height /2); 63 | } 64 | 65 | if (self.mask & UIViewAutoresizingFlexibleHeight) { 66 | CGContextMoveToPoint (context, dirtyRect.size.width / 2, offset + lineCrop); 67 | CGContextAddLineToPoint(context, dirtyRect.size.width / 2, dirtyRect.size.height - offset - lineCrop); 68 | } 69 | 70 | CGContextStrokePath(context); 71 | } 72 | 73 | 74 | - (void)addLeftStrutInRect:(NSRect)rect context:(CGContextRef)context { 75 | CGContextMoveToPoint (context, lineCrop, rect.size.height /2); 76 | CGContextAddLineToPoint (context, offset - lineCrop, rect.size.height /2); 77 | } 78 | 79 | - (void)addRightStrutInRect:(NSRect)rect context:(CGContextRef)context { 80 | CGContextMoveToPoint (context, rect.size.width - lineCrop, rect.size.height /2); 81 | CGContextAddLineToPoint (context, rect.size.width - offset + lineCrop, rect.size.height /2); 82 | } 83 | 84 | - (void)addBottomStrutInRect:(NSRect)rect context:(CGContextRef)context { 85 | CGContextMoveToPoint(context, rect.size.width /2, lineCrop); 86 | CGContextAddLineToPoint(context, rect.size.width /2, offset - lineCrop); 87 | } 88 | 89 | - (void)addTopStrutInRect:(NSRect)rect context:(CGContextRef)context { 90 | CGContextMoveToPoint(context, rect.size.width / 2, rect.size.height - lineCrop); 91 | CGContextAddLineToPoint(context, rect.size.width / 2, rect.size.height - offset + lineCrop); 92 | } 93 | 94 | @end 95 | -------------------------------------------------------------------------------- /ViewAutoresize/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /ViewAutoresize/types.h: -------------------------------------------------------------------------------- 1 | // 2 | // types.h 3 | // ViewAutoresize 4 | // 5 | // Created by Denis Lebedev on 12/23/12. 6 | // Copyright (c) 2012 Denis Lebedev. All rights reserved. 7 | // 8 | 9 | typedef NS_OPTIONS(NSUInteger, UIViewAutoresizing) { 10 | UIViewAutoresizingNone = 0, 11 | UIViewAutoresizingFlexibleLeftMargin = 1 << 0, 12 | UIViewAutoresizingFlexibleWidth = 1 << 1, 13 | UIViewAutoresizingFlexibleRightMargin = 1 << 2, 14 | UIViewAutoresizingFlexibleTopMargin = 1 << 3, 15 | UIViewAutoresizingFlexibleHeight = 1 << 4, 16 | UIViewAutoresizingFlexibleBottomMargin = 1 << 5 17 | }; -------------------------------------------------------------------------------- /example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/delebedev/AutoresizeMask-for-Xcode/ae71e37b4bedbf2e26a89790e2ca890620ad95fc/example.png --------------------------------------------------------------------------------