├── .gitignore ├── Classes ├── AutomaticLayoutChangesController.h ├── AutomaticLayoutChangesController.m ├── AutomaticLayoutChangesController.xib ├── AutomaticLayoutChangesView.h ├── AutomaticLayoutChangesView.m ├── AutomaticLayoutChangesView.xib ├── GridLayoutController.h ├── GridLayoutController.m ├── GridLayoutController.xib ├── GridLayoutView.h ├── GridLayoutView.m ├── GridLayoutView.xib ├── LayoutSupportController.h ├── LayoutSupportController.m ├── LayoutSupportController.xib ├── LoadFromCodeController.h ├── LoadFromCodeController.m ├── LoadFromCodeController.xib ├── LoadFromCodeView.h ├── LoadFromCodeView.m ├── LoadFromNIBController.h ├── LoadFromNIBController.m ├── LoadFromNIBController.xib ├── LoadFromNIBView+IB.h ├── LoadFromNIBView.h ├── LoadFromNIBView.m ├── LoadFromNIBView.xib ├── NMViewAppDelegate.h ├── NMViewAppDelegate.m ├── TestLayoutsView.h ├── TestLayoutsView.m ├── TestLayoutsView.xib ├── ViewTemplatesController.h ├── ViewTemplatesController.m ├── ViewTemplatesController.xib ├── ViewTemplatesView+IB.h ├── ViewTemplatesView.h ├── ViewTemplatesView.m └── ViewTemplatesView.xib ├── LICENSE ├── Libraries └── NMView │ ├── NMExplicitLayout.h │ ├── NMExplicitLayout.m │ ├── NMExplicitLayoutManager.h │ ├── NMExplicitLayoutManager.m │ ├── NMGridLayoutManager.h │ ├── NMGridLayoutManager.m │ ├── NMView.h │ ├── NMView.m │ ├── NMViewLayoutManager.h │ ├── NMViewLayoutManager.m │ ├── NMViewLayoutOmitSubviewsView.h │ ├── NMViewLayoutOmitSubviewsView.m │ ├── NMViewLayoutView.h │ ├── NMViewLayoutView.m │ ├── UIImage+NMNSCoding.h │ ├── UIImage+NMNSCoding.m │ ├── UIView+NMTemplating.h │ └── UIView+NMTemplating.m ├── NMView.xcodeproj └── project.pbxproj ├── NMView_Prefix.pch ├── README.markdown ├── Resources ├── Icon-72.png ├── MainWindow.xib └── NMView-Info.plist └── main.m /.gitignore: -------------------------------------------------------------------------------- 1 | # Build folder 2 | build 3 | 4 | # User-specific files 5 | *.pbxuser 6 | *.mode1v3 7 | 8 | # Xcode 4 9 | *.xcworkspace 10 | xcuserdata 11 | 12 | # Mac OS X 13 | .DS_Store 14 | -------------------------------------------------------------------------------- /Classes/AutomaticLayoutChangesController.h: -------------------------------------------------------------------------------- 1 | // 2 | // AutomaticLayoutChangesController.h 3 | // NMView 4 | // 5 | // Created by Benjamin Broll on 24.03.11. 6 | // Copyright 2011 NEXT Munich GmbH. The App Agency. All rights reserved. 7 | // 8 | 9 | /* 10 | * The BSD License 11 | * http://www.opensource.org/licenses/bsd-license.php 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * - Redistributions of source code must retain the above copyright notice, this 17 | * list of conditions and the following disclaimer. 18 | * - Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * - Neither the name of NEXT Munich GmbH nor the names of its contributors may 22 | * be used to endorse or promote products derived from this software without 23 | * specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | * POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | #import 39 | 40 | 41 | /** 42 | * This sample illustrates automatic layout changes of an NMView whenever the 43 | * view's -layoutSubviews method is called. 44 | * 45 | * Automatic layout changes can be activated by setting the 46 | * automaticLayoutChangesEnabled property of your NMView to YES. In case you set 47 | * the property in -viewDidLoad of your NMView subclass, the initialization of 48 | * the NMView will already automatically apply the most suitable layout for the 49 | * bounds of the view set during initialization. 50 | * 51 | * Pro Tip: 52 | * 53 | * It also showcases that you can force NMView to stop applying a layout at any 54 | * depth in the alternative layout. If at any point in your layout a view of 55 | * type NMViewLayoutOmitSubviewsView is encountered, NMView will not change the 56 | * position / size of its subviews but will continue with its next sibling. 57 | * This allows automatic layouting using the autoresizing to be performed on 58 | * parts of a layout. As an example, see how the UIActivityIndicator does not 59 | * change position according to the alternative layout's position for the 60 | * UIActivityIndicator but rather according to the indicator's autoresizing 61 | * properties. 62 | */ 63 | @interface AutomaticLayoutChangesController : UIViewController { 64 | 65 | } 66 | 67 | @end 68 | -------------------------------------------------------------------------------- /Classes/AutomaticLayoutChangesController.m: -------------------------------------------------------------------------------- 1 | // 2 | // AutomaticLayoutChangesController.m 3 | // NMView 4 | // 5 | // Created by Benjamin Broll on 24.03.11. 6 | // Copyright 2011 NEXT Munich GmbH. The App Agency. All rights reserved. 7 | // 8 | 9 | /* 10 | * The BSD License 11 | * http://www.opensource.org/licenses/bsd-license.php 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * - Redistributions of source code must retain the above copyright notice, this 17 | * list of conditions and the following disclaimer. 18 | * - Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * - Neither the name of NEXT Munich GmbH nor the names of its contributors may 22 | * be used to endorse or promote products derived from this software without 23 | * specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | * POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | #import "AutomaticLayoutChangesController.h" 39 | 40 | 41 | @implementation AutomaticLayoutChangesController 42 | 43 | - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 44 | // We allow any interface orientation which will resize our view in case of 45 | // an orientation change. This in turn will cause its subviews to be 46 | // re-layouted using -layoutSubviews which in turn causes the 47 | // AutomaticLayoutChangesView to search the best layout for the current 48 | // view bounds. 49 | return YES; 50 | } 51 | 52 | @end 53 | -------------------------------------------------------------------------------- /Classes/AutomaticLayoutChangesController.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 1056 5 | 10J869 6 | 823 7 | 1038.35 8 | 461.00 9 | 10 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 11 | 132 12 | 13 | 14 | YES 15 | 16 | 17 | 18 | YES 19 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 20 | 21 | 22 | YES 23 | 24 | YES 25 | 26 | 27 | YES 28 | 29 | 30 | 31 | YES 32 | 33 | IBFilesOwner 34 | IBIPadFramework 35 | 36 | 37 | IBFirstResponder 38 | IBIPadFramework 39 | 40 | 41 | 42 | 292 43 | 44 | YES 45 | 46 | 47 | 274 48 | {768, 1004} 49 | 50 | 51 | 3 52 | MQA 53 | 54 | 2 55 | 56 | 57 | IBIPadFramework 58 | 59 | 60 | {768, 1004} 61 | 62 | 63 | 3 64 | MQA 65 | 66 | 67 | NO 68 | 69 | 2 70 | 71 | IBIPadFramework 72 | 73 | 74 | 75 | 76 | YES 77 | 78 | 79 | view 80 | 81 | 82 | 83 | 3 84 | 85 | 86 | 87 | 88 | YES 89 | 90 | 0 91 | 92 | 93 | 94 | 95 | 96 | -1 97 | 98 | 99 | File's Owner 100 | 101 | 102 | -2 103 | 104 | 105 | 106 | 107 | 2 108 | 109 | 110 | YES 111 | 112 | 113 | 114 | 115 | 116 | 4 117 | 118 | 119 | 120 | 121 | 122 | 123 | YES 124 | 125 | YES 126 | -1.CustomClassName 127 | -2.CustomClassName 128 | 2.IBEditorWindowLastContentRect 129 | 2.IBPluginDependency 130 | 4.CustomClassName 131 | 4.IBPluginDependency 132 | 133 | 134 | YES 135 | AutomaticLayoutChangesController 136 | UIResponder 137 | {{461, 0}, {783, 856}} 138 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 139 | AutomaticLayoutChangesView 140 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 141 | 142 | 143 | 144 | YES 145 | 146 | 147 | YES 148 | 149 | 150 | 151 | 152 | YES 153 | 154 | 155 | YES 156 | 157 | 158 | 159 | 4 160 | 161 | 162 | 163 | YES 164 | 165 | AutomaticLayoutChangesController 166 | UIViewController 167 | 168 | IBProjectSource 169 | Classes/AutomaticLayoutChangesController.h 170 | 171 | 172 | 173 | AutomaticLayoutChangesView 174 | NMView 175 | 176 | IBProjectSource 177 | Classes/AutomaticLayoutChangesView.h 178 | 179 | 180 | 181 | NMView 182 | UIView 183 | 184 | IBProjectSource 185 | Classes/NMView.h 186 | 187 | 188 | 189 | UIView 190 | 191 | IBProjectSource 192 | Classes/UIView+Templating.h 193 | 194 | 195 | 196 | 197 | YES 198 | 199 | NSObject 200 | 201 | IBFrameworkSource 202 | Foundation.framework/Headers/NSError.h 203 | 204 | 205 | 206 | NSObject 207 | 208 | IBFrameworkSource 209 | Foundation.framework/Headers/NSFileManager.h 210 | 211 | 212 | 213 | NSObject 214 | 215 | IBFrameworkSource 216 | Foundation.framework/Headers/NSKeyValueCoding.h 217 | 218 | 219 | 220 | NSObject 221 | 222 | IBFrameworkSource 223 | Foundation.framework/Headers/NSKeyValueObserving.h 224 | 225 | 226 | 227 | NSObject 228 | 229 | IBFrameworkSource 230 | Foundation.framework/Headers/NSKeyedArchiver.h 231 | 232 | 233 | 234 | NSObject 235 | 236 | IBFrameworkSource 237 | Foundation.framework/Headers/NSObject.h 238 | 239 | 240 | 241 | NSObject 242 | 243 | IBFrameworkSource 244 | Foundation.framework/Headers/NSRunLoop.h 245 | 246 | 247 | 248 | NSObject 249 | 250 | IBFrameworkSource 251 | Foundation.framework/Headers/NSThread.h 252 | 253 | 254 | 255 | NSObject 256 | 257 | IBFrameworkSource 258 | Foundation.framework/Headers/NSURL.h 259 | 260 | 261 | 262 | NSObject 263 | 264 | IBFrameworkSource 265 | Foundation.framework/Headers/NSURLConnection.h 266 | 267 | 268 | 269 | NSObject 270 | 271 | IBFrameworkSource 272 | UIKit.framework/Headers/UIAccessibility.h 273 | 274 | 275 | 276 | NSObject 277 | 278 | IBFrameworkSource 279 | UIKit.framework/Headers/UINibLoading.h 280 | 281 | 282 | 283 | NSObject 284 | 285 | IBFrameworkSource 286 | UIKit.framework/Headers/UIResponder.h 287 | 288 | 289 | 290 | UIResponder 291 | NSObject 292 | 293 | 294 | 295 | UISearchBar 296 | UIView 297 | 298 | IBFrameworkSource 299 | UIKit.framework/Headers/UISearchBar.h 300 | 301 | 302 | 303 | UISearchDisplayController 304 | NSObject 305 | 306 | IBFrameworkSource 307 | UIKit.framework/Headers/UISearchDisplayController.h 308 | 309 | 310 | 311 | UIView 312 | 313 | IBFrameworkSource 314 | UIKit.framework/Headers/UIPrintFormatter.h 315 | 316 | 317 | 318 | UIView 319 | 320 | IBFrameworkSource 321 | UIKit.framework/Headers/UITextField.h 322 | 323 | 324 | 325 | UIView 326 | UIResponder 327 | 328 | IBFrameworkSource 329 | UIKit.framework/Headers/UIView.h 330 | 331 | 332 | 333 | UIViewController 334 | 335 | IBFrameworkSource 336 | UIKit.framework/Headers/UINavigationController.h 337 | 338 | 339 | 340 | UIViewController 341 | 342 | IBFrameworkSource 343 | UIKit.framework/Headers/UIPopoverController.h 344 | 345 | 346 | 347 | UIViewController 348 | 349 | IBFrameworkSource 350 | UIKit.framework/Headers/UISplitViewController.h 351 | 352 | 353 | 354 | UIViewController 355 | 356 | IBFrameworkSource 357 | UIKit.framework/Headers/UITabBarController.h 358 | 359 | 360 | 361 | UIViewController 362 | UIResponder 363 | 364 | IBFrameworkSource 365 | UIKit.framework/Headers/UIViewController.h 366 | 367 | 368 | 369 | 370 | 0 371 | IBIPadFramework 372 | 373 | com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS 374 | 375 | 376 | 377 | com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3 378 | 379 | 380 | YES 381 | ../NMViewAdvancedLayouts.xcodeproj 382 | 3 383 | 132 384 | 385 | 386 | -------------------------------------------------------------------------------- /Classes/AutomaticLayoutChangesView.h: -------------------------------------------------------------------------------- 1 | // 2 | // PLAutoChangeView.h 3 | // NMView 4 | // 5 | // Created by Benjamin Broll on 17.02.11. 6 | // Copyright 2011 NEXT Munich GmbH. The App Agency. All rights reserved. 7 | // 8 | 9 | /* 10 | * The BSD License 11 | * http://www.opensource.org/licenses/bsd-license.php 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * - Redistributions of source code must retain the above copyright notice, this 17 | * list of conditions and the following disclaimer. 18 | * - Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * - Neither the name of NEXT Munich GmbH nor the names of its contributors may 22 | * be used to endorse or promote products derived from this software without 23 | * specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | * POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | #import 39 | 40 | #import "NMView.h" 41 | 42 | 43 | @interface AutomaticLayoutChangesView : NMView { 44 | 45 | } 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /Classes/AutomaticLayoutChangesView.m: -------------------------------------------------------------------------------- 1 | // 2 | // AutomaticLayoutChangesView.m 3 | // NMView 4 | // 5 | // Created by Benjamin Broll on 17.02.11. 6 | // Copyright 2011 NEXT Munich GmbH. The App Agency. All rights reserved. 7 | // 8 | 9 | /* 10 | * The BSD License 11 | * http://www.opensource.org/licenses/bsd-license.php 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * - Redistributions of source code must retain the above copyright notice, this 17 | * list of conditions and the following disclaimer. 18 | * - Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * - Neither the name of NEXT Munich GmbH nor the names of its contributors may 22 | * be used to endorse or promote products derived from this software without 23 | * specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | * POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | #import "AutomaticLayoutChangesView.h" 39 | 40 | #define TESTLAYOUTSVIEW_TAG 2001 41 | 42 | 43 | @implementation AutomaticLayoutChangesView 44 | 45 | - (void)viewDidLoad { 46 | [super viewDidLoad]; 47 | 48 | // Activate automatic layout changes for the current view and the NMView 49 | // embedded in this view's view hierarchy. 50 | // 51 | // Important notes: 52 | // (1) When using -viewWithTag:, you need to make sure that the tags of 53 | // different UIView subclasses don't interfere. As an example, if 54 | // TESTLAYOUTSVIEW_TAG (in AutomaticLayoutChangesView) and 55 | // TEXT_TAG (in TestLayoutsView) happened to be the same value, your 56 | // code would crash. 57 | self.automaticLayoutChangeEnabled = YES; 58 | NMView *v = (NMView *)[self viewWithTag:TESTLAYOUTSVIEW_TAG]; 59 | v.automaticLayoutChangeEnabled = YES; 60 | } 61 | 62 | @end 63 | -------------------------------------------------------------------------------- /Classes/GridLayoutController.h: -------------------------------------------------------------------------------- 1 | // 2 | // GridLayoutController.h 3 | // NMView 4 | // 5 | // Created by Benjamin Broll on 29.06.11. 6 | // Copyright 2011 NEXT Munich. The App Agency. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | @interface GridLayoutController : UIViewController { 13 | 14 | } 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /Classes/GridLayoutController.m: -------------------------------------------------------------------------------- 1 | // 2 | // GridLayoutController.m 3 | // NMView 4 | // 5 | // Created by Benjamin Broll on 29.06.11. 6 | // Copyright 2011 NEXT Munich. The App Agency. All rights reserved. 7 | // 8 | 9 | #import "GridLayoutController.h" 10 | 11 | 12 | @implementation GridLayoutController 13 | 14 | - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 15 | // Overriden to allow any orientation. 16 | return YES; 17 | } 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /Classes/GridLayoutController.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 1056 5 | 10K540 6 | 823 7 | 1038.36 8 | 461.00 9 | 10 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 11 | 132 12 | 13 | 14 | YES 15 | 16 | 17 | 18 | YES 19 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 20 | 21 | 22 | YES 23 | 24 | YES 25 | 26 | 27 | YES 28 | 29 | 30 | 31 | YES 32 | 33 | IBFilesOwner 34 | IBIPadFramework 35 | 36 | 37 | IBFirstResponder 38 | IBIPadFramework 39 | 40 | 41 | 42 | 292 43 | 44 | YES 45 | 46 | 47 | 274 48 | {768, 1004} 49 | 50 | 51 | 3 52 | MQA 53 | 54 | 2 55 | 56 | 57 | IBIPadFramework 58 | 59 | 60 | {768, 1004} 61 | 62 | 63 | 3 64 | MQA 65 | 66 | 67 | NO 68 | 69 | 2 70 | 71 | IBIPadFramework 72 | 73 | 74 | 75 | 76 | YES 77 | 78 | 79 | view 80 | 81 | 82 | 83 | 3 84 | 85 | 86 | 87 | 88 | YES 89 | 90 | 0 91 | 92 | 93 | 94 | 95 | 96 | -1 97 | 98 | 99 | File's Owner 100 | 101 | 102 | -2 103 | 104 | 105 | 106 | 107 | 2 108 | 109 | 110 | YES 111 | 112 | 113 | 114 | 115 | 116 | 4 117 | 118 | 119 | 120 | 121 | 122 | 123 | YES 124 | 125 | YES 126 | -1.CustomClassName 127 | -2.CustomClassName 128 | 2.IBEditorWindowLastContentRect 129 | 2.IBPluginDependency 130 | 4.CustomClassName 131 | 4.IBPluginDependency 132 | 133 | 134 | YES 135 | GridLayoutController 136 | UIResponder 137 | {{461, 0}, {783, 856}} 138 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 139 | GridLayoutView 140 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 141 | 142 | 143 | 144 | YES 145 | 146 | 147 | YES 148 | 149 | 150 | 151 | 152 | YES 153 | 154 | 155 | YES 156 | 157 | 158 | 159 | 4 160 | 161 | 162 | 163 | YES 164 | 165 | GridLayoutController 166 | UIViewController 167 | 168 | IBProjectSource 169 | Classes/GridLayoutController.h 170 | 171 | 172 | 173 | GridLayoutView 174 | NMView 175 | 176 | IBProjectSource 177 | Classes/GridLayoutView.h 178 | 179 | 180 | 181 | NMView 182 | UIView 183 | 184 | layoutManager 185 | NMViewLayoutManager 186 | 187 | 188 | layoutManager 189 | 190 | layoutManager 191 | NMViewLayoutManager 192 | 193 | 194 | 195 | IBProjectSource 196 | Libraries/NMView/NMView.h 197 | 198 | 199 | 200 | NMViewLayoutManager 201 | NSObject 202 | 203 | IBProjectSource 204 | Libraries/NMView/NMViewLayoutManager.h 205 | 206 | 207 | 208 | UIView 209 | 210 | IBProjectSource 211 | Libraries/NMView/UIView+NMTemplating.h 212 | 213 | 214 | 215 | 216 | YES 217 | 218 | NSObject 219 | 220 | IBFrameworkSource 221 | Foundation.framework/Headers/NSError.h 222 | 223 | 224 | 225 | NSObject 226 | 227 | IBFrameworkSource 228 | Foundation.framework/Headers/NSFileManager.h 229 | 230 | 231 | 232 | NSObject 233 | 234 | IBFrameworkSource 235 | Foundation.framework/Headers/NSKeyValueCoding.h 236 | 237 | 238 | 239 | NSObject 240 | 241 | IBFrameworkSource 242 | Foundation.framework/Headers/NSKeyValueObserving.h 243 | 244 | 245 | 246 | NSObject 247 | 248 | IBFrameworkSource 249 | Foundation.framework/Headers/NSKeyedArchiver.h 250 | 251 | 252 | 253 | NSObject 254 | 255 | IBFrameworkSource 256 | Foundation.framework/Headers/NSObject.h 257 | 258 | 259 | 260 | NSObject 261 | 262 | IBFrameworkSource 263 | Foundation.framework/Headers/NSRunLoop.h 264 | 265 | 266 | 267 | NSObject 268 | 269 | IBFrameworkSource 270 | Foundation.framework/Headers/NSThread.h 271 | 272 | 273 | 274 | NSObject 275 | 276 | IBFrameworkSource 277 | Foundation.framework/Headers/NSURL.h 278 | 279 | 280 | 281 | NSObject 282 | 283 | IBFrameworkSource 284 | Foundation.framework/Headers/NSURLConnection.h 285 | 286 | 287 | 288 | NSObject 289 | 290 | IBFrameworkSource 291 | UIKit.framework/Headers/UIAccessibility.h 292 | 293 | 294 | 295 | NSObject 296 | 297 | IBFrameworkSource 298 | UIKit.framework/Headers/UINibLoading.h 299 | 300 | 301 | 302 | NSObject 303 | 304 | IBFrameworkSource 305 | UIKit.framework/Headers/UIResponder.h 306 | 307 | 308 | 309 | UIResponder 310 | NSObject 311 | 312 | 313 | 314 | UISearchBar 315 | UIView 316 | 317 | IBFrameworkSource 318 | UIKit.framework/Headers/UISearchBar.h 319 | 320 | 321 | 322 | UISearchDisplayController 323 | NSObject 324 | 325 | IBFrameworkSource 326 | UIKit.framework/Headers/UISearchDisplayController.h 327 | 328 | 329 | 330 | UIView 331 | 332 | IBFrameworkSource 333 | UIKit.framework/Headers/UIPrintFormatter.h 334 | 335 | 336 | 337 | UIView 338 | 339 | IBFrameworkSource 340 | UIKit.framework/Headers/UITextField.h 341 | 342 | 343 | 344 | UIView 345 | UIResponder 346 | 347 | IBFrameworkSource 348 | UIKit.framework/Headers/UIView.h 349 | 350 | 351 | 352 | UIViewController 353 | 354 | IBFrameworkSource 355 | UIKit.framework/Headers/UINavigationController.h 356 | 357 | 358 | 359 | UIViewController 360 | 361 | IBFrameworkSource 362 | UIKit.framework/Headers/UIPopoverController.h 363 | 364 | 365 | 366 | UIViewController 367 | 368 | IBFrameworkSource 369 | UIKit.framework/Headers/UISplitViewController.h 370 | 371 | 372 | 373 | UIViewController 374 | 375 | IBFrameworkSource 376 | UIKit.framework/Headers/UITabBarController.h 377 | 378 | 379 | 380 | UIViewController 381 | UIResponder 382 | 383 | IBFrameworkSource 384 | UIKit.framework/Headers/UIViewController.h 385 | 386 | 387 | 388 | 389 | 0 390 | IBIPadFramework 391 | 392 | com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS 393 | 394 | 395 | 396 | com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3 397 | 398 | 399 | YES 400 | ../NMView.xcodeproj 401 | 3 402 | 132 403 | 404 | 405 | -------------------------------------------------------------------------------- /Classes/GridLayoutView.h: -------------------------------------------------------------------------------- 1 | // 2 | // GridLayoutView.h 3 | // NMView 4 | // 5 | // Created by Benjamin Broll on 29.06.11. 6 | // Copyright 2011 NEXT Munich. The App Agency. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "NMView.h" 12 | 13 | 14 | @interface GridLayoutView : NMView { 15 | 16 | } 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /Classes/GridLayoutView.m: -------------------------------------------------------------------------------- 1 | // 2 | // GridLayoutView.m 3 | // NMView 4 | // 5 | // Created by Benjamin Broll on 29.06.11. 6 | // Copyright 2011 NEXT Munich. The App Agency. All rights reserved. 7 | // 8 | 9 | #import "GridLayoutView.h" 10 | 11 | 12 | @implementation GridLayoutView 13 | 14 | - (void)viewDidLoad { 15 | [super viewDidLoad]; 16 | 17 | self.automaticLayoutChangeEnabled = YES; 18 | } 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /Classes/LayoutSupportController.h: -------------------------------------------------------------------------------- 1 | // 2 | // LayoutSupportController.h 3 | // NMView 4 | // 5 | // Created by Benjamin Broll on 17.02.11. 6 | // Copyright 2011 NEXT Munich GmbH. The App Agency. All rights reserved. 7 | // 8 | 9 | /* 10 | * The BSD License 11 | * http://www.opensource.org/licenses/bsd-license.php 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * - Redistributions of source code must retain the above copyright notice, this 17 | * list of conditions and the following disclaimer. 18 | * - Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * - Neither the name of NEXT Munich GmbH nor the names of its contributors may 22 | * be used to endorse or promote products derived from this software without 23 | * specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | * POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | #import 39 | 40 | @class NMView; 41 | 42 | 43 | /** 44 | * This sample illustrates using different layouts based for an NMView instance. 45 | * 46 | * Sometimes, views need to be layouted differently when significantly changing 47 | * the view's aspect ratio: it may have two completely different layouts of the 48 | * same controls depending on whether it is displayed in portrait or landscape 49 | * mode. 50 | * 51 | * NMView supports creating multiple layouts of the same view in the nib file 52 | * and will record the layouts during nib loading. Once loading is complete, the 53 | * view can manually be requested to investigate whether a more suitable 54 | * layout is available. If the automaticLayoutChangeEnabled property is set to 55 | * YES, the view will automatically adapt the layout in -layoutSubviews. 56 | * 57 | * The sample provides an NMView with three different layouts and a button which 58 | * cycles through the different layouts. The background color of the view is 59 | * changed only to better visualize which layout is currently in effect. 60 | */ 61 | @interface LayoutSupportController : UIViewController { 62 | 63 | NMView *v; 64 | 65 | } 66 | 67 | @property (nonatomic, retain) IBOutlet NMView *v; 68 | 69 | - (IBAction)switchLayout; 70 | 71 | @end 72 | -------------------------------------------------------------------------------- /Classes/LayoutSupportController.m: -------------------------------------------------------------------------------- 1 | // 2 | // LayoutSupportController.m 3 | // NMView 4 | // 5 | // Created by Benjamin Broll on 17.02.11. 6 | // Copyright 2011 NEXT Munich GmbH. The App Agency. All rights reserved. 7 | // 8 | 9 | /* 10 | * The BSD License 11 | * http://www.opensource.org/licenses/bsd-license.php 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * - Redistributions of source code must retain the above copyright notice, this 17 | * list of conditions and the following disclaimer. 18 | * - Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * - Neither the name of NEXT Munich GmbH nor the names of its contributors may 22 | * be used to endorse or promote products derived from this software without 23 | * specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | * POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | /* 39 | * The BSD License 40 | * http://www.opensource.org/licenses/bsd-license.php 41 | * 42 | * Redistribution and use in source and binary forms, with or without 43 | * modification, are permitted provided that the following conditions are met: 44 | * 45 | * - Redistributions of source code must retain the above copyright notice, this 46 | * list of conditions and the following disclaimer. 47 | * - Redistributions in binary form must reproduce the above copyright notice, 48 | * this list of conditions and the following disclaimer in the documentation 49 | * and/or other materials provided with the distribution. 50 | * 51 | * Neither the name of NEXT Munich GmbH nor the names of its contributors may be 52 | * used to endorse or promote products derived from this software without 53 | * specific prior written permission. 54 | * 55 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 56 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 57 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 58 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 59 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 60 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 61 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 62 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 63 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 64 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 65 | * POSSIBILITY OF SUCH DAMAGE. 66 | */ 67 | 68 | #import "LayoutSupportController.h" 69 | 70 | #import "NMView.h" 71 | 72 | 73 | @implementation LayoutSupportController 74 | 75 | #pragma mark Properties 76 | 77 | @synthesize v; 78 | 79 | 80 | #pragma mark Button Actions 81 | 82 | - (IBAction)switchLayout { 83 | static int mode = 1; 84 | 85 | // Wrap the change of layout using an animation block to animate the layout 86 | // changes. 87 | [UIView beginAnimations:@"move" context:nil]; 88 | [UIView setAnimationDuration:0.5]; 89 | 90 | // We change the bounds of our view depending on the current state. 91 | if (mode == 0) { 92 | v.center = CGPointMake(70, 120); 93 | v.bounds = CGRectMake(0, 0, 100, 200); 94 | v.backgroundColor = [UIColor yellowColor]; 95 | } else if (mode == 1) { 96 | v.center = CGPointMake(120, 120); 97 | v.bounds = CGRectMake(0, 0, 200, 200); 98 | v.backgroundColor = [UIColor orangeColor]; 99 | } else if (mode == 2) { 100 | v.center = CGPointMake(120, 70); 101 | v.bounds = CGRectMake(0, 0, 200, 100); 102 | v.backgroundColor = [UIColor redColor]; 103 | } else { 104 | v.center = CGPointMake(220, 220); 105 | v.bounds = CGRectMake(0, 0, 400, 400); 106 | v.backgroundColor = [UIColor greenColor]; 107 | } 108 | 109 | // Now we request the view to investigate, whether - based on the new 110 | // bounds - a different layout should be displayed. 111 | [v changeLayoutIfNecessary]; 112 | 113 | [UIView commitAnimations]; 114 | 115 | mode = (mode+1)%4; 116 | } 117 | 118 | 119 | #pragma mark Memory Lifecycle 120 | 121 | - (void)viewDidLoad { 122 | [super viewDidLoad]; 123 | 124 | v.backgroundColor = [UIColor yellowColor]; 125 | } 126 | 127 | - (void)viewDidUnload { 128 | [super viewDidUnload]; 129 | 130 | self.v = nil; 131 | } 132 | 133 | - (void)dealloc { 134 | self.v = nil; 135 | 136 | [super dealloc]; 137 | } 138 | 139 | @end 140 | -------------------------------------------------------------------------------- /Classes/LoadFromCodeController.h: -------------------------------------------------------------------------------- 1 | // 2 | // LoadFromCodeController.h 3 | // NMView 4 | // 5 | // Created by Benjamin Broll on 24.03.11. 6 | // Copyright 2011 NEXT Munich GmbH. The App Agency. All rights reserved. 7 | // 8 | 9 | /* 10 | * The BSD License 11 | * http://www.opensource.org/licenses/bsd-license.php 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * - Redistributions of source code must retain the above copyright notice, this 17 | * list of conditions and the following disclaimer. 18 | * - Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * - Neither the name of NEXT Munich GmbH nor the names of its contributors may 22 | * be used to endorse or promote products derived from this software without 23 | * specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | * POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | #import 39 | 40 | @class LoadFromCodeView; 41 | 42 | 43 | /** 44 | * This sample illustrates how one can programmatically create the UI of an 45 | * NMView by overriding -createView. 46 | * 47 | * This approach is not what we're trying to achieve with NMView. We still make 48 | * life easier by providing a single method to override (-createView) regardless 49 | * of whether the view is constructed during nib loading (and thus with its 50 | * -initWithCoder: method) or by a call to -initWithFrame: 51 | * 52 | * The two different view objects created in this sample (view0 and view1) show 53 | * that the two initializers both create views with the expected layout. 54 | */ 55 | @interface LoadFromCodeController : UIViewController { 56 | 57 | LoadFromCodeView *view0; 58 | 59 | } 60 | 61 | @property (nonatomic, retain) IBOutlet LoadFromCodeView *view0; 62 | 63 | @end 64 | -------------------------------------------------------------------------------- /Classes/LoadFromCodeController.m: -------------------------------------------------------------------------------- 1 | // 2 | // LoadFromCodeController.m 3 | // NMView 4 | // 5 | // Created by Benjamin Broll on 24.03.11. 6 | // Copyright 2011 NEXT Munich GmbH. The App Agency. All rights reserved. 7 | // 8 | 9 | /* 10 | * The BSD License 11 | * http://www.opensource.org/licenses/bsd-license.php 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * - Redistributions of source code must retain the above copyright notice, this 17 | * list of conditions and the following disclaimer. 18 | * - Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * - Neither the name of NEXT Munich GmbH nor the names of its contributors may 22 | * be used to endorse or promote products derived from this software without 23 | * specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | * POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | #import "LoadFromCodeController.h" 39 | 40 | #import "LoadFromCodeView.h" 41 | 42 | 43 | @implementation LoadFromCodeController 44 | 45 | #pragma mark Properties 46 | 47 | @synthesize view0; 48 | 49 | 50 | #pragma mark Orientation Management 51 | 52 | - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { 53 | return YES; 54 | } 55 | 56 | 57 | #pragma mark Memory Lifecycle 58 | 59 | - (void)viewDidLoad { 60 | [super viewDidLoad]; 61 | 62 | // view0 has been loaded using the NIB of the controller. 63 | // If a UIView object is instantiated during NIB loading, its 64 | // -initWithcoder: method is used for initialization. 65 | view0.backgroundColor = [UIColor redColor]; 66 | 67 | // view1 is loaded from code and instantiated using the -initWithFrame: 68 | // method. 69 | CGRect subviewFrame = CGRectMake(0, 80, self.view.bounds.size.width, 40); 70 | LoadFromCodeView *view2 = [[[LoadFromCodeView alloc] initWithFrame:subviewFrame] autorelease]; 71 | view2.autoresizingMask = UIViewAutoresizingFlexibleWidth; 72 | view2.backgroundColor = [UIColor greenColor]; 73 | [self.view addSubview:view2]; 74 | } 75 | 76 | - (void)viewDidUnload { 77 | [super viewDidUnload]; 78 | 79 | self.view0 = nil; 80 | } 81 | 82 | - (void)dealloc { 83 | self.view0 = nil; 84 | 85 | [super dealloc]; 86 | } 87 | 88 | @end 89 | -------------------------------------------------------------------------------- /Classes/LoadFromCodeView.h: -------------------------------------------------------------------------------- 1 | // 2 | // LoadFromCodeView.h 3 | // NMView 4 | // 5 | // Created by Benjamin Broll on 24.03.11. 6 | // Copyright 2011 NEXT Munich GmbH. The App Agency. All rights reserved. 7 | // 8 | 9 | /* 10 | * The BSD License 11 | * http://www.opensource.org/licenses/bsd-license.php 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * - Redistributions of source code must retain the above copyright notice, this 17 | * list of conditions and the following disclaimer. 18 | * - Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * - Neither the name of NEXT Munich GmbH nor the names of its contributors may 22 | * be used to endorse or promote products derived from this software without 23 | * specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | * POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | #import 39 | 40 | #import "NMView.h" 41 | 42 | 43 | @interface LoadFromCodeView : NMView { 44 | 45 | } 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /Classes/LoadFromCodeView.m: -------------------------------------------------------------------------------- 1 | // 2 | // LoadFromCodeView.m 3 | // NMView 4 | // 5 | // Created by Benjamin Broll on 24.03.11. 6 | // Copyright 2011 NEXT Munich GmbH. The App Agency. All rights reserved. 7 | // 8 | 9 | /* 10 | * The BSD License 11 | * http://www.opensource.org/licenses/bsd-license.php 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * - Redistributions of source code must retain the above copyright notice, this 17 | * list of conditions and the following disclaimer. 18 | * - Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * - Neither the name of NEXT Munich GmbH nor the names of its contributors may 22 | * be used to endorse or promote products derived from this software without 23 | * specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | * POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | #import "LoadFromCodeView.h" 39 | 40 | 41 | @implementation LoadFromCodeView 42 | 43 | 44 | - (void)createView { 45 | // This is the only method we need to override in case we want to create our 46 | // view's layout in code. We don't have to know that -initWithCoder: or 47 | // -initWithFrame: can be used to instantiate the class. 48 | 49 | // The layout below creates a left- and a right-aligned label with 50 | // appropriate auto-resizing properties. 51 | 52 | CGRect frm = CGRectInset(self.bounds, 5, 5); 53 | 54 | // create a left-aligned label 55 | frm.size = CGSizeMake(frm.size.width/2, frm.size.height); 56 | UILabel *lblLeft = [[[UILabel alloc] initWithFrame:frm] autorelease]; 57 | lblLeft.backgroundColor = [UIColor clearColor]; 58 | lblLeft.text = @"I'm a left-aligned label."; 59 | lblLeft.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight; 60 | [self addSubview:lblLeft]; 61 | 62 | // create a right-aligned label 63 | frm.origin = CGPointMake(frm.origin.x+frm.size.width, frm.origin.y); 64 | UILabel *lblRight = [[[UILabel alloc] initWithFrame:frm] autorelease]; 65 | lblRight.backgroundColor = [UIColor clearColor]; 66 | lblRight.text = @"... and I'm right-aligned."; 67 | lblRight.textAlignment = UITextAlignmentRight; 68 | lblRight.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight; 69 | [self addSubview:lblRight]; 70 | } 71 | 72 | @end 73 | -------------------------------------------------------------------------------- /Classes/LoadFromNIBController.h: -------------------------------------------------------------------------------- 1 | // 2 | // LoadFromNIBController.h 3 | // NMView 4 | // 5 | // Created by Benjamin Broll on 24.03.11. 6 | // Copyright 2011 NEXT Munich GmbH. The App Agency. All rights reserved. 7 | // 8 | 9 | /* 10 | * The BSD License 11 | * http://www.opensource.org/licenses/bsd-license.php 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * - Redistributions of source code must retain the above copyright notice, this 17 | * list of conditions and the following disclaimer. 18 | * - Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * - Neither the name of NEXT Munich GmbH nor the names of its contributors may 22 | * be used to endorse or promote products derived from this software without 23 | * specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | * POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | #import 39 | 40 | @class LoadFromNIBView; 41 | 42 | 43 | /** 44 | * This sample illustrates the main benefit of working with NMView: creating 45 | * your custom UIView subclasses using Interface Builder. 46 | * 47 | * LoadFromNIBView has an associated nib file which defines the view's 48 | * properties and its subview hierarchy. The LoadFromNIBView has access to the 49 | * subviews via regular IB-integration with IBOutlet and IBAction. 50 | * 51 | * The sample also highlights some important points regarding the properties 52 | * defined in the view's nib in relation to the different initializers (see the 53 | * respective comments in -viewDidLoad). 54 | */ 55 | @interface LoadFromNIBController : UIViewController { 56 | 57 | LoadFromNIBView *view0; 58 | 59 | } 60 | 61 | @property (nonatomic, retain) IBOutlet LoadFromNIBView *view0; 62 | 63 | @end 64 | -------------------------------------------------------------------------------- /Classes/LoadFromNIBController.m: -------------------------------------------------------------------------------- 1 | // 2 | // LoadFromNIBController.m 3 | // NMView 4 | // 5 | // Created by Benjamin Broll on 24.03.11. 6 | // Copyright 2011 NEXT Munich GmbH. The App Agency. All rights reserved. 7 | // 8 | 9 | /* 10 | * The BSD License 11 | * http://www.opensource.org/licenses/bsd-license.php 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * - Redistributions of source code must retain the above copyright notice, this 17 | * list of conditions and the following disclaimer. 18 | * - Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * - Neither the name of NEXT Munich GmbH nor the names of its contributors may 22 | * be used to endorse or promote products derived from this software without 23 | * specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | * POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | #import "LoadFromNIBController.h" 39 | 40 | #import "LoadFromNIBView.h" 41 | #import "NMView.h" 42 | 43 | 44 | @implementation LoadFromNIBController 45 | 46 | #pragma mark Properties 47 | 48 | @synthesize view0; 49 | 50 | 51 | #pragma mark Memory Lifecycle 52 | 53 | - (void)viewDidLoad { 54 | [super viewDidLoad]; 55 | 56 | // --- 57 | // view0 has been initialized and loaded when the LoadFromNIBController's 58 | // view was loaded from the NIB. It's been initialized using -initWithCoder: 59 | // which in turn uses -loadViewWithNibName:bundle: passing nil / nil. 60 | // The default loading strategy of -loadViewWithNibName:bundle: tries to 61 | // load from the default bundle (if nil is passed) and tries to load a nib 62 | // which has the same name as the NMView subclass. Since the type of view0 63 | // has been set to LoadFromNIBView in IBs "Identity Inspector" of the view, 64 | // the LoadFromNIBView nib has been used for loading view0. 65 | // 66 | // Important things to note: 67 | // (1) The properties assigned to the LoadFromNIBView in the nib of 68 | // LoadFromNIBController (eg. the green background and the 69 | // clip subviews setting) will be overwritten 70 | // by the properties in LoadFromNIBView nib. The view's nib will always 71 | // take precedence over the nib using the view except for: 72 | // - the view's frame (the nib using the view takes precendence) 73 | // - the view's tag (the nib using the view takes precendence) 74 | view0.text = @"----> This is also a very long text that exceeds the view's bounds"; 75 | 76 | // --- 77 | // view1 is initialized using -initWithFrame: which in turn uses 78 | // -loadViewWithNibName:bundle: passing nil / nil to load the layout of the 79 | // view. Again, the default loading strategy discovers LoadFromNIBView nib 80 | // and uses that nib for creating the view's layout. 81 | // 82 | // Important things to note: 83 | // (1) The frame passed to -initWithFrame: will be applied after the view's 84 | // layout has been loaded from the nib. It takes precendence over the 85 | // frame set in the view's nib. 86 | // (2) After the view has been loaded, properties like the clip subviews 87 | // setting will, of course, take precedence over what was set in the 88 | // view's nib. 89 | CGRect subviewFrame = CGRectMake(20, self.view.bounds.size.height/2-50, 100, 100); 90 | LoadFromNIBView *view1 = [[[LoadFromNIBView alloc] initWithFrame:subviewFrame] autorelease]; 91 | view1.clipsToBounds = YES; 92 | [self.view addSubview:view1]; 93 | 94 | // --- 95 | // view2 is initialized as a regular NMView object, passing the name of nib 96 | // to load for creating the view's layout. 97 | // 98 | // Important things to note: 99 | // (1) -initWithNibName:bundle: applies the bounds set in the view's nib. 100 | // Thus, this instance of LoadFromNIBView is larger than the two above. 101 | // (2) We could be using 102 | // [[NMView alloc] initWithNibName:@"LoadFromNIBView" bundle:nil] to 103 | // initialize a generic NMView object from a nib. In this case it would 104 | // fail, however, since the nib tries to access the IBOutlet 105 | // activityIndicator which is not available on NMView but only on 106 | // LoadFromNIBView. Moreover, when using NMView, we would obviously not 107 | // have access to the text property. 108 | LoadFromNIBView *view2 = [[[LoadFromNIBView alloc] initWithNibName:nil bundle:nil] autorelease]; 109 | view2.frame = CGRectMake(20, self.view.bounds.size.height-view2.bounds.size.height-20, 110 | view2.bounds.size.width, view2.bounds.size.height); 111 | [self.view addSubview:view2]; 112 | } 113 | 114 | - (void)viewDidUnload { 115 | [super viewDidUnload]; 116 | 117 | self.view0 = nil; 118 | } 119 | 120 | - (void)dealloc { 121 | self.view0 = nil; 122 | 123 | [super dealloc]; 124 | } 125 | 126 | 127 | @end 128 | -------------------------------------------------------------------------------- /Classes/LoadFromNIBController.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 1056 5 | 10J869 6 | 823 7 | 1038.35 8 | 461.00 9 | 10 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 11 | 132 12 | 13 | 14 | YES 15 | 16 | 17 | 18 | YES 19 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 20 | 21 | 22 | YES 23 | 24 | YES 25 | 26 | 27 | YES 28 | 29 | 30 | 31 | YES 32 | 33 | IBFilesOwner 34 | IBIPadFramework 35 | 36 | 37 | IBFirstResponder 38 | IBIPadFramework 39 | 40 | 41 | 42 | 292 43 | 44 | YES 45 | 46 | 47 | 292 48 | {{20, 20}, {100, 100}} 49 | 50 | 51 | 1 52 | MC40NjY2NjY2NjY3IDAuNzU2ODYyNzQ1MSAwLjMwNTg4MjM1MjkAA 53 | 54 | YES 55 | IBIPadFramework 56 | 57 | 58 | {768, 1004} 59 | 60 | 61 | 3 62 | MQA 63 | 64 | 2 65 | 66 | 67 | NO 68 | 69 | 2 70 | 71 | IBIPadFramework 72 | 73 | 74 | 75 | 76 | YES 77 | 78 | 79 | view 80 | 81 | 82 | 83 | 3 84 | 85 | 86 | 87 | view0 88 | 89 | 90 | 91 | 5 92 | 93 | 94 | 95 | 96 | YES 97 | 98 | 0 99 | 100 | 101 | 102 | 103 | 104 | -1 105 | 106 | 107 | File's Owner 108 | 109 | 110 | -2 111 | 112 | 113 | 114 | 115 | 2 116 | 117 | 118 | YES 119 | 120 | 121 | 122 | 123 | 124 | 4 125 | 126 | 127 | 128 | 129 | 130 | 131 | YES 132 | 133 | YES 134 | -1.CustomClassName 135 | -2.CustomClassName 136 | 2.IBEditorWindowLastContentRect 137 | 2.IBPluginDependency 138 | 4.CustomClassName 139 | 4.IBPluginDependency 140 | 4.IBViewBoundsToFrameTransform 141 | 142 | 143 | YES 144 | LoadFromNIBController 145 | UIResponder 146 | {{461, 0}, {783, 856}} 147 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 148 | LoadFromNIBView 149 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 150 | 151 | P4AAAL+AAAAAAAAAwsQAAA 152 | 153 | 154 | 155 | 156 | YES 157 | 158 | 159 | YES 160 | 161 | 162 | 163 | 164 | YES 165 | 166 | 167 | YES 168 | 169 | 170 | 171 | 5 172 | 173 | 174 | 175 | YES 176 | 177 | LoadFromNIBController 178 | UIViewController 179 | 180 | view0 181 | LoadFromNIBView 182 | 183 | 184 | view0 185 | 186 | view0 187 | LoadFromNIBView 188 | 189 | 190 | 191 | IBProjectSource 192 | Classes/LoadFromNIBController.h 193 | 194 | 195 | 196 | LoadFromNIBView 197 | NMView 198 | 199 | IBProjectSource 200 | Classes/LoadFromNIBView.h 201 | 202 | 203 | 204 | NMView 205 | UIView 206 | 207 | IBProjectSource 208 | Classes/NMView.h 209 | 210 | 211 | 212 | UIView 213 | 214 | IBProjectSource 215 | Classes/UIView+Templating.h 216 | 217 | 218 | 219 | 220 | YES 221 | 222 | NSObject 223 | 224 | IBFrameworkSource 225 | Foundation.framework/Headers/NSError.h 226 | 227 | 228 | 229 | NSObject 230 | 231 | IBFrameworkSource 232 | Foundation.framework/Headers/NSFileManager.h 233 | 234 | 235 | 236 | NSObject 237 | 238 | IBFrameworkSource 239 | Foundation.framework/Headers/NSKeyValueCoding.h 240 | 241 | 242 | 243 | NSObject 244 | 245 | IBFrameworkSource 246 | Foundation.framework/Headers/NSKeyValueObserving.h 247 | 248 | 249 | 250 | NSObject 251 | 252 | IBFrameworkSource 253 | Foundation.framework/Headers/NSKeyedArchiver.h 254 | 255 | 256 | 257 | NSObject 258 | 259 | IBFrameworkSource 260 | Foundation.framework/Headers/NSObject.h 261 | 262 | 263 | 264 | NSObject 265 | 266 | IBFrameworkSource 267 | Foundation.framework/Headers/NSRunLoop.h 268 | 269 | 270 | 271 | NSObject 272 | 273 | IBFrameworkSource 274 | Foundation.framework/Headers/NSThread.h 275 | 276 | 277 | 278 | NSObject 279 | 280 | IBFrameworkSource 281 | Foundation.framework/Headers/NSURL.h 282 | 283 | 284 | 285 | NSObject 286 | 287 | IBFrameworkSource 288 | Foundation.framework/Headers/NSURLConnection.h 289 | 290 | 291 | 292 | NSObject 293 | 294 | IBFrameworkSource 295 | UIKit.framework/Headers/UIAccessibility.h 296 | 297 | 298 | 299 | NSObject 300 | 301 | IBFrameworkSource 302 | UIKit.framework/Headers/UINibLoading.h 303 | 304 | 305 | 306 | NSObject 307 | 308 | IBFrameworkSource 309 | UIKit.framework/Headers/UIResponder.h 310 | 311 | 312 | 313 | UIResponder 314 | NSObject 315 | 316 | 317 | 318 | UISearchBar 319 | UIView 320 | 321 | IBFrameworkSource 322 | UIKit.framework/Headers/UISearchBar.h 323 | 324 | 325 | 326 | UISearchDisplayController 327 | NSObject 328 | 329 | IBFrameworkSource 330 | UIKit.framework/Headers/UISearchDisplayController.h 331 | 332 | 333 | 334 | UIView 335 | 336 | IBFrameworkSource 337 | UIKit.framework/Headers/UIPrintFormatter.h 338 | 339 | 340 | 341 | UIView 342 | 343 | IBFrameworkSource 344 | UIKit.framework/Headers/UITextField.h 345 | 346 | 347 | 348 | UIView 349 | UIResponder 350 | 351 | IBFrameworkSource 352 | UIKit.framework/Headers/UIView.h 353 | 354 | 355 | 356 | UIViewController 357 | 358 | IBFrameworkSource 359 | UIKit.framework/Headers/UINavigationController.h 360 | 361 | 362 | 363 | UIViewController 364 | 365 | IBFrameworkSource 366 | UIKit.framework/Headers/UIPopoverController.h 367 | 368 | 369 | 370 | UIViewController 371 | 372 | IBFrameworkSource 373 | UIKit.framework/Headers/UISplitViewController.h 374 | 375 | 376 | 377 | UIViewController 378 | 379 | IBFrameworkSource 380 | UIKit.framework/Headers/UITabBarController.h 381 | 382 | 383 | 384 | UIViewController 385 | UIResponder 386 | 387 | IBFrameworkSource 388 | UIKit.framework/Headers/UIViewController.h 389 | 390 | 391 | 392 | 393 | 0 394 | IBIPadFramework 395 | 396 | com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS 397 | 398 | 399 | 400 | com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3 401 | 402 | 403 | YES 404 | ../NMViewAdvancedLayouts.xcodeproj 405 | 3 406 | 132 407 | 408 | 409 | -------------------------------------------------------------------------------- /Classes/LoadFromNIBView+IB.h: -------------------------------------------------------------------------------- 1 | // 2 | // LoadFromNIBView+IB.h 3 | // NMView 4 | // 5 | // Created by Benjamin Broll on 24.03.11. 6 | // Copyright 2011 NEXT Munich GmbH. The App Agency. All rights reserved. 7 | // 8 | 9 | /* 10 | * The BSD License 11 | * http://www.opensource.org/licenses/bsd-license.php 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * - Redistributions of source code must retain the above copyright notice, this 17 | * list of conditions and the following disclaimer. 18 | * - Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * - Neither the name of NEXT Munich GmbH nor the names of its contributors may 22 | * be used to endorse or promote products derived from this software without 23 | * specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | * POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | #import 39 | 40 | #import "LoadFromNIBView.h" 41 | 42 | 43 | /* 44 | * Contains all IB integration that should not be exposed as part of a public 45 | * API of LoadFromNIBView. 46 | */ 47 | @interface LoadFromNIBView (IB) 48 | 49 | @property (nonatomic, retain) IBOutlet UIActivityIndicatorView *activityIndicator; 50 | 51 | @end 52 | 53 | -------------------------------------------------------------------------------- /Classes/LoadFromNIBView.h: -------------------------------------------------------------------------------- 1 | // 2 | // LoadFromNIBView.h 3 | // NMView 4 | // 5 | // Created by Benjamin Broll on 24.03.11. 6 | // Copyright 2011 NEXT Munich GmbH. The App Agency. All rights reserved. 7 | // 8 | 9 | /* 10 | * The BSD License 11 | * http://www.opensource.org/licenses/bsd-license.php 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * - Redistributions of source code must retain the above copyright notice, this 17 | * list of conditions and the following disclaimer. 18 | * - Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * - Neither the name of NEXT Munich GmbH nor the names of its contributors may 22 | * be used to endorse or promote products derived from this software without 23 | * specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | * POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | #import 39 | 40 | #import "NMView.h" 41 | 42 | 43 | @interface LoadFromNIBView : NMView { 44 | 45 | UIActivityIndicatorView *activityIndicator; 46 | 47 | } 48 | 49 | @property (nonatomic, copy) NSString *text; 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /Classes/LoadFromNIBView.m: -------------------------------------------------------------------------------- 1 | // 2 | // LoadFromNIBView.m 3 | // NMView 4 | // 5 | // Created by Benjamin Broll on 24.03.11. 6 | // Copyright 2011 NEXT Munich GmbH. The App Agency. All rights reserved. 7 | // 8 | 9 | /* 10 | * The BSD License 11 | * http://www.opensource.org/licenses/bsd-license.php 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * - Redistributions of source code must retain the above copyright notice, this 17 | * list of conditions and the following disclaimer. 18 | * - Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * - Neither the name of NEXT Munich GmbH nor the names of its contributors may 22 | * be used to endorse or promote products derived from this software without 23 | * specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | * POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | #import "LoadFromNIBView.h" 39 | #import "LoadFromNIBView+IB.h" 40 | 41 | #define TEXT_TAG 1 42 | 43 | 44 | @implementation LoadFromNIBView 45 | 46 | #pragma mark Properties 47 | 48 | - (void)setText:(NSString *)text { 49 | // We can access subviews by tag using -viewWithTag:. 50 | UILabel *lbl = (UILabel *)[self viewWithTag:TEXT_TAG]; 51 | lbl.text = text; 52 | 53 | // We can also access elements of the nib using IBOutlets. 54 | if ([self.activityIndicator isAnimating]) { 55 | [self.activityIndicator stopAnimating]; 56 | } else { 57 | [self.activityIndicator startAnimating]; 58 | } 59 | } 60 | 61 | - (NSString *)text { 62 | UILabel *lbl = (UILabel *)[self viewWithTag:TEXT_TAG]; 63 | return lbl.text; 64 | } 65 | 66 | // @synthesize does not seem to work if ivar and property are not defined in the 67 | // same header. We need to implement the accessors ourselves. 68 | - (void)setActivityIndicator:(UIActivityIndicatorView *)v { 69 | if (activityIndicator != v) { 70 | [activityIndicator release]; 71 | activityIndicator = [v retain]; 72 | } 73 | } 74 | 75 | - (UIActivityIndicatorView *)activityIndicator { 76 | return activityIndicator; 77 | } 78 | 79 | 80 | #pragma mark Dealloc 81 | 82 | - (void)dealloc { 83 | [self.activityIndicator release]; 84 | 85 | [super dealloc]; 86 | } 87 | 88 | @end 89 | -------------------------------------------------------------------------------- /Classes/LoadFromNIBView.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 1056 5 | 10J869 6 | 823 7 | 1038.35 8 | 461.00 9 | 10 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 11 | 132 12 | 13 | 14 | YES 15 | 16 | 17 | 18 | YES 19 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 20 | 21 | 22 | YES 23 | 24 | YES 25 | 26 | 27 | YES 28 | 29 | 30 | 31 | YES 32 | 33 | IBFilesOwner 34 | IBCocoaTouchFramework 35 | 36 | 37 | IBFirstResponder 38 | IBCocoaTouchFramework 39 | 40 | 41 | 42 | 292 43 | 44 | YES 45 | 46 | 47 | 292 48 | {{20, 20}, {360, 21}} 49 | 50 | NO 51 | YES 52 | 7 53 | 1 54 | NO 55 | IBCocoaTouchFramework 56 | I'm a label with a very long text that does not fit within its bounds. 57 | 58 | 1 59 | MCAwIDAAA 60 | 61 | 62 | 3 63 | MQA 64 | 65 | 1 66 | NO 67 | 10 68 | 69 | 70 | 71 | -2147483380 72 | {{20, 93}, {37, 37}} 73 | 74 | NO 75 | IBCocoaTouchFramework 76 | 0 77 | 78 | 79 | {400, 150} 80 | 81 | 82 | 1 83 | MSAwIDAAA 84 | 85 | IBCocoaTouchFramework 86 | 87 | 88 | 89 | 90 | YES 91 | 92 | 93 | activityIndicator 94 | 95 | 96 | 97 | 6 98 | 99 | 100 | 101 | 102 | YES 103 | 104 | 0 105 | 106 | 107 | 108 | 109 | 110 | -1 111 | 112 | 113 | File's Owner 114 | 115 | 116 | -2 117 | 118 | 119 | 120 | 121 | 2 122 | 123 | 124 | YES 125 | 126 | 127 | 128 | 129 | 130 | 131 | 3 132 | 133 | 134 | 135 | 136 | 4 137 | 138 | 139 | 140 | 141 | 142 | 143 | YES 144 | 145 | YES 146 | -1.CustomClassName 147 | -2.CustomClassName 148 | 2.IBEditorWindowLastContentRect 149 | 2.IBPluginDependency 150 | 3.IBPluginDependency 151 | 4.IBPluginDependency 152 | 153 | 154 | YES 155 | LoadFromNIBView 156 | UIResponder 157 | {{619, 589}, {400, 150}} 158 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 159 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 160 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 161 | 162 | 163 | 164 | YES 165 | 166 | 167 | YES 168 | 169 | 170 | 171 | 172 | YES 173 | 174 | 175 | YES 176 | 177 | 178 | 179 | 6 180 | 181 | 182 | 183 | YES 184 | 185 | LoadFromNIBView 186 | 187 | activityIndicator 188 | UIActivityIndicatorView 189 | 190 | 191 | activityIndicator 192 | 193 | activityIndicator 194 | UIActivityIndicatorView 195 | 196 | 197 | 198 | IBProjectSource 199 | Classes/LoadFromNIBView+IB.h 200 | 201 | 202 | 203 | LoadFromNIBView 204 | NMView 205 | 206 | IBProjectSource 207 | Classes/LoadFromNIBView.h 208 | 209 | 210 | 211 | NMView 212 | UIView 213 | 214 | IBProjectSource 215 | Classes/NMView.h 216 | 217 | 218 | 219 | UIView 220 | 221 | IBProjectSource 222 | Classes/UIView+Templating.h 223 | 224 | 225 | 226 | 227 | YES 228 | 229 | NSObject 230 | 231 | IBFrameworkSource 232 | Foundation.framework/Headers/NSError.h 233 | 234 | 235 | 236 | NSObject 237 | 238 | IBFrameworkSource 239 | Foundation.framework/Headers/NSFileManager.h 240 | 241 | 242 | 243 | NSObject 244 | 245 | IBFrameworkSource 246 | Foundation.framework/Headers/NSKeyValueCoding.h 247 | 248 | 249 | 250 | NSObject 251 | 252 | IBFrameworkSource 253 | Foundation.framework/Headers/NSKeyValueObserving.h 254 | 255 | 256 | 257 | NSObject 258 | 259 | IBFrameworkSource 260 | Foundation.framework/Headers/NSKeyedArchiver.h 261 | 262 | 263 | 264 | NSObject 265 | 266 | IBFrameworkSource 267 | Foundation.framework/Headers/NSObject.h 268 | 269 | 270 | 271 | NSObject 272 | 273 | IBFrameworkSource 274 | Foundation.framework/Headers/NSRunLoop.h 275 | 276 | 277 | 278 | NSObject 279 | 280 | IBFrameworkSource 281 | Foundation.framework/Headers/NSThread.h 282 | 283 | 284 | 285 | NSObject 286 | 287 | IBFrameworkSource 288 | Foundation.framework/Headers/NSURL.h 289 | 290 | 291 | 292 | NSObject 293 | 294 | IBFrameworkSource 295 | Foundation.framework/Headers/NSURLConnection.h 296 | 297 | 298 | 299 | NSObject 300 | 301 | IBFrameworkSource 302 | UIKit.framework/Headers/UIAccessibility.h 303 | 304 | 305 | 306 | NSObject 307 | 308 | IBFrameworkSource 309 | UIKit.framework/Headers/UINibLoading.h 310 | 311 | 312 | 313 | NSObject 314 | 315 | IBFrameworkSource 316 | UIKit.framework/Headers/UIResponder.h 317 | 318 | 319 | 320 | UIActivityIndicatorView 321 | UIView 322 | 323 | IBFrameworkSource 324 | UIKit.framework/Headers/UIActivityIndicatorView.h 325 | 326 | 327 | 328 | UILabel 329 | UIView 330 | 331 | IBFrameworkSource 332 | UIKit.framework/Headers/UILabel.h 333 | 334 | 335 | 336 | UIResponder 337 | NSObject 338 | 339 | 340 | 341 | UIView 342 | 343 | IBFrameworkSource 344 | UIKit.framework/Headers/UIPrintFormatter.h 345 | 346 | 347 | 348 | UIView 349 | 350 | IBFrameworkSource 351 | UIKit.framework/Headers/UITextField.h 352 | 353 | 354 | 355 | UIView 356 | UIResponder 357 | 358 | IBFrameworkSource 359 | UIKit.framework/Headers/UIView.h 360 | 361 | 362 | 363 | 364 | 0 365 | IBCocoaTouchFramework 366 | 367 | com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS 368 | 369 | 370 | 371 | com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3 372 | 373 | 374 | YES 375 | ../NMViewAdvancedLayouts.xcodeproj 376 | 3 377 | 132 378 | 379 | 380 | -------------------------------------------------------------------------------- /Classes/NMViewAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // NMViewAppDelegate.h 3 | // NMView 4 | // 5 | // Created by Benjamin Broll on 27.03.11. 6 | // Copyright 2011 NEXT Munich GmbH. The App Agency. All rights reserved. 7 | // 8 | 9 | /* 10 | * The BSD License 11 | * http://www.opensource.org/licenses/bsd-license.php 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * - Redistributions of source code must retain the above copyright notice, this 17 | * list of conditions and the following disclaimer. 18 | * - Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * - Neither the name of NEXT Munich GmbH nor the names of its contributors may 22 | * be used to endorse or promote products derived from this software without 23 | * specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | * POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | #import 39 | 40 | @interface NMViewAppDelegate : NSObject { 41 | 42 | UIWindow *window; 43 | 44 | UIViewController *loadFromCodeController; 45 | UIViewController *loadFromNIBController; 46 | UIViewController *layoutSupportController; 47 | UIViewController *automaticLayoutChangesController; 48 | UIViewController *gridLayoutController; 49 | UIViewController *viewTemplatesController; 50 | 51 | } 52 | 53 | @property (nonatomic, retain) IBOutlet UIWindow *window; 54 | 55 | @property (nonatomic, retain) IBOutlet UIViewController *loadFromCodeController; 56 | @property (nonatomic, retain) IBOutlet UIViewController *loadFromNIBController; 57 | @property (nonatomic, retain) IBOutlet UIViewController *layoutSupportController; 58 | @property (nonatomic, retain) IBOutlet UIViewController *automaticLayoutChangesController; 59 | @property (nonatomic, retain) IBOutlet UIViewController *gridLayoutController; 60 | @property (nonatomic, retain) IBOutlet UIViewController *viewTemplatesController; 61 | 62 | @end 63 | 64 | -------------------------------------------------------------------------------- /Classes/NMViewAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // NMViewAppDelegate.m 3 | // NMView 4 | // 5 | // Created by Benjamin Broll on 27.03.11. 6 | // Copyright 2011 NEXT Munich GmbH. The App Agency. All rights reserved. 7 | // 8 | 9 | /* 10 | * The BSD License 11 | * http://www.opensource.org/licenses/bsd-license.php 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * - Redistributions of source code must retain the above copyright notice, this 17 | * list of conditions and the following disclaimer. 18 | * - Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * - Neither the name of NEXT Munich GmbH nor the names of its contributors may 22 | * be used to endorse or promote products derived from this software without 23 | * specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | * POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | #import "NMViewAppDelegate.h" 39 | 40 | 41 | @implementation NMViewAppDelegate 42 | 43 | #pragma mark Properties 44 | 45 | @synthesize window; 46 | @synthesize loadFromCodeController; 47 | @synthesize loadFromNIBController; 48 | @synthesize layoutSupportController; 49 | @synthesize automaticLayoutChangesController; 50 | @synthesize gridLayoutController; 51 | @synthesize viewTemplatesController; 52 | 53 | 54 | 55 | #pragma mark Application lifecycle 56 | 57 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 58 | 59 | // These defines are set in the different targets. 60 | 61 | #ifdef LOAD_FROM_CODE 62 | [window addSubview:loadFromCodeController.view]; 63 | #elif LOAD_FROM_NIB 64 | [window addSubview:loadFromNIBController.view]; 65 | #elif LAYOUT_SUPPORT 66 | [window addSubview:layoutSupportController.view]; 67 | #elif AUTOMATIC_LAYOUT_CHANGES 68 | [window addSubview:automaticLayoutChangesController.view]; 69 | #elif GRID_LAYOUT 70 | [window addSubview:gridLayoutController.view]; 71 | #elif VIEW_TEMPLATES 72 | [window addSubview:viewTemplatesController.view]; 73 | #endif 74 | 75 | [window makeKeyAndVisible]; 76 | 77 | return YES; 78 | } 79 | 80 | 81 | - (void)dealloc { 82 | [loadFromCodeController release]; 83 | [loadFromNIBController release]; 84 | [layoutSupportController release]; 85 | [automaticLayoutChangesController release]; 86 | [gridLayoutController release]; 87 | [viewTemplatesController release]; 88 | [window release]; 89 | 90 | [super dealloc]; 91 | } 92 | 93 | @end 94 | -------------------------------------------------------------------------------- /Classes/TestLayoutsView.h: -------------------------------------------------------------------------------- 1 | // 2 | // TestLayoutsView.h 3 | // NMView 4 | // 5 | // Created by Benjamin Broll on 17.02.11. 6 | // Copyright 2011 NEXT Munich GmbH. The App Agency. All rights reserved. 7 | // 8 | 9 | /* 10 | * The BSD License 11 | * http://www.opensource.org/licenses/bsd-license.php 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * - Redistributions of source code must retain the above copyright notice, this 17 | * list of conditions and the following disclaimer. 18 | * - Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * - Neither the name of NEXT Munich GmbH nor the names of its contributors may 22 | * be used to endorse or promote products derived from this software without 23 | * specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | * POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | #import 39 | 40 | #import "NMView.h" 41 | 42 | 43 | /** 44 | * This view has three different layouts defined in its nib file. 45 | * 46 | * For a layout to work correctly, the layout has to contain each of the 47 | * original layout's views in the exact same order in IB (order and hierarchy / 48 | * depth are both crucial). Once this setup is in place, you can re-position 49 | * the views (*not* change their order / depth) as you see fit. As the last 50 | * step, the type of the top level view which defines a layout needs to be 51 | * changed (in IB using the "Identity Inspector") to NMViewLayoutView to 52 | * indicate to NMView that it is indeed defining a layout. As an alternative, 53 | * you can also set the top level view's tag to a special value (see 54 | * NMViewLayout for the tag value). 55 | * 56 | * Overwrite the -layoutDidChangeToAspectRatio: method to perform some 57 | * post-processing of the views that cannot automatically happen in IB. As an 58 | * example, you can change the transform of a subview in 59 | * -layoutDidChangeToAspectRatio: to rotate it by 90°. 60 | * 61 | * Important notes: 62 | * (1) The basic view properties (like tag, auto-resizing properties and so on) 63 | * of the subviews are loaded from the initial layout only. When changing to 64 | * a different layout these properties will not change. Only the position 65 | * and size of the subviews are adjusted during a layout change. 66 | */ 67 | @interface TestLayoutsView : NMView { 68 | 69 | } 70 | 71 | @end 72 | -------------------------------------------------------------------------------- /Classes/TestLayoutsView.m: -------------------------------------------------------------------------------- 1 | // 2 | // TestLayoutsView.m 3 | // NMView 4 | // 5 | // Created by Benjamin Broll on 17.02.11. 6 | // Copyright 2011 NEXT Munich GmbH. The App Agency. All rights reserved. 7 | // 8 | 9 | /* 10 | * The BSD License 11 | * http://www.opensource.org/licenses/bsd-license.php 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * - Redistributions of source code must retain the above copyright notice, this 17 | * list of conditions and the following disclaimer. 18 | * - Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * - Neither the name of NEXT Munich GmbH nor the names of its contributors may 22 | * be used to endorse or promote products derived from this software without 23 | * specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | * POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | #import "TestLayoutsView.h" 39 | 40 | #import "NMExplicitLayout.h" 41 | #import "NMExplicitLayoutManager.h" 42 | 43 | 44 | #define TEXT_TAG 1001 45 | 46 | @implementation TestLayoutsView 47 | 48 | 49 | - (void)layoutDidChange { 50 | // Apply post processing after a new layout has been applied. 51 | if ([self.layoutManager isKindOfClass:[NMExplicitLayoutManager class]]) { 52 | NMExplicitLayoutManager *mgr = (NMExplicitLayoutManager *)self.layoutManager; 53 | 54 | UILabel *lbl = (UILabel *)[self viewWithTag:TEXT_TAG]; 55 | lbl.text = [NSString stringWithFormat:@"%f", mgr.currentLayout.aspectRatio]; 56 | } 57 | } 58 | 59 | @end 60 | -------------------------------------------------------------------------------- /Classes/ViewTemplatesController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewTemplatesController.h 3 | // NMView 4 | // 5 | // Created by Benjamin Broll on 24.03.11. 6 | // Copyright 2011 NEXT Munich GmbH. The App Agency. All rights reserved. 7 | // 8 | 9 | /* 10 | * The BSD License 11 | * http://www.opensource.org/licenses/bsd-license.php 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * - Redistributions of source code must retain the above copyright notice, this 17 | * list of conditions and the following disclaimer. 18 | * - Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * - Neither the name of NEXT Munich GmbH nor the names of its contributors may 22 | * be used to endorse or promote products derived from this software without 23 | * specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | * POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | #import 39 | 40 | @class ViewTemplatesView; 41 | 42 | 43 | /** 44 | * This sample illustrates view templating. 45 | * 46 | * Using the -applyViewTemplate: method of the UIView+NMTemplating.h UIView 47 | * category, we can copy all properties and the full subview hierarchy of the 48 | * view passed into the method as a parameter onto the view on which the method 49 | * was called. This allows for the creation of template views in a nib and the 50 | * easy creation of many views which look identical to the template without 51 | * additional nib loading. 52 | * 53 | * In this example, ViewTemplatesView provides a means to populate the view 54 | * with items consisting of a title and a text. The look and feel of an item is 55 | * defined in the ViewTemplatesView nib and is made available via an IBOutlet to 56 | * ViewTemplatesView. When adding a new item, ViewTemplatesView creates a new 57 | * UIView instance and applies the template to it. Once the template has been 58 | * applied, the new instance is configured according to the values for the new 59 | * item. 60 | */ 61 | @interface ViewTemplatesController : UIViewController { 62 | 63 | ViewTemplatesView *itemView; 64 | 65 | } 66 | 67 | @property (nonatomic, retain) IBOutlet ViewTemplatesView *itemView; 68 | 69 | - (IBAction)addItem; 70 | 71 | @end 72 | -------------------------------------------------------------------------------- /Classes/ViewTemplatesController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewTemplatesController.m 3 | // NMView 4 | // 5 | // Created by Benjamin Broll on 24.03.11. 6 | // Copyright 2011 NEXT Munich GmbH. The App Agency. All rights reserved. 7 | // 8 | 9 | /* 10 | * The BSD License 11 | * http://www.opensource.org/licenses/bsd-license.php 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * - Redistributions of source code must retain the above copyright notice, this 17 | * list of conditions and the following disclaimer. 18 | * - Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * - Neither the name of NEXT Munich GmbH nor the names of its contributors may 22 | * be used to endorse or promote products derived from this software without 23 | * specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | * POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | #import "ViewTemplatesController.h" 39 | 40 | #import "ViewTemplatesView.h" 41 | 42 | 43 | @implementation ViewTemplatesController 44 | 45 | #pragma mark Properties 46 | 47 | @synthesize itemView; 48 | 49 | 50 | #pragma mark Button Actions 51 | 52 | - (IBAction)addItem { 53 | static int counter = 1; 54 | 55 | [itemView addItemWithTitle:[NSString stringWithFormat:@"Item %d", counter] 56 | text:[NSString stringWithFormat:@"A text belonging to item %d.", counter]]; 57 | 58 | counter++; 59 | } 60 | 61 | 62 | #pragma mark Memory Lifecycle 63 | 64 | - (void)viewDidUnload { 65 | [super viewDidUnload]; 66 | 67 | self.itemView = nil; 68 | } 69 | 70 | - (void)dealloc { 71 | self.itemView = nil; 72 | 73 | [super dealloc]; 74 | } 75 | 76 | @end 77 | -------------------------------------------------------------------------------- /Classes/ViewTemplatesView+IB.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewTemplatesView+IB.h 3 | // NMView 4 | // 5 | // Created by Benjamin Broll on 24.03.11. 6 | // Copyright 2011 NEXT Munich GmbH. The App Agency. All rights reserved. 7 | // 8 | 9 | /* 10 | * The BSD License 11 | * http://www.opensource.org/licenses/bsd-license.php 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * - Redistributions of source code must retain the above copyright notice, this 17 | * list of conditions and the following disclaimer. 18 | * - Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * - Neither the name of NEXT Munich GmbH nor the names of its contributors may 22 | * be used to endorse or promote products derived from this software without 23 | * specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | * POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | #import 39 | 40 | 41 | @interface ViewTemplatesView (IB) 42 | 43 | @property (nonatomic, retain) IBOutlet UIView *itemTemplate; 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /Classes/ViewTemplatesView.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewTemplatesView.h 3 | // NMView 4 | // 5 | // Created by Benjamin Broll on 24.03.11. 6 | // Copyright 2011 NEXT Munich GmbH. The App Agency. All rights reserved. 7 | // 8 | 9 | /* 10 | * The BSD License 11 | * http://www.opensource.org/licenses/bsd-license.php 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * - Redistributions of source code must retain the above copyright notice, this 17 | * list of conditions and the following disclaimer. 18 | * - Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * - Neither the name of NEXT Munich GmbH nor the names of its contributors may 22 | * be used to endorse or promote products derived from this software without 23 | * specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | * POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | #import 39 | 40 | #import "NMView.h" 41 | 42 | 43 | @interface ViewTemplatesView : NMView { 44 | 45 | // View 46 | UIView *itemTemplate; 47 | 48 | // Model 49 | CGFloat currentX; 50 | 51 | } 52 | 53 | - (void)addItemWithTitle:(NSString *)title text:(NSString *)text; 54 | 55 | @end 56 | -------------------------------------------------------------------------------- /Classes/ViewTemplatesView.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewTemplatesView.m 3 | // NMView 4 | // 5 | // Created by Benjamin Broll on 24.03.11. 6 | // Copyright 2011 NEXT Munich GmbH. The App Agency. All rights reserved. 7 | // 8 | 9 | /* 10 | * The BSD License 11 | * http://www.opensource.org/licenses/bsd-license.php 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * - Redistributions of source code must retain the above copyright notice, this 17 | * list of conditions and the following disclaimer. 18 | * - Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * - Neither the name of NEXT Munich GmbH nor the names of its contributors may 22 | * be used to endorse or promote products derived from this software without 23 | * specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | * POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | #import "ViewTemplatesView.h" 39 | 40 | #import "UIView+NMTemplating.h" 41 | 42 | 43 | @implementation ViewTemplatesView 44 | 45 | #pragma mark Properties 46 | 47 | - (void)setItemTemplate:(UIView *)template { 48 | if (itemTemplate != template) { 49 | [itemTemplate release]; 50 | itemTemplate = [template retain]; 51 | } 52 | } 53 | 54 | - (UIView *)itemTemplate { 55 | return itemTemplate; 56 | } 57 | 58 | 59 | #pragma mark Item Management 60 | 61 | - (void)addItemWithTitle:(NSString *)title text:(NSString *)text { 62 | // Create a new item based on the template view 63 | CGRect itemFrame = CGRectMake(currentX, 20, itemTemplate.bounds.size.width, itemTemplate.bounds.size.height); 64 | UIView *item = [[[UIView alloc] initWithFrame:itemFrame] autorelease]; 65 | currentX += 20+itemFrame.size.width; 66 | 67 | // This is where the magic happens: the call copies all properties of the 68 | // template view and its subview hierarchy into "item". Since we copy (ie. 69 | // we create an entirely new hierarchy, separate from the template itself), 70 | // the template can be reused from call to call and does not have to be 71 | // re-loaded from a nib. 72 | [item applyViewTemplate:itemTemplate]; 73 | 74 | // Customize the item according to the given properties 75 | UILabel *lbl = (UILabel *)[item viewWithTag:3001]; 76 | lbl.text = title; 77 | UITextView *txt = (UITextView *)[item viewWithTag:3002]; 78 | txt.text = text; 79 | 80 | [self addSubview:item]; 81 | } 82 | 83 | 84 | #pragma mark View Lifecycle 85 | 86 | - (void)viewDidLoad { 87 | [super viewDidLoad]; 88 | 89 | currentX = 20; 90 | } 91 | 92 | @end 93 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The BSD License 2 | http://www.opensource.org/licenses/bsd-license.php 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | - Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | - Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | - Neither the name of NEXT Munich GmbH nor the names of its contributors may 13 | be used to endorse or promote products derived from this software without 14 | specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /Libraries/NMView/NMExplicitLayout.h: -------------------------------------------------------------------------------- 1 | // 2 | // NMExplicitLayout.h 3 | // NMView 4 | // 5 | // Created by Benjamin Broll on 18.02.11. 6 | // Copyright 2011 NEXT Munich GmbH. The App Agency. All rights reserved. 7 | // 8 | 9 | /* 10 | * The BSD License 11 | * http://www.opensource.org/licenses/bsd-license.php 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * - Redistributions of source code must retain the above copyright notice, this 17 | * list of conditions and the following disclaimer. 18 | * - Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * - Neither the name of NEXT Munich GmbH nor the names of its contributors may 22 | * be used to endorse or promote products derived from this software without 23 | * specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | * POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | #import 39 | 40 | 41 | #define NMViewLayoutTag 66768 42 | #define NMViewLayoutOmitSubviewsTag 66769 43 | 44 | 45 | @interface NMExplicitLayout : NSObject { 46 | 47 | CGRect alternativeBaseFrame; 48 | UIView *baseView; 49 | NSMutableDictionary *configuration; 50 | 51 | } 52 | 53 | @property (nonatomic, readonly) CGFloat aspectRatio; 54 | @property (nonatomic, readonly) CGRect alternativeBaseFrame; 55 | 56 | + (NMExplicitLayout *)layoutForView:(UIView *)original 57 | withAlternativeView:(UIView *)alternative; 58 | 59 | - (void)applyToView:(UIView *)view; 60 | 61 | @end 62 | -------------------------------------------------------------------------------- /Libraries/NMView/NMExplicitLayout.m: -------------------------------------------------------------------------------- 1 | // 2 | // NMExplicitLayout.m 3 | // NMView 4 | // 5 | // Created by Benjamin Broll on 18.02.11. 6 | // Copyright 2011 NEXT Munich GmbH. The App Agency. All rights reserved. 7 | // 8 | 9 | /* 10 | * The BSD License 11 | * http://www.opensource.org/licenses/bsd-license.php 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * - Redistributions of source code must retain the above copyright notice, this 17 | * list of conditions and the following disclaimer. 18 | * - Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * - Neither the name of NEXT Munich GmbH nor the names of its contributors may 22 | * be used to endorse or promote products derived from this software without 23 | * specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | * POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | #import "NMExplicitLayout.h" 39 | 40 | #import "NMViewLayoutOmitSubviewsView.h" 41 | #import "NMViewLayoutView.h" 42 | 43 | 44 | #pragma mark - 45 | #pragma mark NMViewLayoutConfiguration Implementation 46 | 47 | @interface NMViewLayoutConfiguration : NSObject { 48 | CGRect frame; 49 | CGFloat alpha; 50 | UIViewAutoresizing autoresizingMask; 51 | } 52 | 53 | @property (nonatomic, assign) CGRect frame; 54 | @property (nonatomic, assign) CGFloat alpha; 55 | @property (nonatomic, assign) UIViewAutoresizing autoresizingMask; 56 | 57 | + (NMViewLayoutConfiguration *)configurationWithFrame:(CGRect)f 58 | alpha:(CGFloat)a 59 | autoresizingMask:(UIViewAutoresizing)mask; 60 | 61 | @end 62 | 63 | @implementation NMViewLayoutConfiguration 64 | 65 | @synthesize frame, alpha, autoresizingMask; 66 | 67 | + (NMViewLayoutConfiguration *)configurationWithFrame:(CGRect)f 68 | alpha:(CGFloat)a 69 | autoresizingMask:(UIViewAutoresizing)mask { 70 | NMViewLayoutConfiguration *config = [[[NMViewLayoutConfiguration alloc] init] autorelease]; 71 | config.frame = f; 72 | config.alpha = a; 73 | config.autoresizingMask = mask; 74 | return config; 75 | } 76 | 77 | @end 78 | 79 | 80 | #pragma mark - 81 | #pragma mark NMViewLayout Implementation 82 | 83 | @implementation NMExplicitLayout 84 | 85 | @synthesize alternativeBaseFrame; 86 | 87 | - (CGFloat)aspectRatio { 88 | return alternativeBaseFrame.size.width/alternativeBaseFrame.size.height; 89 | } 90 | 91 | 92 | - (void)addConfiguration:(id)config forView:(UIView *)view { 93 | NSNumber *num = [NSNumber numberWithUnsignedInteger:(NSUInteger)view]; 94 | [configuration setObject:config forKey:num]; 95 | } 96 | 97 | - (id)configurationForView:(UIView *)view { 98 | return [configuration objectForKey:[NSNumber numberWithUnsignedInteger:(NSUInteger)view]]; 99 | } 100 | 101 | 102 | - (BOOL)shouldUseSubviewsForView:(UIView *)view { 103 | NSString *classname = NSStringFromClass([view class]); 104 | 105 | return (view.tag != NMViewLayoutOmitSubviewsTag 106 | && ![view isKindOfClass:[NMViewLayoutOmitSubviewsView class]] 107 | && (view == baseView 108 | || [classname isEqualToString:NSStringFromClass([NMViewLayoutView class])] 109 | || [classname isEqualToString:@"UIView"] 110 | || [classname isEqualToString:@"UIScrollView"])); 111 | } 112 | 113 | 114 | - (void)applyToView:(UIView *)view { 115 | if (view != baseView) { 116 | NMViewLayoutConfiguration *config = [self configurationForView:view]; 117 | 118 | // setting center and bounds instead of frame because the view might be 119 | // using a transform so that setting the frame is not a valid operation 120 | view.center = CGPointMake(config.frame.origin.x+config.frame.size.width/2, 121 | config.frame.origin.y+config.frame.size.height/2); 122 | view.bounds = CGRectMake(0, 0, config.frame.size.width, config.frame.size.height); 123 | 124 | //view.alpha = config.alpha; 125 | //view.autoresizingMask = config.autoresizingMask; 126 | } 127 | 128 | if ([self shouldUseSubviewsForView:view]) { 129 | for (NSInteger i = 0; i < [view.subviews count]; i++) { 130 | [self applyToView:[view.subviews objectAtIndex:i]]; 131 | } 132 | } 133 | } 134 | 135 | 136 | - (void)addLayoutForView:(UIView *)original 137 | alternativeView:(UIView *)alternative { 138 | 139 | NMViewLayoutConfiguration *config = [NMViewLayoutConfiguration configurationWithFrame:alternative.frame 140 | alpha:alternative.alpha 141 | autoresizingMask:alternative.autoresizingMask]; 142 | 143 | [self addConfiguration:config forView:original]; 144 | 145 | if ([self shouldUseSubviewsForView:alternative]) { 146 | for (NSInteger i = 0; i < [original.subviews count]; i++) { 147 | UIView *subview = [original.subviews objectAtIndex:i]; 148 | 149 | if (i < [alternative.subviews count]) { 150 | UIView *alternativeSubview = [alternative.subviews objectAtIndex:i]; 151 | 152 | [self addLayoutForView:subview alternativeView:alternativeSubview]; 153 | } 154 | } 155 | } 156 | } 157 | 158 | 159 | + (NMExplicitLayout *)layoutForView:(UIView *)original 160 | withAlternativeView:(UIView *)alternative { 161 | 162 | NMExplicitLayout *layout = [[[NMExplicitLayout alloc] init] autorelease]; 163 | layout->alternativeBaseFrame = alternative.frame; 164 | layout->baseView = original; 165 | 166 | [layout addLayoutForView:original alternativeView:alternative]; 167 | 168 | return layout; 169 | } 170 | 171 | - (id)init { 172 | if ((self = [super init])) { 173 | configuration = [[NSMutableDictionary alloc] init]; 174 | } 175 | 176 | return self; 177 | } 178 | 179 | - (void)dealloc { 180 | [configuration release]; 181 | 182 | [super dealloc]; 183 | } 184 | 185 | @end 186 | -------------------------------------------------------------------------------- /Libraries/NMView/NMExplicitLayoutManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // NMExplicitLayoutManager.h 3 | // NMView 4 | // 5 | // Created by Benjamin Broll on 29.06.11. 6 | // Copyright 2011 NEXT Munich. The App Agency. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "NMViewLayoutManager.h" 12 | 13 | @class NMExplicitLayout; 14 | 15 | 16 | /** 17 | * An NMViewLayoutManager implementation that records alternative layouts 18 | * for a view that are applied based on the layout that best matches the 19 | * current aspect-ration of the view. 20 | */ 21 | @interface NMExplicitLayoutManager : NMViewLayoutManager { 22 | 23 | NMExplicitLayout *currentLayout; // weak ref 24 | NSMutableArray *layouts; 25 | 26 | } 27 | 28 | @property (nonatomic, readonly) NMExplicitLayout *currentLayout; 29 | 30 | /** 31 | * Records the changes required to produce the given alternative layout for 32 | * the provided original view. 33 | * 34 | * Whenever the NMExplicitLayoutManager is subsequently asked to layout the 35 | * original view, the recorded alternative layout is considered and will be 36 | * applied in case its aspect-ratio best matches the aspect-ratio of the 37 | * original view at the time of the call to [NMView changeLayoutIfNecessary]. 38 | * 39 | * @param alternative A view that contains the same subview hierarchy as the 40 | * original view. The only changes recorded are the center 41 | * and bounds of the alternative view. 42 | * @param original The original view for which an alternative layout is 43 | * provided. 44 | */ 45 | - (void)addExplicitLayoutAlternative:(UIView *)alternative forView:(UIView *)original; 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /Libraries/NMView/NMExplicitLayoutManager.m: -------------------------------------------------------------------------------- 1 | // 2 | // NMExplicitLayoutManager.m 3 | // NMView 4 | // 5 | // Created by Benjamin Broll on 29.06.11. 6 | // Copyright 2011 NEXT Munich. The App Agency. All rights reserved. 7 | // 8 | 9 | #import "NMExplicitLayoutManager.h" 10 | 11 | #import "NMExplicitLayout.h" 12 | #import "NMViewLayoutView.h" 13 | 14 | 15 | @implementation NMExplicitLayoutManager 16 | 17 | #pragma mark Properties 18 | 19 | @synthesize currentLayout; 20 | 21 | 22 | #pragma mark Layouting 23 | 24 | - (BOOL)layoutSubviews:(UIView *)view { 25 | CGFloat aspectRatio = view.bounds.size.width/view.bounds.size.height; 26 | CGFloat smallestDifference = 100; 27 | NMExplicitLayout *closestLayout = nil; 28 | 29 | for (NMExplicitLayout *layout in layouts) { 30 | if (ABS(layout.aspectRatio-aspectRatio) < smallestDifference) { 31 | smallestDifference = ABS(layout.aspectRatio-aspectRatio); 32 | closestLayout = layout; 33 | } 34 | } 35 | 36 | 37 | if (closestLayout != nil) { 38 | [closestLayout applyToView:view]; 39 | currentLayout = closestLayout; 40 | return YES; 41 | } else { 42 | return NO; 43 | } 44 | } 45 | 46 | 47 | #pragma mark Public API 48 | 49 | - (void)addExplicitLayoutAlternative:(UIView *)alternative forView:(UIView *)original { 50 | if (alternative == original 51 | || alternative.tag == NMViewLayoutTag 52 | || [alternative isKindOfClass:[NMViewLayoutView class]]) { 53 | 54 | [layouts addObject:[NMExplicitLayout layoutForView:original 55 | withAlternativeView:alternative]]; 56 | } 57 | } 58 | 59 | 60 | #pragma mark Init & Dealloc 61 | 62 | - (id)init { 63 | if ((self = [super init])) { 64 | layouts = [[NSMutableArray alloc] init]; 65 | } 66 | 67 | return self; 68 | } 69 | 70 | - (void)dealloc { 71 | [layouts release]; 72 | 73 | [super dealloc]; 74 | } 75 | 76 | @end 77 | -------------------------------------------------------------------------------- /Libraries/NMView/NMGridLayoutManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // NMGridLayoutManager.h 3 | // NMView 4 | // 5 | // Created by Benjamin Broll on 29.06.11. 6 | // Copyright 2011 NEXT Munich. The App Agency. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "NMViewLayoutManager.h" 12 | 13 | typedef enum { 14 | /** Arranges subviews one row (from left to right) at a time, from top to bottom. */ 15 | NMGridLayoutDirectionLeftToRightTopToBottom, 16 | /** Arranges subviews one column (from top to bottom) at a time, from left to right. */ 17 | NMGridLayoutDirectionTopToBottomLeftToRight 18 | } NMGridLayoutDirection; 19 | 20 | typedef enum { 21 | /** 22 | * Stops layouting subviews once the first subview is encountered which does not fit 23 | * within its' superview's bounds. 24 | */ 25 | NMGridLayoutExtensionNone, 26 | /** 27 | * Layouts consecutive subviews to fill full 'pages' (multiples of the bounds with same 28 | * left/right and top/bottom margins) of subviews. Useful for layouting UIScrollViews 29 | * with pagingEnabled set to YES. 30 | */ 31 | NMGridLayoutExtensionNextFullPage, 32 | /** 33 | * Layouts consecutive subviews continuing with the same spacing as used for all 34 | * previous subviews. Useful for layouting UIScrollViews with pagingEnabled set to NO. 35 | */ 36 | NMGridLayoutExtensionLastItem 37 | } NMGridLayoutExtension; 38 | 39 | typedef enum { 40 | /** Extends at the right of the superview's bounds. */ 41 | NMGridLayoutExtensionDirectionRight, 42 | /** Extends at the bottom of the superview's bounds. */ 43 | NMGridLayoutExtensionDirectionDown 44 | } NMGridLayoutExtensionDirection; 45 | 46 | 47 | /** 48 | * An NMViewLayoutManager implementation that provides a generic grid layout 49 | * algorithm for arranging the subviews of a UIView. 50 | * 51 | * The algorithm uses the subviews' sizes 'as is' and lays them out one by one 52 | * in the specified direction. Once the algorithm encounters the first subview 53 | * that can no longer be placed within its' superviews' bounds, it uses the 54 | * specified extension mode and extensionDirection to determine how the subview 55 | * (and any subsequent subviews) will be placed outside of their superview's 56 | * bounds. 57 | */ 58 | @interface NMGridLayoutManager : NMViewLayoutManager { 59 | 60 | // Layouting Parameters 61 | NMGridLayoutDirection direction; 62 | NMGridLayoutExtension extension; 63 | NMGridLayoutExtensionDirection extensionDirection; 64 | 65 | } 66 | 67 | /** 68 | * Specifies the direction in which a view's subviews are layed out within 69 | * their superview. 70 | */ 71 | @property (nonatomic, assign) NMGridLayoutDirection direction; 72 | 73 | /** 74 | * Specifies how subviews are layed out in case they do not fit within their 75 | * superview's bounds (i.e. how they are 'extended' beyond their superview's 76 | * bounds). 77 | */ 78 | @property (nonatomic, assign) NMGridLayoutExtension extension; 79 | 80 | /** 81 | * Specifies the direction in which subviews that do not fit within their 82 | * superview's bounds are extended beyond their superview's bounds. 83 | */ 84 | @property (nonatomic, assign) NMGridLayoutExtensionDirection extensionDirection; 85 | 86 | 87 | @end 88 | -------------------------------------------------------------------------------- /Libraries/NMView/NMGridLayoutManager.m: -------------------------------------------------------------------------------- 1 | // 2 | // NMGridLayoutManager.m 3 | // NMView 4 | // 5 | // Created by Benjamin Broll on 29.06.11. 6 | // Copyright 2011 NEXT Munich. The App Agency. All rights reserved. 7 | // 8 | 9 | #import "NMGridLayoutManager.h" 10 | 11 | 12 | @interface NMGridLayoutManager (Private) 13 | 14 | - (CGSize)layoutViews:(NSArray *)views constrainedToSize:(CGSize)containerSize; 15 | - (CGSize)layoutViews:(NSArray *)views constrainedToSize:(CGSize)containerSize 16 | viewsPerRow:(NSInteger)viewsPerRow viewsPerCol:(NSInteger)viewsPerCol; 17 | - (CGSize)layoutViews:(NSArray *)views constrainedToSize:(CGSize)containerSize 18 | viewsPerRow:(NSInteger)viewsPerRow viewsPerCol:(NSInteger)viewsPerCol 19 | skipHiddenViews:(BOOL)skipHiddenViews; 20 | 21 | @end 22 | 23 | 24 | 25 | @implementation NMGridLayoutManager 26 | 27 | #pragma mark Properties 28 | 29 | @synthesize direction, extension, extensionDirection; 30 | 31 | 32 | #pragma mark Layouting 33 | 34 | - (BOOL)layoutSubviews:(UIView *)view { 35 | [self layoutViews:view.subviews constrainedToSize:view.bounds.size]; 36 | 37 | return YES; 38 | } 39 | 40 | 41 | #pragma mark Private API 42 | 43 | - (CGSize)layoutViews:(NSArray *)views constrainedToSize:(CGSize)containerSize { 44 | return [self layoutViews:views constrainedToSize:containerSize viewsPerRow:0 viewsPerCol:0]; 45 | } 46 | 47 | - (CGSize)layoutViews:(NSArray *)views constrainedToSize:(CGSize)containerSize 48 | viewsPerRow:(NSInteger)viewsPerRow viewsPerCol:(NSInteger)viewsPerCol { 49 | 50 | 51 | return [self layoutViews:views constrainedToSize:containerSize 52 | viewsPerRow:viewsPerRow viewsPerCol:viewsPerCol 53 | skipHiddenViews:YES]; 54 | } 55 | 56 | - (CGSize)layoutViews:(NSArray *)views constrainedToSize:(CGSize)containerSize 57 | viewsPerRow:(NSInteger)viewsPerRow viewsPerCol:(NSInteger)viewsPerCol 58 | skipHiddenViews:(BOOL)skipHiddenViews { 59 | 60 | if ([views count] == 0) return CGSizeZero; 61 | 62 | // calculate layouting parameters 63 | CGSize viewSize = [[views objectAtIndex:0] bounds].size; 64 | viewsPerRow = (viewsPerRow <= 0 ? (NSInteger) (containerSize.width/viewSize.width) : viewsPerRow); 65 | viewsPerCol = (viewsPerCol <= 0 ? (NSInteger) (containerSize.height/viewSize.height) : viewsPerCol); 66 | NSInteger viewsPerPage = (viewsPerRow*viewsPerCol); 67 | 68 | CGFloat horizontalGap = (containerSize.width-viewsPerRow*viewSize.width)/(viewsPerRow+1); 69 | CGFloat verticalGap = (containerSize.height-viewsPerCol*viewSize.height)/(viewsPerCol+1); 70 | 71 | // arrange views 72 | NSUInteger viewIndex = 0; 73 | for (UIView *view in views) { 74 | NSUInteger page = (viewIndex / viewsPerPage); 75 | CGSize pageOffset = CGSizeMake(page*containerSize.width, page*containerSize.height); 76 | 77 | NSUInteger row = 0; 78 | NSUInteger col = 0; 79 | 80 | // determine the row and column of the view on the current page 81 | if (direction == NMGridLayoutDirectionLeftToRightTopToBottom) { 82 | row = (viewIndex / viewsPerRow) % viewsPerCol; 83 | col = (viewIndex % viewsPerRow); 84 | } else if (direction == NMGridLayoutDirectionTopToBottomLeftToRight) { 85 | row = (viewIndex % viewsPerCol); 86 | col = (viewIndex / viewsPerCol) % viewsPerRow; 87 | } 88 | 89 | // in case we're no longer on the first page, remove the "big gap" that 90 | // is required for an extension to the next full page in case we're 91 | // using an extension to the last item only 92 | if (extension == NMGridLayoutExtensionLastItem) { 93 | pageOffset.width = MAX(0, pageOffset.width-horizontalGap); 94 | pageOffset.height = MAX(0, pageOffset.height-verticalGap); 95 | } 96 | 97 | // adjust the page offset based on the direction in which we would like 98 | // to extend 99 | if (extensionDirection == NMGridLayoutExtensionDirectionRight) { 100 | pageOffset.height = 0; 101 | } else if (extensionDirection == NMGridLayoutExtensionDirectionDown) { 102 | pageOffset.width = 0; 103 | } 104 | 105 | // position the view 106 | view.frame = CGRectMake(horizontalGap+pageOffset.width+col*(horizontalGap+viewSize.width), 107 | verticalGap+pageOffset.height+row*(verticalGap+viewSize.height), 108 | viewSize.width, viewSize.height); 109 | 110 | // increase view index if necessary 111 | if (!view.hidden || !skipHiddenViews) viewIndex++; 112 | } 113 | 114 | // calculate size 115 | if (extension == NMGridLayoutExtensionNextFullPage) { 116 | NSUInteger pageOfLastButton = (viewIndex-1)/viewsPerPage; 117 | 118 | if (extensionDirection == NMGridLayoutExtensionDirectionRight) { 119 | return CGSizeMake((pageOfLastButton+1)*containerSize.width, containerSize.height); 120 | } else { 121 | return CGSizeMake(containerSize.width, (pageOfLastButton+1)*containerSize.height); 122 | } 123 | } else if (extension == NMGridLayoutExtensionLastItem) { 124 | UIView *firstView = [views objectAtIndex:0]; 125 | UIView *lastView = [views lastObject]; 126 | 127 | return CGSizeMake(2*horizontalGap+(CGRectGetMaxX(lastView.frame)-CGRectGetMinX(firstView.frame)), 128 | 2*verticalGap+(CGRectGetMaxY(lastView.frame)-CGRectGetMinY(firstView.frame))); 129 | } else { 130 | return containerSize; 131 | } 132 | } 133 | 134 | @end 135 | -------------------------------------------------------------------------------- /Libraries/NMView/NMView.h: -------------------------------------------------------------------------------- 1 | // 2 | // NMView.h 3 | // NMView 4 | // 5 | // Created by Benjamin Broll on 17.02.11. 6 | // Copyright 2011 NEXT Munich GmbH. The App Agency. All rights reserved. 7 | // 8 | 9 | #define NMVIEW_VERSION @"1.1.3" 10 | 11 | 12 | /* 13 | * The BSD License 14 | * http://www.opensource.org/licenses/bsd-license.php 15 | * 16 | * Redistribution and use in source and binary forms, with or without 17 | * modification, are permitted provided that the following conditions are met: 18 | * 19 | * - Redistributions of source code must retain the above copyright notice, this 20 | * list of conditions and the following disclaimer. 21 | * - Redistributions in binary form must reproduce the above copyright notice, 22 | * this list of conditions and the following disclaimer in the documentation 23 | * and/or other materials provided with the distribution. 24 | * - Neither the name of NEXT Munich GmbH nor the names of its contributors may 25 | * be used to endorse or promote products derived from this software without 26 | * specific prior written permission. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 29 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 30 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 31 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 34 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 35 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 36 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 37 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | * POSSIBILITY OF SUCH DAMAGE. 39 | */ 40 | 41 | #import 42 | 43 | @class NMViewLayoutManager; 44 | 45 | 46 | /** 47 | * The NMView class allows the creation of custom UIView subclasses using nib 48 | * files to specify the layout of the view. 49 | * 50 | * Typically, when creating UIView subclasses, the view's appearance and its 51 | * subview hierarchy have to be assembled in code. This can become tedious and 52 | * is prone to error. With NMView, you design your view's layout using IB, save 53 | * the layout in a nib file and load the view with its layout during its 54 | * initialization. 55 | * 56 | * ## View layouts using nib files 57 | * 58 | * NMView provides a default implementation of the -loadViewWithNibName:bundle: 59 | * method which is used to load the view's layout from a nib file. The 60 | * implementation relies on a special structure of the nib file which is 61 | * described in detail in the documentation of -loadViewWithNibName:bundle:. 62 | * 63 | * For initialization of your view in code, you can either use the regular 64 | * -initWithFrame: method or the -initWithNibName:bundle: method. If the view is 65 | * initialized as part of a nib loading process (eg. when the view is added as 66 | * a subview to a UIViewController's view hierarchy in the view controller's nib 67 | * file), the -initWithCoder: method is used to initialize the view. 68 | * 69 | * Each of the initialization methods try to load the view's layout from a nib 70 | * file using -loadViewWithNibName:bundle:. The -initWithFrame: and 71 | * -initWithCoder: methods try to load the nib by passing nil for the nib name 72 | * and nil for the bundle, the -initWithNibName:bundle: method passes its 73 | * argument values to -loadViewWithNibName:bundle:. Passing nil / nil will try 74 | * to load a nib with the class name's name from the main bundle. 75 | * 76 | * If NMView cannot load the view from a nib (either because there is no 77 | * matching nib file or because the nib's structure does not fit the loading 78 | * process), it will call the -createView method as a last resort for creating 79 | * the view's layout programmatically. Therefore, even when creating your view's 80 | * layout in code, subclassing from NMView can make sense since -createView is 81 | * called regardless of the initializer used to create the instance. 82 | * 83 | * After the view has been loaded (either from a nib or using -createView), the 84 | * -viewDidLoad method is called. You can override the method in your custom 85 | * NMView subclass to perform some post-processing work that cannot be performed 86 | * in Interface Builder. 87 | * 88 | * One obvious thing to point out: since NMView (and its subclasses) directly 89 | * inherits from UIView, its view is loaded during initialization for the whole 90 | * lifetime of the instance. This is in contrast to a 91 | * UIViewController where the controller can exist without the associated view 92 | * (ie. -initWithNibName:bundle: on UIViewController does *not* load the view). 93 | * Therefore, for NMView, -viewDidLoad is always called exactly once during the 94 | * lifetime of an NMView instance whereas a UIViewController's -viewDidLoad 95 | * might be called multiple times. 96 | * 97 | * ## Alternative layouts 98 | * 99 | * On top of loading the view's layout from a nib file, NMView also supports 100 | * alternative layouts that can be activated based on the current bounds of the 101 | * view. This allows, for example, for the creation of different layouts of the 102 | * same NMView subclass for portrait and landscape orientations that cannot be 103 | * implemented using regular view autoresizing. 104 | * 105 | * Layouts can either be activated manually using the -changeLayoutIfNecessary 106 | * method or can be changed automatically by setting the 107 | * automaticLayoutChangeEnabled property to YES. In that case, each call to 108 | * -layoutSubviews automatically calls -changeLayoutIfNecessary. 109 | * 110 | * Once a layout has been applied, the -layoutDidChange method is 111 | * called to allow the NMView subclass to perform some post-processing on the 112 | * new layout. In this method you can, for example, apply modifications to your 113 | * layout that you cannot define in IB (like change the transform of one of the 114 | * subviews). 115 | * 116 | * For NMView to be able to load alternative layouts, the layouts have to be 117 | * specified in the same nib that the view is loaded from. Next to the regular 118 | * view layout, the nib will have to include another top-level view of the exact 119 | * same hierarchy for each alternative layout. Using Interface Builder, the 120 | * subviews in the alternative layout can now be re-arranged (as long as their 121 | * hierarchy is kept in the same shape as the regular layout). Once done, the 122 | * top-level view's type of each alternative layout has to be changed to 123 | * NMViewLayoutView so that NMView can detect which of the views should be used 124 | * for alternative layouts and which views might serve a different purpose (like 125 | * being injected into IBOutlets of your view). 126 | */ 127 | @interface NMView : UIView { 128 | 129 | @private 130 | 131 | NMViewLayoutManager *layoutManager; 132 | BOOL automaticLayoutChangeEnabled; 133 | 134 | } 135 | 136 | 137 | #pragma mark View Loading 138 | 139 | /// ---------------------- 140 | /// @name Initialization 141 | /// ---------------------- 142 | 143 | /** 144 | * Initializes a new view object by first calling -initWithFrame: of UIView with 145 | * a default CGRect and subsequently trying to load the view by calling 146 | * -loadViewWithNibName:bundle: passing nil / nil for the nib name and bundle. 147 | * 148 | * If the a nib file was loaded successfully, the view's frame will be set to 149 | * that loaded from the nib file. If no matching nib was found, the -createView 150 | * method can reset the default frame to a more suitable value. 151 | */ 152 | - (id)init; 153 | 154 | /** 155 | * Initializes a new view object by first calling -initWithFrame: of UIView and 156 | * subsequently trying to load the view by calling -loadViewWithNibName:bundle: 157 | * passing nil / nil for the nib name and bundle. 158 | * 159 | * After the view has been loaded from the nib, the view's frame is reset to the 160 | * parameter passed into the method, overriding the frame that was set in the 161 | * view's nib. 162 | * 163 | * @param frame The frame applied to the view after it has been loaded. The 164 | * returned view will always have this frame set. 165 | */ 166 | - (id)initWithFrame:(CGRect)frame; 167 | 168 | /** 169 | * Initializes a new view object from the given nib file. 170 | * 171 | * This method calls -loadViewWithNibName:bundle: to perform the actual view 172 | * loading. 173 | * 174 | * @param nibName The name of the nib file from which the view should be loaded. 175 | * Can be nil to indicate that the class' name should be used for 176 | * the nib name. The name must be passed without extension. 177 | * @param nibBundle The bundle from which the nib file should be loaded. Can be 178 | * nil to indicate that the main bundle should be used. 179 | */ 180 | - (id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle; 181 | 182 | /// -------------------- 183 | /// @name View Loading 184 | /// -------------------- 185 | 186 | /** 187 | * Loads the view's properties from the given nib file. 188 | * 189 | * If nibBundle is nil, [NSBundle mainBundle] is used for loading the nib. 190 | * If nibName is nil, we're trying to load a nib with the name of the current 191 | * class. 192 | * If the nib was loaded properly, it has to contain at least one object of 193 | * type UIView. That UIView object's properties are applied to this view to 194 | * customize its appearance and view hierarchy. The nib is searched for the 195 | * UIView "from top to bottom" (ie. the first UIView object contained in the nib 196 | * is used. 197 | * If no nib could be found, the -createView method is called as a last resort 198 | * to construct the view programatically. 199 | * 200 | * Override this method to provide your own loading strategy. 201 | * 202 | * @warning This method should not be called by users of NMView and is only 203 | * meant for subclassing. 204 | * 205 | * @param nibName The name of the nib file from which the view should be loaded. 206 | * Can be nil to indicate that the class' name should be used for 207 | * the nib name. The name must be passed without extension. 208 | * @param nibBundle The bundle from which the nib file should be loaded. Can be 209 | * nil to indicate that the main bundle should be used. 210 | */ 211 | - (void)loadViewWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle; 212 | 213 | /** 214 | * Programmatically creates the view and its hierarchy. 215 | * 216 | * Override this method to create your custom view subclass. The default 217 | * implementation does nothing. 218 | * 219 | * @warning This method should not be called by users of NMView and is only meant 220 | * for subclassing. 221 | */ 222 | - (void)createView; 223 | 224 | /** 225 | * Called after the view was loaded either from a nib or using the -createView 226 | * method. 227 | * 228 | * Override this method to perform any view customization when loading did 229 | * finish. The default implementation does nothing. 230 | * 231 | * @warning This method should not be called by users of NMView and is only meant 232 | * for subclassing. 233 | */ 234 | - (void)viewDidLoad; 235 | 236 | 237 | #pragma mark Layout Management 238 | 239 | /// ------------------------- 240 | /// @name Layout Management 241 | /// ------------------------- 242 | 243 | /** 244 | * Sets the NMViewLayoutManager that is used to change the view's layout in 245 | * response to a call to -changeLayoutIfNecessary. 246 | * 247 | * The layout manager is nil by default. If the view is loaded from a nib which 248 | * includes alternative layouts, NMExplicitLayoutManager is set as the layout 249 | * manager and will automatically be configured with the view's alternative 250 | * layouts. 251 | */ 252 | @property (nonatomic, retain) IBOutlet NMViewLayoutManager *layoutManager; 253 | 254 | /** 255 | * Enables automatic layout changes whenever -layoutSubviews is called. The 256 | * default value is NO. 257 | */ 258 | @property (nonatomic, assign) BOOL automaticLayoutChangeEnabled; 259 | 260 | /** 261 | * Called to ask the view to update its layout using the NMViewLayoutManager 262 | * assigned to layoutManager. In case the NMViewLayoutManager indicates that 263 | * the layout was changed, the -layoutDidChange method will be invoked to 264 | * allow subclasses to react to the layout change. 265 | */ 266 | - (void)changeLayoutIfNecessary; 267 | 268 | /** 269 | * Called after the layout of a view was changed during a call to 270 | * -changeLayoutIfNecessary to better match the current aspect ratio. 271 | * 272 | * Override this method to dynamically adapt to the layout change. 273 | * 274 | * @warning This method should not be called by users of NMView and is only meant 275 | * for subclassing. 276 | */ 277 | - (void)layoutDidChange; 278 | 279 | @end 280 | -------------------------------------------------------------------------------- /Libraries/NMView/NMView.m: -------------------------------------------------------------------------------- 1 | // 2 | // NMView.m 3 | // NMView 4 | // 5 | // Created by Benjamin Broll on 17.02.11. 6 | // Copyright 2011 NEXT Munich GmbH. The App Agency. All rights reserved. 7 | // 8 | 9 | /* 10 | * The BSD License 11 | * http://www.opensource.org/licenses/bsd-license.php 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * - Redistributions of source code must retain the above copyright notice, this 17 | * list of conditions and the following disclaimer. 18 | * - Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * - Neither the name of NEXT Munich GmbH nor the names of its contributors may 22 | * be used to endorse or promote products derived from this software without 23 | * specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | * POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | #import "NMView.h" 39 | 40 | #import "NMViewLayoutManager.h" 41 | #import "NMExplicitLayoutManager.h" 42 | #import "UIView+NMTemplating.h" 43 | 44 | 45 | @implementation NMView 46 | 47 | #pragma mark Properties 48 | 49 | @synthesize layoutManager; 50 | @synthesize automaticLayoutChangeEnabled; 51 | 52 | 53 | #pragma mark Methods to be overridden by subclasses 54 | 55 | - (void)loadViewWithNibName:(NSString *)nibName bundle:(NSBundle *)bundle { 56 | // 1. check for nil values and use default values, if necessary 57 | if (nibName == nil) nibName = NSStringFromClass([self class]); 58 | if (bundle == nil) bundle = [NSBundle mainBundle]; 59 | 60 | // 2. test if nib exists in bundle 61 | BOOL viewLoadedFromNib = NO; 62 | NSString *path = [bundle pathForResource:nibName ofType:@"nib"]; 63 | if (path != nil) { 64 | // 2a. try to load from nib 65 | NSArray *nibContent = [bundle loadNibNamed:nibName owner:self options:nil]; 66 | if (nibContent != nil) { 67 | BOOL layoutManagerWasLoadedFromNib = (self.layoutManager != nil); 68 | 69 | for (NSUInteger i = 0; i < [nibContent count]; i++) { 70 | NSObject *object = [nibContent objectAtIndex:i]; 71 | 72 | if ([object isKindOfClass:[UIView class]]) { 73 | UIView *view = (UIView *)object; 74 | 75 | if (!viewLoadedFromNib) { 76 | // apply nib template to current view 77 | [self applyViewTemplateByCopyingHierarchy:view]; 78 | viewLoadedFromNib = YES; 79 | } else if (!layoutManagerWasLoadedFromNib) { 80 | // automatic use of explicit layout manager since 81 | // a. multiple top-level views have been defined in the 82 | // nib 83 | // b. no layout manager was set in the nib 84 | 85 | if (self.layoutManager == nil) { 86 | // lazily initialize layout manager 87 | NMExplicitLayoutManager *mgr = [[[NMExplicitLayoutManager alloc] init] autorelease]; 88 | self.layoutManager = mgr; 89 | 90 | // treat the original view layout as one of the 91 | // explicit layouts 92 | [mgr addExplicitLayoutAlternative:self forView:self]; 93 | } 94 | 95 | NMExplicitLayoutManager *mgr = (NMExplicitLayoutManager *)self.layoutManager; 96 | [mgr addExplicitLayoutAlternative:view forView:self]; 97 | } 98 | } 99 | } 100 | } 101 | } 102 | 103 | // 3. create view using code if nib loading failed 104 | if (!viewLoadedFromNib) { 105 | [self createView]; 106 | } 107 | 108 | // 4. let subclasses know that the view did load 109 | [self viewDidLoad]; 110 | } 111 | 112 | - (void)createView { } 113 | 114 | - (void)viewDidLoad { } 115 | 116 | 117 | #pragma mark Layout Management 118 | 119 | - (void)layoutSubviews { 120 | if (self.automaticLayoutChangeEnabled) { 121 | [self changeLayoutIfNecessary]; 122 | } 123 | } 124 | 125 | - (void)changeLayoutIfNecessary { 126 | if (self.layoutManager != nil) { 127 | BOOL managerDidChangeLayout = [self.layoutManager layoutSubviews:self]; 128 | if (managerDidChangeLayout) { 129 | [self layoutDidChange]; 130 | } 131 | } 132 | } 133 | 134 | - (void)layoutDidChange { } 135 | 136 | 137 | #pragma mark Init 138 | 139 | - (id)init { 140 | return [self initWithNibName:nil bundle:nil]; 141 | } 142 | 143 | - (id)initWithNibName:(NSString*)name bundle:(NSBundle*)bundle { 144 | // use a dummy rect to initialize the UIView object 145 | if ((self = [super initWithFrame:CGRectMake(0, 0, 100, 100)])) { 146 | // load the view's layout, maintaining the rect that was set in the nib 147 | [self loadViewWithNibName:name bundle:bundle]; 148 | 149 | // re-layout (in case of a view which changes layouts automatically) 150 | [self layoutSubviews]; 151 | } 152 | return self; 153 | } 154 | 155 | - (id)initWithFrame:(CGRect)frame { 156 | if ((self = [super initWithFrame:frame])) { 157 | // load the view's layout 158 | [self loadViewWithNibName:nil bundle:nil]; 159 | 160 | // overwrite the nib-loaded frame with the given frame parameter 161 | self.frame = frame; 162 | 163 | // re-layout (in case of a view which changes layouts automatically) 164 | [self layoutSubviews]; 165 | } 166 | return self; 167 | } 168 | 169 | - (id)initWithCoder:(NSCoder *)aDecoder { 170 | if ((self = [super initWithCoder:aDecoder])) { 171 | // store the frame and tag loaded from the nib which is using this view 172 | CGRect frameBeforeLoad = self.frame; 173 | NSInteger t = self.tag; 174 | UIViewAutoresizing mask = self.autoresizingMask; 175 | 176 | // load the view's layout 177 | [self loadViewWithNibName:nil bundle:nil]; 178 | 179 | // overwrite the nib-loaded frame and tag with the frame and tag of the 180 | // nib using this view 181 | self.autoresizingMask = mask; 182 | self.frame = frameBeforeLoad; 183 | self.tag = t; 184 | 185 | // re-layout (in case of a view which changes layouts automatically) 186 | [self layoutSubviews]; 187 | } 188 | return self; 189 | } 190 | 191 | - (void)dealloc { 192 | self.layoutManager = nil; 193 | 194 | [super dealloc]; 195 | } 196 | 197 | @end 198 | -------------------------------------------------------------------------------- /Libraries/NMView/NMViewLayoutManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // NMViewLayoutManager.h 3 | // NMView 4 | // 5 | // Created by Benjamin Broll on 29.06.11. 6 | // Copyright 2011 NEXT Munich. The App Agency. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | /** 13 | * The NMViewLayoutManager defines the contract for a class that wants 14 | * to change the layout of a UIView. 15 | * 16 | * It can be subclassed and used as the [NMView layoutManager] to e.g. 17 | * provide a grid-based layout for the subclasses of your view. 18 | */ 19 | @interface NMViewLayoutManager : NSObject { 20 | 21 | } 22 | 23 | /** 24 | * Called by NMView to ask the NMViewLayoutManager to check the current 25 | * layout of the passed in view and, if necessary, update its' layout. 26 | * 27 | * @param view The view to layout. 28 | * @return Whether the layout manager changed the layout of the view. 29 | */ 30 | - (BOOL)layoutSubviews:(UIView *)view; 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /Libraries/NMView/NMViewLayoutManager.m: -------------------------------------------------------------------------------- 1 | // 2 | // NMViewLayoutManager.m 3 | // NMView 4 | // 5 | // Created by Benjamin Broll on 29.06.11. 6 | // Copyright 2011 NEXT Munich. The App Agency. All rights reserved. 7 | // 8 | 9 | #import "NMViewLayoutManager.h" 10 | 11 | 12 | @implementation NMViewLayoutManager 13 | 14 | - (BOOL)layoutSubviews:(UIView *)view { 15 | return NO; 16 | } 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /Libraries/NMView/NMViewLayoutOmitSubviewsView.h: -------------------------------------------------------------------------------- 1 | // 2 | // NMViewLayoutOmitSubviewsView.h 3 | // NMView 4 | // 5 | // Created by Benjamin Broll on 21.02.11. 6 | // Copyright 2011 NEXT Munich GmbH. The App Agency. All rights reserved. 7 | // 8 | 9 | /* 10 | * The BSD License 11 | * http://www.opensource.org/licenses/bsd-license.php 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * - Redistributions of source code must retain the above copyright notice, this 17 | * list of conditions and the following disclaimer. 18 | * - Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * - Neither the name of NEXT Munich GmbH nor the names of its contributors may 22 | * be used to endorse or promote products derived from this software without 23 | * specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | * POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | #import 39 | 40 | 41 | /** 42 | * A class which serves as a marker in Interface Builder to identify the 43 | * views for which NMExplicitLayoutManager should not re-layout their subviews. 44 | */ 45 | @interface NMViewLayoutOmitSubviewsView : UIView { 46 | 47 | } 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /Libraries/NMView/NMViewLayoutOmitSubviewsView.m: -------------------------------------------------------------------------------- 1 | // 2 | // NMViewLayoutOmitSubviewsView.m 3 | // NMView 4 | // 5 | // Created by Benjamin Broll on 21.02.11. 6 | // Copyright 2011 NEXT Munich GmbH. The App Agency. All rights reserved. 7 | // 8 | 9 | /* 10 | * The BSD License 11 | * http://www.opensource.org/licenses/bsd-license.php 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * - Redistributions of source code must retain the above copyright notice, this 17 | * list of conditions and the following disclaimer. 18 | * - Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * - Neither the name of NEXT Munich GmbH nor the names of its contributors may 22 | * be used to endorse or promote products derived from this software without 23 | * specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | * POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | #import "NMViewLayoutOmitSubviewsView.h" 39 | 40 | 41 | @implementation NMViewLayoutOmitSubviewsView 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /Libraries/NMView/NMViewLayoutView.h: -------------------------------------------------------------------------------- 1 | // 2 | // NMViewLayoutView.h 3 | // NMView 4 | // 5 | // Created by Benjamin Broll on 21.02.11. 6 | // Copyright 2011 NEXT Munich GmbH. The App Agency. All rights reserved. 7 | // 8 | 9 | /* 10 | * The BSD License 11 | * http://www.opensource.org/licenses/bsd-license.php 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * - Redistributions of source code must retain the above copyright notice, this 17 | * list of conditions and the following disclaimer. 18 | * - Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * - Neither the name of NEXT Munich GmbH nor the names of its contributors may 22 | * be used to endorse or promote products derived from this software without 23 | * specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | * POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | #import 39 | 40 | 41 | /** 42 | * A class which serves as a marker in Interface Builder to identify the 43 | * views which should be used as alternative layouts for an NMView. 44 | */ 45 | @interface NMViewLayoutView : UIView { 46 | 47 | } 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /Libraries/NMView/NMViewLayoutView.m: -------------------------------------------------------------------------------- 1 | // 2 | // NMViewLayoutView.m 3 | // NMView 4 | // 5 | // Created by Benjamin Broll on 21.02.11. 6 | // Copyright 2011 NEXT Munich GmbH. The App Agency. All rights reserved. 7 | // 8 | 9 | /* 10 | * The BSD License 11 | * http://www.opensource.org/licenses/bsd-license.php 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * - Redistributions of source code must retain the above copyright notice, this 17 | * list of conditions and the following disclaimer. 18 | * - Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * - Neither the name of NEXT Munich GmbH nor the names of its contributors may 22 | * be used to endorse or promote products derived from this software without 23 | * specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | * POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | #import "NMViewLayoutView.h" 39 | 40 | 41 | @implementation NMViewLayoutView 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /Libraries/NMView/UIImage+NMNSCoding.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+NMNSCoding.h 3 | // NMView 4 | // 5 | // Created by Benjamin Broll on 17.02.11. 6 | // Copyright 2011 NEXT Munich GmbH. The App Agency. All rights reserved. 7 | // 8 | 9 | /* 10 | * The BSD License 11 | * http://www.opensource.org/licenses/bsd-license.php 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * - Redistributions of source code must retain the above copyright notice, this 17 | * list of conditions and the following disclaimer. 18 | * - Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * - Neither the name of NEXT Munich GmbH nor the names of its contributors may 22 | * be used to endorse or promote products derived from this software without 23 | * specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | * POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | #import 39 | 40 | 41 | @interface UIImage (NMNSCoding) 42 | 43 | - (id)initWithCoder:(NSCoder *)decoder; 44 | - (void)encodeWithCoder:(NSCoder *)encoder; 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /Libraries/NMView/UIImage+NMNSCoding.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+NMNSCoding.m 3 | // NMView 4 | // 5 | // Created by Benjamin Broll on 17.02.11. 6 | // Copyright 2011 NEXT Munich GmbH. The App Agency. All rights reserved. 7 | // 8 | 9 | /* 10 | * The BSD License 11 | * http://www.opensource.org/licenses/bsd-license.php 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * - Redistributions of source code must retain the above copyright notice, this 17 | * list of conditions and the following disclaimer. 18 | * - Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * - Neither the name of NEXT Munich GmbH nor the names of its contributors may 22 | * be used to endorse or promote products derived from this software without 23 | * specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | * POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | #import "UIImage+NMNSCoding.h" 39 | 40 | #define kEncodingKey @"imageData" 41 | 42 | 43 | @implementation UIImage (NMNSCoding) 44 | 45 | // These pragmas are used to disable the warnings indicating that we're overriding the 46 | // -initWithCoder: / -encodeWithCoder: methods using a category. 47 | #pragma clang diagnostic push 48 | #pragma clang diagnostic ignored "-Wobjc-protocol-method-implementation" 49 | 50 | - (id)initWithCoder:(NSCoder *)decoder 51 | { 52 | if ((self = [super init])) 53 | { 54 | NSData *data = [decoder decodeObjectForKey:kEncodingKey]; 55 | self = [self initWithData:data]; 56 | } 57 | 58 | return self; 59 | } 60 | - (void)encodeWithCoder:(NSCoder *)encoder 61 | { 62 | NSData *data = UIImagePNGRepresentation(self); 63 | [encoder encodeObject:data forKey:kEncodingKey]; 64 | } 65 | 66 | #pragma clang diagnostic pop 67 | 68 | @end 69 | -------------------------------------------------------------------------------- /Libraries/NMView/UIView+NMTemplating.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+NMTemplating.h 3 | // NMView 4 | // 5 | // Created by Benjamin Broll on 17.02.11. 6 | // Copyright 2011 NEXT Munich GmbH. The App Agency. All rights reserved. 7 | // 8 | 9 | /* 10 | * The BSD License 11 | * http://www.opensource.org/licenses/bsd-license.php 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * - Redistributions of source code must retain the above copyright notice, this 17 | * list of conditions and the following disclaimer. 18 | * - Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * - Neither the name of NEXT Munich GmbH nor the names of its contributors may 22 | * be used to endorse or promote products derived from this software without 23 | * specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | * POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | #import 39 | #import 40 | 41 | 42 | @interface UIView (NMTemplating) 43 | 44 | - (void)applyViewTemplate:(UIView *)view; 45 | 46 | - (void)applyViewTemplateByCopyingHierarchy:(UIView *)view; 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /Libraries/NMView/UIView+NMTemplating.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+NMTemplating.m 3 | // NMView 4 | // 5 | // Created by Benjamin Broll on 17.02.11. 6 | // Copyright 2011 NEXT Munich GmbH. The App Agency. All rights reserved. 7 | // 8 | 9 | /* 10 | * The BSD License 11 | * http://www.opensource.org/licenses/bsd-license.php 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * - Redistributions of source code must retain the above copyright notice, this 17 | * list of conditions and the following disclaimer. 18 | * - Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * - Neither the name of NEXT Munich GmbH nor the names of its contributors may 22 | * be used to endorse or promote products derived from this software without 23 | * specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | * POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | #import "UIView+NMTemplating.h" 39 | 40 | 41 | @implementation UIView (NMTemplating) 42 | 43 | 44 | - (void)applyViewProperties:(UIView *)view { 45 | // Visual Appearance 46 | self.backgroundColor = view.backgroundColor; 47 | self.hidden = view.hidden; 48 | self.alpha = view.alpha; 49 | self.opaque = view.opaque; 50 | self.clipsToBounds = view.clipsToBounds; 51 | self.clearsContextBeforeDrawing = view.clearsContextBeforeDrawing; 52 | 53 | // Event-Related 54 | self.userInteractionEnabled = view.userInteractionEnabled; 55 | self.multipleTouchEnabled = view.multipleTouchEnabled; 56 | self.exclusiveTouch = view.exclusiveTouch; 57 | 58 | // Resizing Behaviour 59 | self.autoresizingMask = view.autoresizingMask; 60 | self.autoresizesSubviews = view.autoresizesSubviews; 61 | self.contentMode = view.contentMode; 62 | self.contentStretch = view.contentStretch; 63 | 64 | // Drawing / Updating 65 | if ([self respondsToSelector:@selector(contentScaleFactor)]) { 66 | self.contentScaleFactor = view.contentScaleFactor; 67 | } 68 | 69 | // Identifying 70 | self.tag = view.tag; 71 | 72 | // Bounds 73 | self.bounds = view.bounds; 74 | } 75 | 76 | 77 | - (UIView *)createCopyOfView { 78 | if ([self respondsToSelector:@selector(encodeWithCoder:)]) { 79 | NSMutableData *data = [[NSMutableData alloc] init]; 80 | 81 | NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data]; 82 | [archiver encodeObject:self forKey:@"view"]; 83 | [archiver finishEncoding]; 84 | [archiver release]; 85 | 86 | NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data]; 87 | UIView *copy = [unarchiver decodeObjectForKey:@"view"]; 88 | [unarchiver finishDecoding]; 89 | [unarchiver release]; 90 | 91 | [data release]; 92 | 93 | return copy; 94 | } else { 95 | return nil; 96 | } 97 | } 98 | 99 | 100 | - (void)applyViewTemplate:(UIView *)view { 101 | // Apply Properties 102 | [self applyViewProperties:view]; 103 | 104 | // Re-Create subview structure 105 | for (UIView *subview in view.subviews) { 106 | UIView *copy = [subview createCopyOfView]; 107 | [self addSubview:copy]; 108 | } 109 | } 110 | 111 | - (void)applyViewTemplateByCopyingHierarchy:(UIView *)view { 112 | // Apply Properties 113 | [self applyViewProperties:view]; 114 | 115 | // Detach / Attach subviews 116 | for (UIView *subview in view.subviews) { 117 | [subview retain]; 118 | [subview removeFromSuperview]; 119 | 120 | [self addSubview:subview]; 121 | 122 | [subview release]; 123 | } 124 | } 125 | 126 | @end 127 | -------------------------------------------------------------------------------- /NMView_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'NMView' target in the 'NMView' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #import 8 | #endif 9 | -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | # iOS 11 Bug 2 | 3 | This library causes a problem with UIActivityViewController on iOS 11. When trying to share a PDF 4 | document with UIActivityViewController on iPad on iOS 11, the share sheet is not displayed. 5 | 6 | The issue is caused by the UIImage+NMNSCoding category used by the library. 7 | 8 | # Deprecation Warning 9 | 10 | This library has not been maintained for quite a long time so I suppose nobody is using it anymore. 11 | However, since we have recently discovered an subtle issue on iOS 11 which is caused by this library, 12 | I wanted to officially highlight that the project should no longer be used. -------------------------------------------------------------------------------- /Resources/Icon-72.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nextmunich/NMView/fccbfb3b56a80c2050c79d097152d3217d498e7b/Resources/Icon-72.png -------------------------------------------------------------------------------- /Resources/NMView-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en_US 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIconFile 12 | 13 | CFBundleIdentifier 14 | com.yourcompany.${PRODUCT_NAME:rfc1034identifier} 15 | CFBundleInfoDictionaryVersion 16 | 6.0 17 | CFBundleName 18 | ${PRODUCT_NAME} 19 | CFBundlePackageType 20 | APPL 21 | CFBundleShortVersionString 22 | 1.0 23 | CFBundleSignature 24 | ???? 25 | CFBundleVersion 26 | ${CURRENT_PROJECT_VERSION} 27 | LSRequiresIPhoneOS 28 | 29 | NSMainNibFile 30 | MainWindow 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationPortraitUpsideDown 35 | UIInterfaceOrientationLandscapeLeft 36 | UIInterfaceOrientationLandscapeRight 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // NMView 4 | // 5 | // Created by Benjamin Broll on 27.03.11. 6 | // Copyright 2011 NEXT Munich GmbH. The App Agency. All rights reserved. 7 | // 8 | 9 | /* 10 | * The BSD License 11 | * http://www.opensource.org/licenses/bsd-license.php 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * - Redistributions of source code must retain the above copyright notice, this 17 | * list of conditions and the following disclaimer. 18 | * - Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * - Neither the name of NEXT Munich GmbH nor the names of its contributors may 22 | * be used to endorse or promote products derived from this software without 23 | * specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | * POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | #import 39 | 40 | int main(int argc, char *argv[]) { 41 | 42 | NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 43 | int retVal = UIApplicationMain(argc, argv, nil, nil); 44 | [pool release]; 45 | return retVal; 46 | } 47 | --------------------------------------------------------------------------------