├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── UpdateAutoLayoutConstraints.podspec ├── UpdateAutoLayoutConstraints.xcodeproj ├── project.pbxproj └── xcshareddata │ └── xcschemes │ └── UpdateAutoLayoutConstraints-Example.xcscheme ├── UpdateAutoLayoutConstraints ├── DRAppDelegate.h ├── DRAppDelegate.m ├── DRViewController.h ├── DRViewController.m ├── Images.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── LaunchImage.launchimage │ │ └── Contents.json ├── PodFiles │ ├── UIView+UpdateAutoLayoutConstraints.h │ └── UIView+UpdateAutoLayoutConstraints.m ├── UpdateAutoLayoutConstraints-Info.plist ├── UpdateAutoLayoutConstraints-Prefix.pch ├── en.lproj │ └── InfoPlist.strings └── main.m └── picture.jpg /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Xcode 4 | build/* 5 | *.pbxuser 6 | !default.pbxuser 7 | *.mode1v3 8 | !default.mode1v3 9 | *.mode2v3 10 | !default.mode2v3 11 | *.perspectivev3 12 | !default.perspectivev3 13 | *.xcworkspace 14 | !default.xcworkspace 15 | xcuserdata 16 | profile 17 | *.moved-aside 18 | .DS_Store -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # references: 2 | # * http://www.objc.io/issue-6/travis-ci.html 3 | # * https://github.com/supermarin/xcpretty#usage 4 | 5 | language: objective-c 6 | # cache: cocoapods 7 | # podfile: Example/Podfile 8 | # before_install: 9 | # - gem install cocoapods # Since Travis is not always on latest version 10 | # - pod install --project-directory=Example 11 | install: 12 | - gem install xcpretty --no-rdoc --no-ri --no-document --quiet 13 | script: 14 | - set -o pipefail && xcodebuild test -workspace Example/UpdateAutoLayoutConstraints.xcworkspace -scheme UpdateAutoLayoutConstraints-Example -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO | xcpretty -c 15 | - pod lib lint --quick 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 Damien 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | UIView-UpdateAutoLayoutConstraints 2 | ================================== 3 | 4 | An easy way to create and update AutoLayout Constraints (Mainly to update Width and Height of UIView) 5 | 6 | 7 | ![alt text](https://github.com/damienromito/UIView-UpdateAutoLayoutConstraints/blob/master/picture.jpg "Resize tableViewHeader") 8 | 9 | 10 | **1 - import Category** 11 | 12 | ```objective-c 13 | #import "UIView+UpdateAutoLayoutConstraints.h" 14 | ``` 15 | 16 | **2 - create your UIViews** 17 | ```objective-c 18 | UIView *myView1 = [[UIView alloc]init]; 19 | one.backgroundColor = [UIColor redColor]; 20 | one.translatesAutoresizingMaskIntoConstraints = NO; //<<-- Don't forget this line to enable AutoLayout 21 | [self.view addSubview:one]; 22 | 23 | UIView *myView2 = [[UIView alloc]init]; 24 | two.backgroundColor = [UIColor blueColor]; 25 | two.translatesAutoresizingMaskIntoConstraints = NO; 26 | [self.view addSubview:two]; 27 | ``` 28 | 29 | **3 - create initial constraints** 30 | ```objective-c 31 | NSDictionary *metrics = @{@"height":@50.0}; 32 | NSDictionary *views = NSDictionaryOfVariableBindings(myView1,myView2); 33 | 34 | [self.view addConstraints:[NSLayoutConstraint 35 | constraintsWithVisualFormat:@"|-[one]-|" 36 | options: 0 37 | metrics:metrics 38 | views:views]]; 39 | 40 | [self.view addConstraints:[NSLayoutConstraint 41 | constraintsWithVisualFormat:@"V:|-[myView1(50)][myView2]]" 42 | options:NSLayoutFormatAlignAllLeft | NSLayoutFormatAlignAllRight 43 | metrics:metrics 44 | views:views]]; 45 | 46 | ``` 47 | **4 - Whenever you want, Update this constraint** 48 | ```objective-c 49 | //Hide View 50 | [myView1 setConstraintConstant:0 forAttribute:NSLayoutAttributeHeight]; 51 | 52 | //if constraint doesn't exist, it will be created 53 | [myView1 setConstraintConstant:20 forAttribute:NSLayoutAttributeWidth]; 54 | 55 | //you can use tools to hide/show a uiview 56 | [myView1 hideByHeight:YES]; 57 | 58 | //then 59 | [myView1 hideByHeight:NO]; 60 | ``` 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /UpdateAutoLayoutConstraints.podspec: -------------------------------------------------------------------------------- 1 | 2 | Pod::Spec.new do |s| 3 | s.name = "UpdateAutoLayoutConstraints" 4 | s.version = "0.2.0" 5 | s.summary = "An easy way to create and update AutoLayout Constraints (Mainly to update Width and Height of UIView)" 6 | s.homepage = "https://github.com/damienromito/UIView-UpdateAutoLayoutConstraints" 7 | s.license = 'MIT' 8 | s.author = { "Damien" => "damien@romito.fr" } 9 | s.source = { :git => "https://github.com/damienromito/UIView-UpdateAutoLayoutConstraints.git", :tag => s.version.to_s } 10 | # s.social_media_url = 'https://twitter.com/damienromito' 11 | s.platform = :ios, '7.0' 12 | s.requires_arc = true 13 | s.source_files = 'UpdateAutoLayoutConstraints/PodFiles/*.{h,m}' 14 | end 15 | -------------------------------------------------------------------------------- /UpdateAutoLayoutConstraints.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 1F57D5601AA89582006BC3EA /* UIView+UpdateAutoLayoutConstraints.m in Sources */ = {isa = PBXBuildFile; fileRef = 1F57D55F1AA89582006BC3EA /* UIView+UpdateAutoLayoutConstraints.m */; }; 11 | 6003F58E195388D20070C39A /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F58D195388D20070C39A /* Foundation.framework */; }; 12 | 6003F590195388D20070C39A /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F58F195388D20070C39A /* CoreGraphics.framework */; }; 13 | 6003F592195388D20070C39A /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F591195388D20070C39A /* UIKit.framework */; }; 14 | 6003F598195388D20070C39A /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 6003F596195388D20070C39A /* InfoPlist.strings */; }; 15 | 6003F59A195388D20070C39A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 6003F599195388D20070C39A /* main.m */; }; 16 | 6003F59E195388D20070C39A /* DRAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 6003F59D195388D20070C39A /* DRAppDelegate.m */; }; 17 | 6003F5A7195388D20070C39A /* DRViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6003F5A6195388D20070C39A /* DRViewController.m */; }; 18 | 6003F5A9195388D20070C39A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6003F5A8195388D20070C39A /* Images.xcassets */; }; 19 | /* End PBXBuildFile section */ 20 | 21 | /* Begin PBXFileReference section */ 22 | 1F57D55E1AA89582006BC3EA /* UIView+UpdateAutoLayoutConstraints.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "UIView+UpdateAutoLayoutConstraints.h"; path = "PodFiles/UIView+UpdateAutoLayoutConstraints.h"; sourceTree = ""; }; 23 | 1F57D55F1AA89582006BC3EA /* UIView+UpdateAutoLayoutConstraints.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "UIView+UpdateAutoLayoutConstraints.m"; path = "PodFiles/UIView+UpdateAutoLayoutConstraints.m"; sourceTree = ""; }; 24 | 6003F58A195388D20070C39A /* UpdateAutoLayoutConstraints.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = UpdateAutoLayoutConstraints.app; sourceTree = BUILT_PRODUCTS_DIR; }; 25 | 6003F58D195388D20070C39A /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 26 | 6003F58F195388D20070C39A /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; 27 | 6003F591195388D20070C39A /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 28 | 6003F595195388D20070C39A /* UpdateAutoLayoutConstraints-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "UpdateAutoLayoutConstraints-Info.plist"; sourceTree = ""; }; 29 | 6003F597195388D20070C39A /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 30 | 6003F599195388D20070C39A /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 31 | 6003F59B195388D20070C39A /* UpdateAutoLayoutConstraints-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UpdateAutoLayoutConstraints-Prefix.pch"; sourceTree = ""; }; 32 | 6003F59C195388D20070C39A /* DRAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DRAppDelegate.h; sourceTree = ""; }; 33 | 6003F59D195388D20070C39A /* DRAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DRAppDelegate.m; sourceTree = ""; }; 34 | 6003F5A5195388D20070C39A /* DRViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DRViewController.h; sourceTree = ""; }; 35 | 6003F5A6195388D20070C39A /* DRViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DRViewController.m; sourceTree = ""; }; 36 | 6003F5A8195388D20070C39A /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 37 | 6003F5AF195388D20070C39A /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; }; 38 | /* End PBXFileReference section */ 39 | 40 | /* Begin PBXFrameworksBuildPhase section */ 41 | 6003F587195388D20070C39A /* Frameworks */ = { 42 | isa = PBXFrameworksBuildPhase; 43 | buildActionMask = 2147483647; 44 | files = ( 45 | 6003F590195388D20070C39A /* CoreGraphics.framework in Frameworks */, 46 | 6003F592195388D20070C39A /* UIKit.framework in Frameworks */, 47 | 6003F58E195388D20070C39A /* Foundation.framework in Frameworks */, 48 | ); 49 | runOnlyForDeploymentPostprocessing = 0; 50 | }; 51 | /* End PBXFrameworksBuildPhase section */ 52 | 53 | /* Begin PBXGroup section */ 54 | 6003F581195388D10070C39A = { 55 | isa = PBXGroup; 56 | children = ( 57 | 6003F593195388D20070C39A /* UpdateAutoLayoutConstraints */, 58 | 6003F58C195388D20070C39A /* Frameworks */, 59 | 6003F58B195388D20070C39A /* Products */, 60 | ); 61 | sourceTree = ""; 62 | }; 63 | 6003F58B195388D20070C39A /* Products */ = { 64 | isa = PBXGroup; 65 | children = ( 66 | 6003F58A195388D20070C39A /* UpdateAutoLayoutConstraints.app */, 67 | ); 68 | name = Products; 69 | sourceTree = ""; 70 | }; 71 | 6003F58C195388D20070C39A /* Frameworks */ = { 72 | isa = PBXGroup; 73 | children = ( 74 | 6003F58D195388D20070C39A /* Foundation.framework */, 75 | 6003F58F195388D20070C39A /* CoreGraphics.framework */, 76 | 6003F591195388D20070C39A /* UIKit.framework */, 77 | 6003F5AF195388D20070C39A /* XCTest.framework */, 78 | ); 79 | name = Frameworks; 80 | sourceTree = ""; 81 | }; 82 | 6003F593195388D20070C39A /* UpdateAutoLayoutConstraints */ = { 83 | isa = PBXGroup; 84 | children = ( 85 | 1F57D55E1AA89582006BC3EA /* UIView+UpdateAutoLayoutConstraints.h */, 86 | 1F57D55F1AA89582006BC3EA /* UIView+UpdateAutoLayoutConstraints.m */, 87 | 6003F59C195388D20070C39A /* DRAppDelegate.h */, 88 | 6003F59D195388D20070C39A /* DRAppDelegate.m */, 89 | 6003F5A5195388D20070C39A /* DRViewController.h */, 90 | 6003F5A6195388D20070C39A /* DRViewController.m */, 91 | 6003F5A8195388D20070C39A /* Images.xcassets */, 92 | 6003F594195388D20070C39A /* Supporting Files */, 93 | ); 94 | path = UpdateAutoLayoutConstraints; 95 | sourceTree = ""; 96 | }; 97 | 6003F594195388D20070C39A /* Supporting Files */ = { 98 | isa = PBXGroup; 99 | children = ( 100 | 6003F595195388D20070C39A /* UpdateAutoLayoutConstraints-Info.plist */, 101 | 6003F596195388D20070C39A /* InfoPlist.strings */, 102 | 6003F599195388D20070C39A /* main.m */, 103 | 6003F59B195388D20070C39A /* UpdateAutoLayoutConstraints-Prefix.pch */, 104 | ); 105 | name = "Supporting Files"; 106 | sourceTree = ""; 107 | }; 108 | /* End PBXGroup section */ 109 | 110 | /* Begin PBXNativeTarget section */ 111 | 6003F589195388D20070C39A /* UpdateAutoLayoutConstraints */ = { 112 | isa = PBXNativeTarget; 113 | buildConfigurationList = 6003F5BF195388D20070C39A /* Build configuration list for PBXNativeTarget "UpdateAutoLayoutConstraints" */; 114 | buildPhases = ( 115 | 6003F586195388D20070C39A /* Sources */, 116 | 6003F587195388D20070C39A /* Frameworks */, 117 | 6003F588195388D20070C39A /* Resources */, 118 | ); 119 | buildRules = ( 120 | ); 121 | dependencies = ( 122 | ); 123 | name = UpdateAutoLayoutConstraints; 124 | productName = UpdateAutoLayoutConstraints; 125 | productReference = 6003F58A195388D20070C39A /* UpdateAutoLayoutConstraints.app */; 126 | productType = "com.apple.product-type.application"; 127 | }; 128 | /* End PBXNativeTarget section */ 129 | 130 | /* Begin PBXProject section */ 131 | 6003F582195388D10070C39A /* Project object */ = { 132 | isa = PBXProject; 133 | attributes = { 134 | CLASSPREFIX = DR; 135 | LastUpgradeCheck = 0510; 136 | ORGANIZATIONNAME = Damien; 137 | }; 138 | buildConfigurationList = 6003F585195388D10070C39A /* Build configuration list for PBXProject "UpdateAutoLayoutConstraints" */; 139 | compatibilityVersion = "Xcode 3.2"; 140 | developmentRegion = English; 141 | hasScannedForEncodings = 0; 142 | knownRegions = ( 143 | en, 144 | Base, 145 | ); 146 | mainGroup = 6003F581195388D10070C39A; 147 | productRefGroup = 6003F58B195388D20070C39A /* Products */; 148 | projectDirPath = ""; 149 | projectRoot = ""; 150 | targets = ( 151 | 6003F589195388D20070C39A /* UpdateAutoLayoutConstraints */, 152 | ); 153 | }; 154 | /* End PBXProject section */ 155 | 156 | /* Begin PBXResourcesBuildPhase section */ 157 | 6003F588195388D20070C39A /* Resources */ = { 158 | isa = PBXResourcesBuildPhase; 159 | buildActionMask = 2147483647; 160 | files = ( 161 | 6003F5A9195388D20070C39A /* Images.xcassets in Resources */, 162 | 6003F598195388D20070C39A /* InfoPlist.strings in Resources */, 163 | ); 164 | runOnlyForDeploymentPostprocessing = 0; 165 | }; 166 | /* End PBXResourcesBuildPhase section */ 167 | 168 | /* Begin PBXSourcesBuildPhase section */ 169 | 6003F586195388D20070C39A /* Sources */ = { 170 | isa = PBXSourcesBuildPhase; 171 | buildActionMask = 2147483647; 172 | files = ( 173 | 6003F59E195388D20070C39A /* DRAppDelegate.m in Sources */, 174 | 1F57D5601AA89582006BC3EA /* UIView+UpdateAutoLayoutConstraints.m in Sources */, 175 | 6003F5A7195388D20070C39A /* DRViewController.m in Sources */, 176 | 6003F59A195388D20070C39A /* main.m in Sources */, 177 | ); 178 | runOnlyForDeploymentPostprocessing = 0; 179 | }; 180 | /* End PBXSourcesBuildPhase section */ 181 | 182 | /* Begin PBXVariantGroup section */ 183 | 6003F596195388D20070C39A /* InfoPlist.strings */ = { 184 | isa = PBXVariantGroup; 185 | children = ( 186 | 6003F597195388D20070C39A /* en */, 187 | ); 188 | name = InfoPlist.strings; 189 | sourceTree = ""; 190 | }; 191 | /* End PBXVariantGroup section */ 192 | 193 | /* Begin XCBuildConfiguration section */ 194 | 6003F5BD195388D20070C39A /* Debug */ = { 195 | isa = XCBuildConfiguration; 196 | buildSettings = { 197 | ALWAYS_SEARCH_USER_PATHS = NO; 198 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 199 | CLANG_CXX_LIBRARY = "libc++"; 200 | CLANG_ENABLE_MODULES = YES; 201 | CLANG_ENABLE_OBJC_ARC = YES; 202 | CLANG_WARN_BOOL_CONVERSION = YES; 203 | CLANG_WARN_CONSTANT_CONVERSION = YES; 204 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 205 | CLANG_WARN_EMPTY_BODY = YES; 206 | CLANG_WARN_ENUM_CONVERSION = YES; 207 | CLANG_WARN_INT_CONVERSION = YES; 208 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 209 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 210 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 211 | COPY_PHASE_STRIP = NO; 212 | GCC_C_LANGUAGE_STANDARD = gnu99; 213 | GCC_DYNAMIC_NO_PIC = NO; 214 | GCC_OPTIMIZATION_LEVEL = 0; 215 | GCC_PREPROCESSOR_DEFINITIONS = ( 216 | "DEBUG=1", 217 | "$(inherited)", 218 | ); 219 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 220 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 221 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 222 | GCC_WARN_UNDECLARED_SELECTOR = YES; 223 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 224 | GCC_WARN_UNUSED_FUNCTION = YES; 225 | GCC_WARN_UNUSED_VARIABLE = YES; 226 | IPHONEOS_DEPLOYMENT_TARGET = 7.1; 227 | ONLY_ACTIVE_ARCH = YES; 228 | SDKROOT = iphoneos; 229 | TARGETED_DEVICE_FAMILY = "1,2"; 230 | }; 231 | name = Debug; 232 | }; 233 | 6003F5BE195388D20070C39A /* Release */ = { 234 | isa = XCBuildConfiguration; 235 | buildSettings = { 236 | ALWAYS_SEARCH_USER_PATHS = NO; 237 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 238 | CLANG_CXX_LIBRARY = "libc++"; 239 | CLANG_ENABLE_MODULES = YES; 240 | CLANG_ENABLE_OBJC_ARC = YES; 241 | CLANG_WARN_BOOL_CONVERSION = YES; 242 | CLANG_WARN_CONSTANT_CONVERSION = YES; 243 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 244 | CLANG_WARN_EMPTY_BODY = YES; 245 | CLANG_WARN_ENUM_CONVERSION = YES; 246 | CLANG_WARN_INT_CONVERSION = YES; 247 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 248 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 249 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 250 | COPY_PHASE_STRIP = YES; 251 | ENABLE_NS_ASSERTIONS = NO; 252 | GCC_C_LANGUAGE_STANDARD = gnu99; 253 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 254 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 255 | GCC_WARN_UNDECLARED_SELECTOR = YES; 256 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 257 | GCC_WARN_UNUSED_FUNCTION = YES; 258 | GCC_WARN_UNUSED_VARIABLE = YES; 259 | IPHONEOS_DEPLOYMENT_TARGET = 7.1; 260 | SDKROOT = iphoneos; 261 | TARGETED_DEVICE_FAMILY = "1,2"; 262 | VALIDATE_PRODUCT = YES; 263 | }; 264 | name = Release; 265 | }; 266 | 6003F5C0195388D20070C39A /* Debug */ = { 267 | isa = XCBuildConfiguration; 268 | buildSettings = { 269 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 270 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; 271 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 272 | GCC_PREFIX_HEADER = "UpdateAutoLayoutConstraints/UpdateAutoLayoutConstraints-Prefix.pch"; 273 | INFOPLIST_FILE = "UpdateAutoLayoutConstraints/UpdateAutoLayoutConstraints-Info.plist"; 274 | PRODUCT_NAME = "$(TARGET_NAME)"; 275 | WRAPPER_EXTENSION = app; 276 | }; 277 | name = Debug; 278 | }; 279 | 6003F5C1195388D20070C39A /* Release */ = { 280 | isa = XCBuildConfiguration; 281 | buildSettings = { 282 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 283 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; 284 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 285 | GCC_PREFIX_HEADER = "UpdateAutoLayoutConstraints/UpdateAutoLayoutConstraints-Prefix.pch"; 286 | INFOPLIST_FILE = "UpdateAutoLayoutConstraints/UpdateAutoLayoutConstraints-Info.plist"; 287 | PRODUCT_NAME = "$(TARGET_NAME)"; 288 | WRAPPER_EXTENSION = app; 289 | }; 290 | name = Release; 291 | }; 292 | /* End XCBuildConfiguration section */ 293 | 294 | /* Begin XCConfigurationList section */ 295 | 6003F585195388D10070C39A /* Build configuration list for PBXProject "UpdateAutoLayoutConstraints" */ = { 296 | isa = XCConfigurationList; 297 | buildConfigurations = ( 298 | 6003F5BD195388D20070C39A /* Debug */, 299 | 6003F5BE195388D20070C39A /* Release */, 300 | ); 301 | defaultConfigurationIsVisible = 0; 302 | defaultConfigurationName = Release; 303 | }; 304 | 6003F5BF195388D20070C39A /* Build configuration list for PBXNativeTarget "UpdateAutoLayoutConstraints" */ = { 305 | isa = XCConfigurationList; 306 | buildConfigurations = ( 307 | 6003F5C0195388D20070C39A /* Debug */, 308 | 6003F5C1195388D20070C39A /* Release */, 309 | ); 310 | defaultConfigurationIsVisible = 0; 311 | defaultConfigurationName = Release; 312 | }; 313 | /* End XCConfigurationList section */ 314 | }; 315 | rootObject = 6003F582195388D10070C39A /* Project object */; 316 | } 317 | -------------------------------------------------------------------------------- /UpdateAutoLayoutConstraints.xcodeproj/xcshareddata/xcschemes/UpdateAutoLayoutConstraints-Example.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 49 | 50 | 51 | 52 | 61 | 62 | 68 | 69 | 70 | 71 | 72 | 73 | 79 | 80 | 86 | 87 | 88 | 89 | 91 | 92 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /UpdateAutoLayoutConstraints/DRAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // DRAppDelegate.h 3 | // UpdateAutoLayoutConstraints 4 | // 5 | // Created by CocoaPods on 03/05/2015. 6 | // Copyright (c) 2014 Damien. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface DRAppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /UpdateAutoLayoutConstraints/DRAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // DRAppDelegate.m 3 | // UpdateAutoLayoutConstraints 4 | // 5 | // Created by CocoaPods on 03/05/2015. 6 | // Copyright (c) 2014 Damien. All rights reserved. 7 | // 8 | 9 | #import "DRAppDelegate.h" 10 | #import "DRViewController.h" 11 | 12 | @implementation DRAppDelegate 13 | 14 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 15 | { 16 | 17 | self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 18 | self.window.rootViewController = [[DRViewController alloc] init]; 19 | 20 | [self.window makeKeyAndVisible]; 21 | return YES; 22 | } 23 | 24 | - (void)applicationWillResignActive:(UIApplication *)application 25 | { 26 | // 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. 27 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 28 | } 29 | 30 | - (void)applicationDidEnterBackground:(UIApplication *)application 31 | { 32 | // 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. 33 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 34 | } 35 | 36 | - (void)applicationWillEnterForeground:(UIApplication *)application 37 | { 38 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 39 | } 40 | 41 | - (void)applicationDidBecomeActive:(UIApplication *)application 42 | { 43 | // 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. 44 | } 45 | 46 | - (void)applicationWillTerminate:(UIApplication *)application 47 | { 48 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 49 | } 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /UpdateAutoLayoutConstraints/DRViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // DRViewController.h 3 | // UpdateAutoLayoutConstraints 4 | // 5 | // Created by Damien on 03/05/2015. 6 | // Copyright (c) 2014 Damien. All rights reserved. 7 | // 8 | 9 | 10 | @interface DRViewController : UITableViewController 11 | 12 | @end 13 | -------------------------------------------------------------------------------- /UpdateAutoLayoutConstraints/DRViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // TableViewHeaderAutoLayout 4 | // 5 | // Created by Damien Romito on 17/03/2014. 6 | // Copyright (c) 2014 Damien Romito. All rights reserved. 7 | // 8 | 9 | #import "DRViewController.h" 10 | #import "UIView+UpdateAutoLayoutConstraints.h" 11 | 12 | @interface DRViewController () 13 | @property (nonatomic, strong) UIView *hidableView; 14 | @property (nonatomic, strong) UILabel *dynamicLabel; 15 | 16 | @property (nonatomic, strong) UIView *header; 17 | @end 18 | 19 | @implementation DRViewController 20 | 21 | - (void)viewDidLoad 22 | { 23 | [super viewDidLoad]; 24 | 25 | self.header = [[UIView alloc] init]; 26 | 27 | UIButton * v1 = [UIButton new]; 28 | [v1 setTitle:@"HIDE/SHOW VIEW BELOW" forState:UIControlStateNormal]; 29 | [v1 addTarget:self action:@selector(actionToggle) forControlEvents:UIControlEventTouchUpInside]; 30 | v1.translatesAutoresizingMaskIntoConstraints = NO; 31 | v1.backgroundColor = [UIColor redColor]; 32 | [self.header addSubview:v1]; 33 | 34 | self.hidableView = [UIView new]; 35 | self.hidableView.translatesAutoresizingMaskIntoConstraints = NO; 36 | self.hidableView.backgroundColor = [UIColor yellowColor]; 37 | [self.header addSubview:self.hidableView]; 38 | 39 | //VIEW WITH DYNAMIC HEIGHT 40 | self.dynamicLabel = [UILabel new]; 41 | self.dynamicLabel.backgroundColor = [UIColor whiteColor]; 42 | self.dynamicLabel.numberOfLines = 0; 43 | self.dynamicLabel.backgroundColor = [UIColor grayColor]; 44 | self.dynamicLabel.preferredMaxLayoutWidth = 320; //YOU NEED TO DEFINE THE preferredMaxLayoutWidth 45 | self.dynamicLabel.text = @"Lorem ipsum dolor sit amet Lorem ipsum dolor"; 46 | self.dynamicLabel.lineBreakMode = NSLineBreakByWordWrapping; 47 | [self.dynamicLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical]; 48 | [self.dynamicLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical]; 49 | self.dynamicLabel.translatesAutoresizingMaskIntoConstraints = NO; 50 | [self.header addSubview:self.dynamicLabel]; 51 | 52 | UIButton * v2 = [UIButton new]; 53 | [v2 setTitle:@"TOGGLE TEXT" forState:UIControlStateNormal]; 54 | [v2 addTarget:self action:@selector(actionToggleText) forControlEvents:UIControlEventTouchUpInside]; 55 | v2.translatesAutoresizingMaskIntoConstraints = NO; 56 | v2.backgroundColor = [UIColor greenColor]; 57 | [self.header addSubview:v2]; 58 | 59 | NSDictionary *views = @{@"v1" : v1, 60 | @"hidableView":self.hidableView, 61 | @"dynamicLabel":self.dynamicLabel, 62 | @"v2" : v2, 63 | }; 64 | 65 | [self.header addConstraints:[NSLayoutConstraint 66 | constraintsWithVisualFormat:@"H:|-[v1]-|" 67 | options: 0 68 | metrics:0 69 | views:views]]; 70 | 71 | 72 | [self.header addConstraints:[NSLayoutConstraint 73 | constraintsWithVisualFormat:@"V:|[v1(100)]-[hidableView(30)]-[dynamicLabel]-[v2(40)]|" 74 | options: NSLayoutFormatAlignAllRight | NSLayoutFormatAlignAllLeft 75 | metrics:0 76 | views:views]]; 77 | 78 | 79 | 80 | [self resizeTableViewHeader]; 81 | 82 | 83 | } 84 | 85 | 86 | - (void)resizeTableViewHeader 87 | { 88 | 89 | [self.header sizeToSubviews]; 90 | self.tableView.tableHeaderView = self.header; 91 | } 92 | 93 | 94 | - (void) actionToggle 95 | { 96 | [self.hidableView hideByHeight:!self.hidableView.hidden]; 97 | [self resizeTableViewHeader]; 98 | } 99 | 100 | - (void) actionToggleText 101 | { 102 | if ([self.dynamicLabel.text isEqualToString:@"Lorem ipsum dolor sit amet Lorem ipsum dolor"]) { 103 | self.dynamicLabel.text = @"Or sit amet Lorem ip Lorem ipsum dolor sit amet Lorem ipsum dosit amet Lorem ipsum dolor"; 104 | }else 105 | { 106 | self.dynamicLabel.text = @"Lorem ipsum dolor sit amet Lorem ipsum dolor"; 107 | } 108 | 109 | [self resizeTableViewHeader]; 110 | } 111 | 112 | @end -------------------------------------------------------------------------------- /UpdateAutoLayoutConstraints/Images.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" : "40x40", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "60x60", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "ipad", 20 | "size" : "29x29", 21 | "scale" : "1x" 22 | }, 23 | { 24 | "idiom" : "ipad", 25 | "size" : "29x29", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "ipad", 30 | "size" : "40x40", 31 | "scale" : "1x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "40x40", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "76x76", 41 | "scale" : "1x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "76x76", 46 | "scale" : "2x" 47 | } 48 | ], 49 | "info" : { 50 | "version" : 1, 51 | "author" : "xcode" 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /UpdateAutoLayoutConstraints/Images.xcassets/LaunchImage.launchimage/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "orientation" : "portrait", 5 | "idiom" : "iphone", 6 | "extent" : "full-screen", 7 | "minimum-system-version" : "7.0", 8 | "scale" : "2x" 9 | }, 10 | { 11 | "orientation" : "portrait", 12 | "idiom" : "iphone", 13 | "subtype" : "retina4", 14 | "extent" : "full-screen", 15 | "minimum-system-version" : "7.0", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "orientation" : "portrait", 20 | "idiom" : "ipad", 21 | "extent" : "full-screen", 22 | "minimum-system-version" : "7.0", 23 | "scale" : "1x" 24 | }, 25 | { 26 | "orientation" : "landscape", 27 | "idiom" : "ipad", 28 | "extent" : "full-screen", 29 | "minimum-system-version" : "7.0", 30 | "scale" : "1x" 31 | }, 32 | { 33 | "orientation" : "portrait", 34 | "idiom" : "ipad", 35 | "extent" : "full-screen", 36 | "minimum-system-version" : "7.0", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "orientation" : "landscape", 41 | "idiom" : "ipad", 42 | "extent" : "full-screen", 43 | "minimum-system-version" : "7.0", 44 | "scale" : "2x" 45 | } 46 | ], 47 | "info" : { 48 | "version" : 1, 49 | "author" : "xcode" 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /UpdateAutoLayoutConstraints/PodFiles/UIView+UpdateAutoLayoutConstraints.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+UpdateAutoLayoutConstant.h 3 | // ConstraintsCodeDemo 4 | // 5 | // Created by Damien Romito on 13/03/2014. 6 | // Copyright (c) 2014 Damien Romito. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIView (UpdateAutoLayoutConstraints) 12 | - (BOOL) setConstraintConstant:(CGFloat)constant forAttribute:(NSLayoutAttribute)attribute; 13 | - (CGFloat) constraintConstantforAttribute:(NSLayoutAttribute)attribute; 14 | - (NSLayoutConstraint*) constraintForAttribute:(NSLayoutAttribute)attribute; 15 | - (void)hideView:(BOOL)hidden byAttribute:(NSLayoutAttribute)attribute; 16 | - (void)hideByHeight:(BOOL)hidden; 17 | - (void)hideByWidth:(BOOL)hidden; 18 | - (CGSize) getSize; 19 | - (void)sizeToSubviews; 20 | - (void)updateSizes; 21 | @end 22 | -------------------------------------------------------------------------------- /UpdateAutoLayoutConstraints/PodFiles/UIView+UpdateAutoLayoutConstraints.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+UpdateAutoLayoutConstant.m 3 | // ConstraintsCodeDemo 4 | // 5 | // Created by Damien Romito on 13/03/2014. 6 | // Copyright (c) 2014 Damien Romito. All rights reserved. 7 | // 8 | 9 | #import "UIView+UpdateAutoLayoutConstraints.h" 10 | 11 | @implementation UIView (UpdateAutoLayoutConstraints) 12 | 13 | 14 | - (BOOL) setConstraintConstant:(CGFloat)constant forAttribute:(NSLayoutAttribute)attribute 15 | { 16 | NSLayoutConstraint * constraint = [self constraintForAttribute:attribute]; 17 | if(constraint) 18 | { 19 | [constraint setConstant:constant]; 20 | return YES; 21 | }else 22 | { 23 | [self.superview addConstraint: [NSLayoutConstraint constraintWithItem:self attribute:attribute relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0f constant:constant]]; 24 | return NO; 25 | } 26 | } 27 | 28 | 29 | - (CGFloat) constraintConstantforAttribute:(NSLayoutAttribute)attribute 30 | { 31 | NSLayoutConstraint * constraint = [self constraintForAttribute:attribute]; 32 | 33 | if (constraint) { 34 | return constraint.constant; 35 | }else 36 | { 37 | return NAN; 38 | } 39 | 40 | } 41 | 42 | 43 | - (NSLayoutConstraint*) constraintForAttribute:(NSLayoutAttribute)attribute 44 | { 45 | NSPredicate *predicate = [NSPredicate predicateWithFormat:@"firstAttribute = %d && firstItem = %@", attribute, self]; 46 | NSArray *fillteredArray = [[self.superview constraints] filteredArrayUsingPredicate:predicate]; 47 | if(fillteredArray.count == 0) 48 | { 49 | return nil; 50 | }else 51 | { 52 | return fillteredArray.firstObject; 53 | } 54 | } 55 | 56 | 57 | - (void)hideByHeight:(BOOL)hidden 58 | { 59 | [self hideView:hidden byAttribute:NSLayoutAttributeHeight]; 60 | } 61 | 62 | 63 | - (void)hideByWidth:(BOOL)hidden 64 | { 65 | [self hideView:hidden byAttribute:NSLayoutAttributeWidth]; 66 | } 67 | 68 | 69 | 70 | - (void)hideView:(BOOL)hidden byAttribute:(NSLayoutAttribute)attribute 71 | { 72 | if (self.hidden != hidden) { 73 | CGFloat constraintConstant = [self constraintConstantforAttribute:attribute]; 74 | 75 | if (hidden) 76 | { 77 | 78 | if (!isnan(constraintConstant)) { 79 | self.alpha = constraintConstant; 80 | }else 81 | { 82 | CGSize size = [self getSize]; 83 | self.alpha = (attribute == NSLayoutAttributeHeight)?size.height:size.width; 84 | } 85 | 86 | [self setConstraintConstant:0 forAttribute:attribute]; 87 | self.hidden = YES; 88 | 89 | }else 90 | { 91 | if (!isnan(constraintConstant) ) { 92 | self.hidden = NO; 93 | [self setConstraintConstant:self.alpha forAttribute:attribute]; 94 | self.alpha = 1; 95 | } 96 | } 97 | } 98 | } 99 | 100 | 101 | - (CGSize) getSize 102 | { 103 | [self updateSizes]; 104 | return CGSizeMake(self.bounds.size.width, self.bounds.size.height); 105 | } 106 | 107 | - (void)updateSizes 108 | { 109 | [self setNeedsLayout]; 110 | [self layoutIfNeeded]; 111 | } 112 | 113 | - (void)sizeToSubviews 114 | { 115 | [self updateSizes]; 116 | CGSize fittingSize = [self systemLayoutSizeFittingSize: UILayoutFittingCompressedSize]; 117 | self.frame = CGRectMake(0, 0, 320, fittingSize.height); 118 | } 119 | 120 | 121 | @end 122 | -------------------------------------------------------------------------------- /UpdateAutoLayoutConstraints/UpdateAutoLayoutConstraints-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | org.cocoapods.demo.${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 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /UpdateAutoLayoutConstraints/UpdateAutoLayoutConstraints-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header 3 | // 4 | // The contents of this file are implicitly included at the beginning of every source file. 5 | // 6 | 7 | #import 8 | 9 | #ifndef __IPHONE_5_0 10 | #warning "This project uses features only available in iOS SDK 5.0 and later." 11 | #endif 12 | 13 | #ifdef __OBJC__ 14 | #import 15 | #import 16 | #endif 17 | -------------------------------------------------------------------------------- /UpdateAutoLayoutConstraints/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /UpdateAutoLayoutConstraints/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // UpdateAutoLayoutConstraints 4 | // 5 | // Created by Damien on 03/05/2015. 6 | // Copyright (c) 2014 Damien. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "DRAppDelegate.h" 12 | 13 | int main(int argc, char * argv[]) 14 | { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([DRAppDelegate class])); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /picture.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/damienromito/UIView-UpdateAutoLayoutConstraints/76622fbac2dacfee262ca926c52ce9303f584ecc/picture.jpg --------------------------------------------------------------------------------