diff --git a/.gitignore b/.gitignore index 89c499e..04529e0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,12 @@ # Xcode -.DS_Store +# +# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore + +## Build generated build/ +DerivedData + +## Various settings *.pbxuser !default.pbxuser *.mode1v3 @@ -9,10 +15,29 @@ build/ !default.mode2v3 *.perspectivev3 !default.perspectivev3 -*.xcworkspace -!default.xcworkspace xcuserdata -profile + +## Other +*.xccheckout *.moved-aside -DerivedData -.idea/ +*.xcuserstate +*.xcscmblueprint + +## Obj-C/Swift specific +*.hmap +*.ipa + +# CocoaPods +# +# We recommend against adding the Pods directory to your .gitignore. However +# you should judge for yourself, the pros and cons are mentioned at: +# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control +# +#Pods/ + +# Carthage +# +# Add this line if you want to avoid checking in source code from Carthage dependencies. +# Carthage/Checkouts + +Carthage/Build \ No newline at end of file diff --git a/Podfile b/Podfile new file mode 100644 index 0000000..1bf41f0 --- /dev/null +++ b/Podfile @@ -0,0 +1,3 @@ +use_frameworks! + +pod 'PureLayout' diff --git a/Podfile.lock b/Podfile.lock new file mode 100644 index 0000000..c5a36c7 --- /dev/null +++ b/Podfile.lock @@ -0,0 +1,10 @@ +PODS: + - PureLayout (3.0.0) + +DEPENDENCIES: + - PureLayout + +SPEC CHECKSUMS: + PureLayout: 270dfee2236f697ab1d5e2771c2e5c248495fa0d + +COCOAPODS: 0.38.2 diff --git a/Pods/Headers/Private/PureLayout/ALView+PureLayout.h b/Pods/Headers/Private/PureLayout/ALView+PureLayout.h new file mode 120000 index 0000000..ac489e2 --- /dev/null +++ b/Pods/Headers/Private/PureLayout/ALView+PureLayout.h @@ -0,0 +1 @@ +../../../PureLayout/PureLayout/PureLayout/ALView+PureLayout.h \ No newline at end of file diff --git a/Pods/Headers/Private/PureLayout/NSArray+PureLayout.h b/Pods/Headers/Private/PureLayout/NSArray+PureLayout.h new file mode 120000 index 0000000..76395e6 --- /dev/null +++ b/Pods/Headers/Private/PureLayout/NSArray+PureLayout.h @@ -0,0 +1 @@ +../../../PureLayout/PureLayout/PureLayout/NSArray+PureLayout.h \ No newline at end of file diff --git a/Pods/Headers/Private/PureLayout/NSLayoutConstraint+PureLayout.h b/Pods/Headers/Private/PureLayout/NSLayoutConstraint+PureLayout.h new file mode 120000 index 0000000..a2afdda --- /dev/null +++ b/Pods/Headers/Private/PureLayout/NSLayoutConstraint+PureLayout.h @@ -0,0 +1 @@ +../../../PureLayout/PureLayout/PureLayout/NSLayoutConstraint+PureLayout.h \ No newline at end of file diff --git a/Pods/Headers/Private/PureLayout/PureLayout+Internal.h b/Pods/Headers/Private/PureLayout/PureLayout+Internal.h new file mode 120000 index 0000000..972a4ee --- /dev/null +++ b/Pods/Headers/Private/PureLayout/PureLayout+Internal.h @@ -0,0 +1 @@ +../../../PureLayout/PureLayout/PureLayout/PureLayout+Internal.h \ No newline at end of file diff --git a/Pods/Headers/Private/PureLayout/PureLayout.h b/Pods/Headers/Private/PureLayout/PureLayout.h new file mode 120000 index 0000000..616d281 --- /dev/null +++ b/Pods/Headers/Private/PureLayout/PureLayout.h @@ -0,0 +1 @@ +../../../PureLayout/PureLayout/PureLayout/PureLayout.h \ No newline at end of file diff --git a/Pods/Headers/Private/PureLayout/PureLayoutDefines.h b/Pods/Headers/Private/PureLayout/PureLayoutDefines.h new file mode 120000 index 0000000..4a67193 --- /dev/null +++ b/Pods/Headers/Private/PureLayout/PureLayoutDefines.h @@ -0,0 +1 @@ +../../../PureLayout/PureLayout/PureLayout/PureLayoutDefines.h \ No newline at end of file diff --git a/Pods/Manifest.lock b/Pods/Manifest.lock new file mode 100644 index 0000000..c5a36c7 --- /dev/null +++ b/Pods/Manifest.lock @@ -0,0 +1,10 @@ +PODS: + - PureLayout (3.0.0) + +DEPENDENCIES: + - PureLayout + +SPEC CHECKSUMS: + PureLayout: 270dfee2236f697ab1d5e2771c2e5c248495fa0d + +COCOAPODS: 0.38.2 diff --git a/Pods/Pods.xcodeproj/project.pbxproj b/Pods/Pods.xcodeproj/project.pbxproj new file mode 100644 index 0000000..4b44319 --- /dev/null +++ b/Pods/Pods.xcodeproj/project.pbxproj @@ -0,0 +1,532 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 2241ABC30538E46F17BC59AFC645B6C5 /* NSArray+PureLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 191E1C6095DA6537B3B9AD63F2DABA12 /* NSArray+PureLayout.m */; }; + 38792B4D4276C59B21ACF9B4DE6ED4F5 /* PureLayout+Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = DAFA4BCE4B185A782DD016F84B3BE0CF /* PureLayout+Internal.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 40C283F04408D7C74CB6D9966B4CE10E /* ALView+PureLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 6FDCF9208FAF09CC79F2DA4FA5683C82 /* ALView+PureLayout.m */; }; + 5EFAEC887045E3038CBA406FC9C48C82 /* Pods-umbrella.h in Headers */ = {isa = PBXBuildFile; fileRef = D3B8F899423E15C997E14FB2404791C6 /* Pods-umbrella.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 6354BF1C514445C33F9B65DD18205535 /* NSArray+PureLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = 913E7306AD4E255661D418473382CF54 /* NSArray+PureLayout.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 6837A6326B4A297F0F37B60F67C0706B /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9011C520EFA96D78421817354D237D35 /* Foundation.framework */; }; + 7C6672FF5BC14E5A632F38FBCF4D84F6 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9011C520EFA96D78421817354D237D35 /* Foundation.framework */; }; + 8A42E3EC15CA6EFC7A14FF66419B4E0A /* NSLayoutConstraint+PureLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 97F5A0160929E8154C67BBC4B5A91B5C /* NSLayoutConstraint+PureLayout.m */; }; + 8FB29797E35802BE65A888432368F471 /* PureLayout-umbrella.h in Headers */ = {isa = PBXBuildFile; fileRef = 17DA7E900B1E7945C8B8CE59D225F706 /* PureLayout-umbrella.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 98DE61629DE81688A6D460FF03DD172A /* PureLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = 6E05779740DB7A4882324BB0CC77FE83 /* PureLayout.h */; settings = {ATTRIBUTES = (Public, ); }; }; + A9DC2F99B25B83F8896D0DEF1D5709D0 /* Pods-dummy.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B29C2EEF0D874EC57444010B89A6DD3 /* Pods-dummy.m */; }; + BEEF2FF4434A311B51CCAEA2D0BC4167 /* PureLayout-dummy.m in Sources */ = {isa = PBXBuildFile; fileRef = 7ADC5572B76BA1CB325993B5EB36DD36 /* PureLayout-dummy.m */; }; + C07804D5CAE775845193B0BDEAE8153A /* ALView+PureLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = 13DC162AF7BEBCA584CAF9D9CEAD8319 /* ALView+PureLayout.h */; settings = {ATTRIBUTES = (Public, ); }; }; + E822E9813D45FF34F11862731B65F4D7 /* NSLayoutConstraint+PureLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = 9CD3AB8195F74BFC43D6997F61F6F298 /* NSLayoutConstraint+PureLayout.h */; settings = {ATTRIBUTES = (Public, ); }; }; + F9A3864238BEAF7F67E75EF7417D7AF4 /* PureLayoutDefines.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FBC3E333821E19620FAC1463F61C533 /* PureLayoutDefines.h */; settings = {ATTRIBUTES = (Public, ); }; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + D4BE9AC9A09AF52392290EC0CA80E1A2 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = D41D8CD98F00B204E9800998ECF8427E /* Project object */; + proxyType = 1; + remoteGlobalIDString = 8240A687A12B3496C485DFBEB80E79E2; + remoteInfo = PureLayout; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXFileReference section */ + 0FBC3E333821E19620FAC1463F61C533 /* PureLayoutDefines.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = PureLayoutDefines.h; path = PureLayout/PureLayout/PureLayoutDefines.h; sourceTree = ""; }; + 13DC162AF7BEBCA584CAF9D9CEAD8319 /* ALView+PureLayout.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = "ALView+PureLayout.h"; path = "PureLayout/PureLayout/ALView+PureLayout.h"; sourceTree = ""; }; + 17DA7E900B1E7945C8B8CE59D225F706 /* PureLayout-umbrella.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = "PureLayout-umbrella.h"; sourceTree = ""; }; + 191E1C6095DA6537B3B9AD63F2DABA12 /* NSArray+PureLayout.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = "NSArray+PureLayout.m"; path = "PureLayout/PureLayout/NSArray+PureLayout.m"; sourceTree = ""; }; + 25EB15ADDC91D3318D94A842E4FC598D /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = Pods.debug.xcconfig; sourceTree = ""; }; + 2B98C72313E9B08E15E4970F6A8BB5B6 /* PureLayout.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = PureLayout.xcconfig; sourceTree = ""; }; + 34BE0BA12096455AB6760CFDF1005D58 /* PureLayout.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = PureLayout.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 37B11DEC4162936E069BC7FEF119B09C /* PureLayout.modulemap */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = "sourcecode.module-map"; path = PureLayout.modulemap; sourceTree = ""; }; + 4B29C2EEF0D874EC57444010B89A6DD3 /* Pods-dummy.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = "Pods-dummy.m"; sourceTree = ""; }; + 59D9DEAEBEB4B4AE79B77C4D1EEF3DAE /* Info.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 6E05779740DB7A4882324BB0CC77FE83 /* PureLayout.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = PureLayout.h; path = PureLayout/PureLayout/PureLayout.h; sourceTree = ""; }; + 6FDCF9208FAF09CC79F2DA4FA5683C82 /* ALView+PureLayout.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = "ALView+PureLayout.m"; path = "PureLayout/PureLayout/ALView+PureLayout.m"; sourceTree = ""; }; + 79A9DEDC89FE8336BF5FEDAAF75BF7FC /* Pods.modulemap */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = "sourcecode.module-map"; path = Pods.modulemap; sourceTree = ""; }; + 7ADC5572B76BA1CB325993B5EB36DD36 /* PureLayout-dummy.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = "PureLayout-dummy.m"; sourceTree = ""; }; + 87B213035BAC5F75386F62D3C75D2342 /* Pods-acknowledgements.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; path = "Pods-acknowledgements.plist"; sourceTree = ""; }; + 9011C520EFA96D78421817354D237D35 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.3.sdk/System/Library/Frameworks/Foundation.framework; sourceTree = DEVELOPER_DIR; }; + 913E7306AD4E255661D418473382CF54 /* NSArray+PureLayout.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = "NSArray+PureLayout.h"; path = "PureLayout/PureLayout/NSArray+PureLayout.h"; sourceTree = ""; }; + 97F5A0160929E8154C67BBC4B5A91B5C /* NSLayoutConstraint+PureLayout.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = "NSLayoutConstraint+PureLayout.m"; path = "PureLayout/PureLayout/NSLayoutConstraint+PureLayout.m"; sourceTree = ""; }; + 9CD3AB8195F74BFC43D6997F61F6F298 /* NSLayoutConstraint+PureLayout.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = "NSLayoutConstraint+PureLayout.h"; path = "PureLayout/PureLayout/NSLayoutConstraint+PureLayout.h"; sourceTree = ""; }; + B870EF585C629C2B8EFC01EFA066E0AC /* Pods.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + BA6428E9F66FD5A23C0A2E06ED26CD2F /* Podfile */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = Podfile; path = ../Podfile; sourceTree = SOURCE_ROOT; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; + CBC0F7C552B739C909B650A0F42F7F38 /* Pods-resources.sh */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.script.sh; path = "Pods-resources.sh"; sourceTree = ""; }; + CC4882E403503DE9288AF3969E260251 /* PureLayout-Private.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = "PureLayout-Private.xcconfig"; sourceTree = ""; }; + D0405803033A2A777B8E4DFA0C1800ED /* Pods-acknowledgements.markdown */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; path = "Pods-acknowledgements.markdown"; sourceTree = ""; }; + D3B8F899423E15C997E14FB2404791C6 /* Pods-umbrella.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = "Pods-umbrella.h"; sourceTree = ""; }; + D77F20524604100E192667662A8784A5 /* Pods.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = Pods.release.xcconfig; sourceTree = ""; }; + DAFA4BCE4B185A782DD016F84B3BE0CF /* PureLayout+Internal.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = "PureLayout+Internal.h"; path = "PureLayout/PureLayout/PureLayout+Internal.h"; sourceTree = ""; }; + E608DBDD091C6DAAF7133EFDA8960D3A /* PureLayout-prefix.pch */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = "PureLayout-prefix.pch"; sourceTree = ""; }; + E7F21354943D9F42A70697D5A5EF72E9 /* Pods-frameworks.sh */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.script.sh; path = "Pods-frameworks.sh"; sourceTree = ""; }; + E8446514FBAD26C0E18F24A5715AEF67 /* Info.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 52E761D0B069DCD4C6E2F74FA447C130 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 6837A6326B4A297F0F37B60F67C0706B /* Foundation.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 8D982826564F33040944F955F4866DBD /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 7C6672FF5BC14E5A632F38FBCF4D84F6 /* Foundation.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 53F661C0CA7190D2CF05023FB33D61E4 /* iOS */ = { + isa = PBXGroup; + children = ( + 9011C520EFA96D78421817354D237D35 /* Foundation.framework */, + ); + name = iOS; + sourceTree = ""; + }; + 56E5F5118E3951F2C822D54DF77B17DB /* Support Files */ = { + isa = PBXGroup; + children = ( + 59D9DEAEBEB4B4AE79B77C4D1EEF3DAE /* Info.plist */, + 37B11DEC4162936E069BC7FEF119B09C /* PureLayout.modulemap */, + 2B98C72313E9B08E15E4970F6A8BB5B6 /* PureLayout.xcconfig */, + CC4882E403503DE9288AF3969E260251 /* PureLayout-Private.xcconfig */, + 7ADC5572B76BA1CB325993B5EB36DD36 /* PureLayout-dummy.m */, + E608DBDD091C6DAAF7133EFDA8960D3A /* PureLayout-prefix.pch */, + 17DA7E900B1E7945C8B8CE59D225F706 /* PureLayout-umbrella.h */, + ); + name = "Support Files"; + path = "../Target Support Files/PureLayout"; + sourceTree = ""; + }; + 75D98FF52E597A11900E131B6C4E1ADA /* Pods */ = { + isa = PBXGroup; + children = ( + E8446514FBAD26C0E18F24A5715AEF67 /* Info.plist */, + 79A9DEDC89FE8336BF5FEDAAF75BF7FC /* Pods.modulemap */, + D0405803033A2A777B8E4DFA0C1800ED /* Pods-acknowledgements.markdown */, + 87B213035BAC5F75386F62D3C75D2342 /* Pods-acknowledgements.plist */, + 4B29C2EEF0D874EC57444010B89A6DD3 /* Pods-dummy.m */, + E7F21354943D9F42A70697D5A5EF72E9 /* Pods-frameworks.sh */, + CBC0F7C552B739C909B650A0F42F7F38 /* Pods-resources.sh */, + D3B8F899423E15C997E14FB2404791C6 /* Pods-umbrella.h */, + 25EB15ADDC91D3318D94A842E4FC598D /* Pods.debug.xcconfig */, + D77F20524604100E192667662A8784A5 /* Pods.release.xcconfig */, + ); + name = Pods; + path = "Target Support Files/Pods"; + sourceTree = ""; + }; + 7DB346D0F39D3F0E887471402A8071AB = { + isa = PBXGroup; + children = ( + BA6428E9F66FD5A23C0A2E06ED26CD2F /* Podfile */, + BC3CA7F9E30CC8F7E2DD044DD34432FC /* Frameworks */, + A2FDD832DA64F35B104DD4C55A31BF8E /* Pods */, + CCA510CFBEA2D207524CDA0D73C3B561 /* Products */, + B7B80995527643776607AFFA75B91E24 /* Targets Support Files */, + ); + sourceTree = ""; + }; + A2FDD832DA64F35B104DD4C55A31BF8E /* Pods */ = { + isa = PBXGroup; + children = ( + FB712A69E0D41FEA99EB1907FFD5357A /* PureLayout */, + ); + name = Pods; + sourceTree = ""; + }; + B7B80995527643776607AFFA75B91E24 /* Targets Support Files */ = { + isa = PBXGroup; + children = ( + 75D98FF52E597A11900E131B6C4E1ADA /* Pods */, + ); + name = "Targets Support Files"; + sourceTree = ""; + }; + BC3CA7F9E30CC8F7E2DD044DD34432FC /* Frameworks */ = { + isa = PBXGroup; + children = ( + 53F661C0CA7190D2CF05023FB33D61E4 /* iOS */, + ); + name = Frameworks; + sourceTree = ""; + }; + CCA510CFBEA2D207524CDA0D73C3B561 /* Products */ = { + isa = PBXGroup; + children = ( + B870EF585C629C2B8EFC01EFA066E0AC /* Pods.framework */, + 34BE0BA12096455AB6760CFDF1005D58 /* PureLayout.framework */, + ); + name = Products; + sourceTree = ""; + }; + FB712A69E0D41FEA99EB1907FFD5357A /* PureLayout */ = { + isa = PBXGroup; + children = ( + 13DC162AF7BEBCA584CAF9D9CEAD8319 /* ALView+PureLayout.h */, + 6FDCF9208FAF09CC79F2DA4FA5683C82 /* ALView+PureLayout.m */, + 913E7306AD4E255661D418473382CF54 /* NSArray+PureLayout.h */, + 191E1C6095DA6537B3B9AD63F2DABA12 /* NSArray+PureLayout.m */, + 9CD3AB8195F74BFC43D6997F61F6F298 /* NSLayoutConstraint+PureLayout.h */, + 97F5A0160929E8154C67BBC4B5A91B5C /* NSLayoutConstraint+PureLayout.m */, + 6E05779740DB7A4882324BB0CC77FE83 /* PureLayout.h */, + DAFA4BCE4B185A782DD016F84B3BE0CF /* PureLayout+Internal.h */, + 0FBC3E333821E19620FAC1463F61C533 /* PureLayoutDefines.h */, + 56E5F5118E3951F2C822D54DF77B17DB /* Support Files */, + ); + path = PureLayout; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXHeadersBuildPhase section */ + 0C97D2361202E0C0803501F6EFE50376 /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + 5EFAEC887045E3038CBA406FC9C48C82 /* Pods-umbrella.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + D6A8EB0B19838A8E6F05524B3A33BF15 /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + C07804D5CAE775845193B0BDEAE8153A /* ALView+PureLayout.h in Headers */, + 6354BF1C514445C33F9B65DD18205535 /* NSArray+PureLayout.h in Headers */, + E822E9813D45FF34F11862731B65F4D7 /* NSLayoutConstraint+PureLayout.h in Headers */, + 38792B4D4276C59B21ACF9B4DE6ED4F5 /* PureLayout+Internal.h in Headers */, + 8FB29797E35802BE65A888432368F471 /* PureLayout-umbrella.h in Headers */, + 98DE61629DE81688A6D460FF03DD172A /* PureLayout.h in Headers */, + F9A3864238BEAF7F67E75EF7417D7AF4 /* PureLayoutDefines.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXHeadersBuildPhase section */ + +/* Begin PBXNativeTarget section */ + 057BC0C6AD434A55BEB3F883C422AF4B /* Pods */ = { + isa = PBXNativeTarget; + buildConfigurationList = D2FB98E34FE23B33951F2DB1E322484F /* Build configuration list for PBXNativeTarget "Pods" */; + buildPhases = ( + 3BBEA412E86660B28BB741848540178E /* Sources */, + 52E761D0B069DCD4C6E2F74FA447C130 /* Frameworks */, + 0C97D2361202E0C0803501F6EFE50376 /* Headers */, + ); + buildRules = ( + ); + dependencies = ( + B499FB60A50262DAF978C33F6DCCE2F5 /* PBXTargetDependency */, + ); + name = Pods; + productName = Pods; + productReference = B870EF585C629C2B8EFC01EFA066E0AC /* Pods.framework */; + productType = "com.apple.product-type.framework"; + }; + 8240A687A12B3496C485DFBEB80E79E2 /* PureLayout */ = { + isa = PBXNativeTarget; + buildConfigurationList = 29946541803109559D5B69F86E5F2398 /* Build configuration list for PBXNativeTarget "PureLayout" */; + buildPhases = ( + ABBB6E4260C5266FB8BA4EC731A8D281 /* Sources */, + 8D982826564F33040944F955F4866DBD /* Frameworks */, + D6A8EB0B19838A8E6F05524B3A33BF15 /* Headers */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = PureLayout; + productName = PureLayout; + productReference = 34BE0BA12096455AB6760CFDF1005D58 /* PureLayout.framework */; + productType = "com.apple.product-type.framework"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + D41D8CD98F00B204E9800998ECF8427E /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 0700; + LastUpgradeCheck = 0700; + }; + buildConfigurationList = 2D8E8EC45A3A1A1D94AE762CB5028504 /* Build configuration list for PBXProject "Pods" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = 7DB346D0F39D3F0E887471402A8071AB; + productRefGroup = CCA510CFBEA2D207524CDA0D73C3B561 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 057BC0C6AD434A55BEB3F883C422AF4B /* Pods */, + 8240A687A12B3496C485DFBEB80E79E2 /* PureLayout */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXSourcesBuildPhase section */ + 3BBEA412E86660B28BB741848540178E /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + A9DC2F99B25B83F8896D0DEF1D5709D0 /* Pods-dummy.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + ABBB6E4260C5266FB8BA4EC731A8D281 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 40C283F04408D7C74CB6D9966B4CE10E /* ALView+PureLayout.m in Sources */, + 2241ABC30538E46F17BC59AFC645B6C5 /* NSArray+PureLayout.m in Sources */, + 8A42E3EC15CA6EFC7A14FF66419B4E0A /* NSLayoutConstraint+PureLayout.m in Sources */, + BEEF2FF4434A311B51CCAEA2D0BC4167 /* PureLayout-dummy.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + B499FB60A50262DAF978C33F6DCCE2F5 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + name = PureLayout; + target = 8240A687A12B3496C485DFBEB80E79E2 /* PureLayout */; + targetProxy = D4BE9AC9A09AF52392290EC0CA80E1A2 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin XCBuildConfiguration section */ + 116000359465EEA84BEB4A3D54B09C44 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 25EB15ADDC91D3318D94A842E4FC598D /* Pods.debug.xcconfig */; + buildSettings = { + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + CURRENT_PROJECT_VERSION = 1; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + ENABLE_STRICT_OBJC_MSGSEND = YES; + INFOPLIST_FILE = "Target Support Files/Pods/Info.plist"; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + MODULEMAP_FILE = "Target Support Files/Pods/Pods.modulemap"; + MTL_ENABLE_DEBUG_INFO = YES; + OTHER_LDFLAGS = ""; + OTHER_LIBTOOLFLAGS = ""; + PODS_ROOT = "$(SRCROOT)"; + PRODUCT_NAME = Pods; + SDKROOT = iphoneos; + SKIP_INSTALL = YES; + TARGETED_DEVICE_FAMILY = "1,2"; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = Debug; + }; + 4B0B1BF0388DEA06DE8DF1B21F4B00AB /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = CC4882E403503DE9288AF3969E260251 /* PureLayout-Private.xcconfig */; + buildSettings = { + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + CURRENT_PROJECT_VERSION = 3.0.0; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 3; + DYLIB_CURRENT_VERSION = "$(CURRENT_PROJECT_VERSION)"; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_PREFIX_HEADER = "Target Support Files/PureLayout/PureLayout-prefix.pch"; + INFOPLIST_FILE = "Target Support Files/PureLayout/Info.plist"; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + MODULEMAP_FILE = "Target Support Files/PureLayout/PureLayout.modulemap"; + MTL_ENABLE_DEBUG_INFO = NO; + PRODUCT_NAME = PureLayout; + SDKROOT = iphoneos; + SKIP_INSTALL = YES; + TARGETED_DEVICE_FAMILY = "1,2"; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = Release; + }; + A70CDAD61F90AC503C7D04CC22DA2923 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + ONLY_ACTIVE_ARCH = YES; + STRIP_INSTALLED_PRODUCT = NO; + SYMROOT = "${SRCROOT}/../build"; + }; + name = Debug; + }; + D7F9E64735A4A34EA962C8B922037D79 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = D77F20524604100E192667662A8784A5 /* Pods.release.xcconfig */; + buildSettings = { + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + CURRENT_PROJECT_VERSION = 1; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + ENABLE_STRICT_OBJC_MSGSEND = YES; + INFOPLIST_FILE = "Target Support Files/Pods/Info.plist"; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + MODULEMAP_FILE = "Target Support Files/Pods/Pods.modulemap"; + MTL_ENABLE_DEBUG_INFO = NO; + OTHER_LDFLAGS = ""; + OTHER_LIBTOOLFLAGS = ""; + PODS_ROOT = "$(SRCROOT)"; + PRODUCT_NAME = Pods; + SDKROOT = iphoneos; + SKIP_INSTALL = YES; + TARGETED_DEVICE_FAMILY = "1,2"; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = Release; + }; + DB5C373F43D2E2027D3302E3EB9783D7 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = CC4882E403503DE9288AF3969E260251 /* PureLayout-Private.xcconfig */; + buildSettings = { + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + CURRENT_PROJECT_VERSION = 3.0.0; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 3; + DYLIB_CURRENT_VERSION = "$(CURRENT_PROJECT_VERSION)"; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_PREFIX_HEADER = "Target Support Files/PureLayout/PureLayout-prefix.pch"; + INFOPLIST_FILE = "Target Support Files/PureLayout/Info.plist"; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + MODULEMAP_FILE = "Target Support Files/PureLayout/PureLayout.modulemap"; + MTL_ENABLE_DEBUG_INFO = YES; + PRODUCT_NAME = PureLayout; + SDKROOT = iphoneos; + SKIP_INSTALL = YES; + TARGETED_DEVICE_FAMILY = "1,2"; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = Debug; + }; + FB45FFD90572718D82AB9092B750F0CA /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = YES; + ENABLE_NS_ASSERTIONS = NO; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_PREPROCESSOR_DEFINITIONS = "RELEASE=1"; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + STRIP_INSTALLED_PRODUCT = NO; + SYMROOT = "${SRCROOT}/../build"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 29946541803109559D5B69F86E5F2398 /* Build configuration list for PBXNativeTarget "PureLayout" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + DB5C373F43D2E2027D3302E3EB9783D7 /* Debug */, + 4B0B1BF0388DEA06DE8DF1B21F4B00AB /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 2D8E8EC45A3A1A1D94AE762CB5028504 /* Build configuration list for PBXProject "Pods" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + A70CDAD61F90AC503C7D04CC22DA2923 /* Debug */, + FB45FFD90572718D82AB9092B750F0CA /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + D2FB98E34FE23B33951F2DB1E322484F /* Build configuration list for PBXNativeTarget "Pods" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 116000359465EEA84BEB4A3D54B09C44 /* Debug */, + D7F9E64735A4A34EA962C8B922037D79 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = D41D8CD98F00B204E9800998ECF8427E /* Project object */; +} diff --git a/Pods/PureLayout/LICENSE b/Pods/PureLayout/LICENSE new file mode 100755 index 0000000..5396bc0 --- /dev/null +++ b/Pods/PureLayout/LICENSE @@ -0,0 +1,9 @@ +This code is distributed under the terms and conditions of the MIT license. + +Copyright (c) 2014-2015 Tyler Fox + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/Pods/PureLayout/PureLayout/PureLayout/ALView+PureLayout.h b/Pods/PureLayout/PureLayout/PureLayout/ALView+PureLayout.h new file mode 100755 index 0000000..525e7aa --- /dev/null +++ b/Pods/PureLayout/PureLayout/PureLayout/ALView+PureLayout.h @@ -0,0 +1,213 @@ +// +// ALView+PureLayout.h +// https://github.com/smileyborg/PureLayout +// +// Copyright (c) 2012 Richard Turton +// Copyright (c) 2013-2015 Tyler Fox +// +// This code is distributed under the terms and conditions of the MIT license. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +// + +#import "PureLayoutDefines.h" + + +__PL_ASSUME_NONNULL_BEGIN + +#pragma mark ALView+PureLayout + +/** + A category on UIView/NSView that provides a simple yet powerful interface for creating Auto Layout constraints. + */ +@interface ALView (PureLayout) + + +#pragma mark Factory & Initializer Methods + +/** Creates and returns a new view that does not convert the autoresizing mask into constraints. */ ++ (instancetype)newAutoLayoutView; + +/** Initializes and returns a new view that does not convert the autoresizing mask into constraints. */ +- (instancetype)initForAutoLayout; + +/** Configures an existing view to not convert the autoresizing mask into constraints and returns the view. */ +- (instancetype)configureForAutoLayout; + + +#pragma mark Center & Align in Superview + +/** Centers the view in its superview. */ +- (__NSArray_of(NSLayoutConstraint *) *)autoCenterInSuperview; + +/** Aligns the view to the same axis of its superview. */ +- (NSLayoutConstraint *)autoAlignAxisToSuperviewAxis:(ALAxis)axis; + +#if __PureLayout_MinBaseSDK_iOS_8_0 + +/** Centers the view in its superview's margins. Available in iOS 8.0 and later. */ +- (__NSArray_of(NSLayoutConstraint *) *)autoCenterInSuperviewMargins; + +/** Aligns the view to the corresponding margin axis of its superview. Available in iOS 8.0 and later. */ +- (NSLayoutConstraint *)autoAlignAxisToSuperviewMarginAxis:(ALAxis)axis; + +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ + + +#pragma mark Pin Edges to Superview + +/** Pins the given edge of the view to the same edge of its superview. */ +- (NSLayoutConstraint *)autoPinEdgeToSuperviewEdge:(ALEdge)edge; + +/** Pins the given edge of the view to the same edge of its superview with an inset. */ +- (NSLayoutConstraint *)autoPinEdgeToSuperviewEdge:(ALEdge)edge withInset:(CGFloat)inset; + +/** Pins the given edge of the view to the same edge of its superview with an inset as a maximum or minimum. */ +- (NSLayoutConstraint *)autoPinEdgeToSuperviewEdge:(ALEdge)edge withInset:(CGFloat)inset relation:(NSLayoutRelation)relation; + +/** Pins the edges of the view to the edges of its superview. */ +- (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewEdges; + +/** Pins the edges of the view to the edges of its superview with the given edge insets. */ +- (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets; + +/** Pins 3 of the 4 edges of the view to the edges of its superview with the given edge insets, excluding one edge. */ +- (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets excludingEdge:(ALEdge)edge; + +#if __PureLayout_MinBaseSDK_iOS_8_0 + +/** Pins the given edge of the view to the corresponding margin of its superview. Available in iOS 8.0 and later. */ +- (NSLayoutConstraint *)autoPinEdgeToSuperviewMargin:(ALEdge)edge; + +/** Pins the given edge of the view to the corresponding margin of its superview as a maximum or minimum. Available in iOS 8.0 and later. */ +- (NSLayoutConstraint *)autoPinEdgeToSuperviewMargin:(ALEdge)edge relation:(NSLayoutRelation)relation; + +/** Pins the edges of the view to the margins of its superview. Available in iOS 8.0 and later. */ +- (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewMargins; + +/** Pins 3 of the 4 edges of the view to the margins of its superview excluding one edge. Available in iOS 8.0 and later. */ +- (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewMarginsExcludingEdge:(ALEdge)edge; + +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ + + +#pragma mark Pin Edges + +/** Pins an edge of the view to a given edge of another view. */ +- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(ALView *)otherView; + +/** Pins an edge of the view to a given edge of another view with an offset. */ +- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(ALView *)otherView withOffset:(CGFloat)offset; + +/** Pins an edge of the view to a given edge of another view with an offset as a maximum or minimum. */ +- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(ALView *)otherView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation; + + +#pragma mark Align Axes + +/** Aligns an axis of the view to the same axis of another view. */ +- (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(ALView *)otherView; + +/** Aligns an axis of the view to the same axis of another view with an offset. */ +- (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(ALView *)otherView withOffset:(CGFloat)offset; + +/** Aligns an axis of the view to the same axis of another view with a multiplier. */ +- (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(ALView *)otherView withMultiplier:(CGFloat)multiplier; + + +#pragma mark Match Dimensions + +/** Matches a dimension of the view to a given dimension of another view. */ +- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)otherView; + +/** Matches a dimension of the view to a given dimension of another view with an offset. */ +- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)otherView withOffset:(CGFloat)offset; + +/** Matches a dimension of the view to a given dimension of another view with an offset as a maximum or minimum. */ +- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)otherView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation; + +/** Matches a dimension of the view to a multiple of a given dimension of another view. */ +- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)otherView withMultiplier:(CGFloat)multiplier; + +/** Matches a dimension of the view to a multiple of a given dimension of another view as a maximum or minimum. */ +- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)otherView withMultiplier:(CGFloat)multiplier relation:(NSLayoutRelation)relation; + + +#pragma mark Set Dimensions + +/** Sets the view to a specific size. */ +- (__NSArray_of(NSLayoutConstraint *) *)autoSetDimensionsToSize:(CGSize)size; + +/** Sets the given dimension of the view to a specific size. */ +- (NSLayoutConstraint *)autoSetDimension:(ALDimension)dimension toSize:(CGFloat)size; + +/** Sets the given dimension of the view to a specific size as a maximum or minimum. */ +- (NSLayoutConstraint *)autoSetDimension:(ALDimension)dimension toSize:(CGFloat)size relation:(NSLayoutRelation)relation; + + +#pragma mark Set Content Compression Resistance & Hugging + +/** Sets the priority of content compression resistance for an axis. + NOTE: This method must be called from within the block passed into the method +[NSLayoutConstraint autoSetPriority:forConstraints:] */ +- (void)autoSetContentCompressionResistancePriorityForAxis:(ALAxis)axis; + +/** Sets the priority of content hugging for an axis. + NOTE: This method must be called from within the block passed into the method +[NSLayoutConstraint autoSetPriority:forConstraints:] */ +- (void)autoSetContentHuggingPriorityForAxis:(ALAxis)axis; + + +#pragma mark Constrain Any Attributes + +/** Constrains an attribute of the view to a given attribute of another view. */ +- (NSLayoutConstraint *)autoConstrainAttribute:(ALAttribute)attribute toAttribute:(ALAttribute)toAttribute ofView:(ALView *)otherView; + +/** Constrains an attribute of the view to a given attribute of another view with an offset. */ +- (NSLayoutConstraint *)autoConstrainAttribute:(ALAttribute)attribute toAttribute:(ALAttribute)toAttribute ofView:(ALView *)otherView withOffset:(CGFloat)offset; + +/** Constrains an attribute of the view to a given attribute of another view with an offset as a maximum or minimum. */ +- (NSLayoutConstraint *)autoConstrainAttribute:(ALAttribute)attribute toAttribute:(ALAttribute)toAttribute ofView:(ALView *)otherView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation; + +/** Constrains an attribute of the view to a given attribute of another view with a multiplier. */ +- (NSLayoutConstraint *)autoConstrainAttribute:(ALAttribute)attribute toAttribute:(ALAttribute)toAttribute ofView:(ALView *)otherView withMultiplier:(CGFloat)multiplier; + +/** Constrains an attribute of the view to a given attribute of another view with a multiplier as a maximum or minimum. */ +- (NSLayoutConstraint *)autoConstrainAttribute:(ALAttribute)attribute toAttribute:(ALAttribute)toAttribute ofView:(ALView *)otherView withMultiplier:(CGFloat)multiplier relation:(NSLayoutRelation)relation; + + +#pragma mark Pin to Layout Guides (iOS only) + +#if TARGET_OS_IPHONE + +/** Pins the top edge of the view to the top layout guide of the given view controller with an inset. Available on iOS only. */ +- (NSLayoutConstraint *)autoPinToTopLayoutGuideOfViewController:(UIViewController *)viewController withInset:(CGFloat)inset; + +/** Pins the top edge of the view to the top layout guide of the given view controller with an inset as a maximum or minimum. Available on iOS only. */ +- (NSLayoutConstraint *)autoPinToTopLayoutGuideOfViewController:(UIViewController *)viewController withInset:(CGFloat)inset relation:(NSLayoutRelation)relation; + +/** Pins the bottom edge of the view to the bottom layout guide of the given view controller with an inset. Available on iOS only. */ +- (NSLayoutConstraint *)autoPinToBottomLayoutGuideOfViewController:(UIViewController *)viewController withInset:(CGFloat)inset; + +/** Pins the bottom edge of the view to the bottom layout guide of the given view controller with an inset as a maximum or minimum. Available on iOS only. */ +- (NSLayoutConstraint *)autoPinToBottomLayoutGuideOfViewController:(UIViewController *)viewController withInset:(CGFloat)inset relation:(NSLayoutRelation)relation; + +#endif /* TARGET_OS_IPHONE */ + +@end + +__PL_ASSUME_NONNULL_END diff --git a/Pods/PureLayout/PureLayout/PureLayout/ALView+PureLayout.m b/Pods/PureLayout/PureLayout/PureLayout/ALView+PureLayout.m new file mode 100755 index 0000000..dcc7309 --- /dev/null +++ b/Pods/PureLayout/PureLayout/PureLayout/ALView+PureLayout.m @@ -0,0 +1,848 @@ +// +// ALView+PureLayout.m +// https://github.com/smileyborg/PureLayout +// +// Copyright (c) 2012 Richard Turton +// Copyright (c) 2013-2015 Tyler Fox +// +// This code is distributed under the terms and conditions of the MIT license. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +// + +#import "ALView+PureLayout.h" +#import "NSLayoutConstraint+PureLayout.h" +#import "NSArray+PureLayout.h" +#import "PureLayout+Internal.h" + + +#pragma mark - ALView+PureLayout + +@implementation ALView (PureLayout) + + +#pragma mark Factory & Initializer Methods + +/** + Creates and returns a new view that does not convert the autoresizing mask into constraints. + */ ++ (instancetype)newAutoLayoutView +{ + ALView *view = [self new]; + view.translatesAutoresizingMaskIntoConstraints = NO; + return view; +} + +/** + Initializes and returns a new view that does not convert the autoresizing mask into constraints. + */ +- (instancetype)initForAutoLayout +{ + self = [self init]; + if (self) { + self.translatesAutoresizingMaskIntoConstraints = NO; + } + return self; +} + +/** + Configures an existing view to not convert the autoresizing mask into constraints and returns the view. + */ +- (instancetype)configureForAutoLayout +{ + self.translatesAutoresizingMaskIntoConstraints = NO; + return self; +} + + +#pragma mark Center in Superview + +/** + Centers the view in its superview. + + @return An array of constraints added. + */ +- (__NSArray_of(NSLayoutConstraint *) *)autoCenterInSuperview +{ + __NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new]; + [constraints addObject:[self autoAlignAxisToSuperviewAxis:ALAxisHorizontal]]; + [constraints addObject:[self autoAlignAxisToSuperviewAxis:ALAxisVertical]]; + return constraints; +} + +/** + Aligns the view to the same axis of its superview. + + @param axis The axis of this view and of its superview to align. + @return The constraint added. + */ +- (NSLayoutConstraint *)autoAlignAxisToSuperviewAxis:(ALAxis)axis +{ + self.translatesAutoresizingMaskIntoConstraints = NO; + ALView *superview = self.superview; + NSAssert(superview, @"View's superview must not be nil.\nView: %@", self); + return [self autoConstrainAttribute:(ALAttribute)axis toAttribute:(ALAttribute)axis ofView:superview]; +} + +#if __PureLayout_MinBaseSDK_iOS_8_0 + +/** + Centers the view in its superview, taking into account the layout margins of both the view and its superview. + + @return An array of constraints added. + */ +- (__NSArray_of(NSLayoutConstraint *) *)autoCenterInSuperviewMargins +{ + __NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new]; + [constraints addObject:[self autoAlignAxisToSuperviewMarginAxis:ALAxisHorizontal]]; + [constraints addObject:[self autoAlignAxisToSuperviewMarginAxis:ALAxisVertical]]; + return constraints; +} + +/** + Aligns the view to the corresponding margin axis of its superview. + + @param axis The axis of this view to align to the corresponding margin axis of its superview. + @return The constraint added. + */ +- (NSLayoutConstraint *)autoAlignAxisToSuperviewMarginAxis:(ALAxis)axis +{ + self.translatesAutoresizingMaskIntoConstraints = NO; + ALView *superview = self.superview; + NSAssert(superview, @"View's superview must not be nil.\nView: %@", self); + ALMarginAxis marginAxis = [NSLayoutConstraint al_marginAxisForAxis:axis]; + return [self autoConstrainAttribute:(ALAttribute)axis toAttribute:(ALAttribute)marginAxis ofView:superview]; +} + +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ + + +#pragma mark Pin Edges to Superview + +/** + Pins the given edge of the view to the same edge of its superview. + + @param edge The edge of this view and its superview to pin. + @return The constraint added. + */ +- (NSLayoutConstraint *)autoPinEdgeToSuperviewEdge:(ALEdge)edge +{ + return [self autoPinEdgeToSuperviewEdge:edge withInset:0.0]; +} + +/** + Pins the given edge of the view to the same edge of its superview with an inset. + + @param edge The edge of this view and its superview to pin. + @param inset The amount to inset this view's edge from the superview's edge. + @return The constraint added. + */ +- (NSLayoutConstraint *)autoPinEdgeToSuperviewEdge:(ALEdge)edge withInset:(CGFloat)inset +{ + return [self autoPinEdgeToSuperviewEdge:edge withInset:inset relation:NSLayoutRelationEqual]; +} + +/** + Pins the given edge of the view to the same edge of its superview with an inset as a maximum or minimum. + + @param edge The edge of this view and its superview to pin. + @param inset The amount to inset this view's edge from the superview's edge. + @param relation Whether the inset should be at least, at most, or exactly equal to the given value. + @return The constraint added. + */ +- (NSLayoutConstraint *)autoPinEdgeToSuperviewEdge:(ALEdge)edge withInset:(CGFloat)inset relation:(NSLayoutRelation)relation +{ + self.translatesAutoresizingMaskIntoConstraints = NO; + ALView *superview = self.superview; + NSAssert(superview, @"View's superview must not be nil.\nView: %@", self); + if (edge == ALEdgeBottom || edge == ALEdgeRight || edge == ALEdgeTrailing) { + // The bottom, right, and trailing insets (and relations, if an inequality) are inverted to become offsets + inset = -inset; + if (relation == NSLayoutRelationLessThanOrEqual) { + relation = NSLayoutRelationGreaterThanOrEqual; + } else if (relation == NSLayoutRelationGreaterThanOrEqual) { + relation = NSLayoutRelationLessThanOrEqual; + } + } + return [self autoPinEdge:edge toEdge:edge ofView:superview withOffset:inset relation:relation]; +} + +/** + Pins the edges of the view to the edges of its superview. + + @return An array of constraints added. + */ +- (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewEdges +{ + return [self autoPinEdgesToSuperviewEdgesWithInsets:ALEdgeInsetsZero]; +} + +/** + Pins the edges of the view to the edges of its superview with the given edge insets. + The insets.left corresponds to a leading edge constraint, and insets.right corresponds to a trailing edge constraint. + + @param insets The insets for this view's edges from its superview's edges. + @return An array of constraints added. + */ +- (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets +{ + __NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new]; + [constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:insets.top]]; + [constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:insets.left]]; + [constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:insets.bottom]]; + [constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeTrailing withInset:insets.right]]; + return constraints; +} + +/** + Pins 3 of the 4 edges of the view to the edges of its superview with the given edge insets, excluding one edge. + The insets.left corresponds to a leading edge constraint, and insets.right corresponds to a trailing edge constraint. + + @param insets The insets for this view's edges from its superview's edges. The inset corresponding to the excluded edge + will be ignored. + @param edge The edge of this view to exclude in pinning to its superview; this method will not apply any constraint to it. + @return An array of constraints added. + */ +- (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets excludingEdge:(ALEdge)edge +{ + __NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new]; + if (edge != ALEdgeTop) { + [constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:insets.top]]; + } + if (edge != ALEdgeLeading && edge != ALEdgeLeft) { + [constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:insets.left]]; + } + if (edge != ALEdgeBottom) { + [constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:insets.bottom]]; + } + if (edge != ALEdgeTrailing && edge != ALEdgeRight) { + [constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeTrailing withInset:insets.right]]; + } + return constraints; +} + +#if __PureLayout_MinBaseSDK_iOS_8_0 + +/** + Pins the given edge of the view to the corresponding margin of its superview. + + @param edge The edge of this view to pin to the corresponding margin of its superview. + @return The constraint added. + */ +- (NSLayoutConstraint *)autoPinEdgeToSuperviewMargin:(ALEdge)edge +{ + return [self autoPinEdgeToSuperviewMargin:edge relation:NSLayoutRelationEqual]; +} + +/** + Pins the given edge of the view to the corresponding margin of its superview as a maximum or minimum. + + @param edge The edge of this view to pin to the corresponding margin of its superview. + @param relation Whether the edge should be inset by at least, at most, or exactly the superview's margin. + @return The constraint added. + */ +- (NSLayoutConstraint *)autoPinEdgeToSuperviewMargin:(ALEdge)edge relation:(NSLayoutRelation)relation +{ + self.translatesAutoresizingMaskIntoConstraints = NO; + ALView *superview = self.superview; + NSAssert(superview, @"View's superview must not be nil.\nView: %@", self); + if (edge == ALEdgeBottom || edge == ALEdgeRight || edge == ALEdgeTrailing) { + // The bottom, right, and trailing relations are inverted + if (relation == NSLayoutRelationLessThanOrEqual) { + relation = NSLayoutRelationGreaterThanOrEqual; + } else if (relation == NSLayoutRelationGreaterThanOrEqual) { + relation = NSLayoutRelationLessThanOrEqual; + } + } + ALMargin margin = [NSLayoutConstraint al_marginForEdge:edge]; + return [self autoConstrainAttribute:(ALAttribute)edge toAttribute:(ALAttribute)margin ofView:superview withOffset:0.0 relation:relation]; +} + +/** + Pins the edges of the view to the margins of its superview. + + @return An array of constraints added. + */ +- (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewMargins +{ + __NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new]; + [constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeTop]]; + [constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeLeading]]; + [constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeBottom]]; + [constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeTrailing]]; + return constraints; +} + +/** + Pins 3 of the 4 edges of the view to the margins of its superview, excluding one edge. + + @param edge The edge of this view to exclude in pinning to its superview; this method will not apply any constraint to it. + @return An array of constraints added. + */ +- (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewMarginsExcludingEdge:(ALEdge)edge +{ + __NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new]; + if (edge != ALEdgeTop) { + [constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeTop]]; + } + if (edge != ALEdgeLeading && edge != ALEdgeLeft) { + [constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeLeading]]; + } + if (edge != ALEdgeBottom) { + [constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeBottom]]; + } + if (edge != ALEdgeTrailing && edge != ALEdgeRight) { + [constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeTrailing]]; + } + return constraints; +} + +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ + + +#pragma mark Pin Edges + +/** + Pins an edge of the view to a given edge of another view. + + @param edge The edge of this view to pin. + @param toEdge The edge of the other view to pin to. + @param otherView The other view to pin to. Must be in the same view hierarchy as this view. + @return The constraint added. + */ +- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(ALView *)otherView +{ + return [self autoPinEdge:edge toEdge:toEdge ofView:otherView withOffset:0.0]; +} + +/** + Pins an edge of the view to a given edge of another view with an offset. + + @param edge The edge of this view to pin. + @param toEdge The edge of the other view to pin to. + @param otherView The other view to pin to. Must be in the same view hierarchy as this view. + @param offset The offset between the edge of this view and the edge of the other view. + @return The constraint added. + */ +- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(ALView *)otherView withOffset:(CGFloat)offset +{ + return [self autoPinEdge:edge toEdge:toEdge ofView:otherView withOffset:offset relation:NSLayoutRelationEqual]; +} + +/** + Pins an edge of the view to a given edge of another view with an offset as a maximum or minimum. + + @param edge The edge of this view to pin. + @param toEdge The edge of the other view to pin to. + @param otherView The other view to pin to. Must be in the same view hierarchy as this view. + @param offset The offset between the edge of this view and the edge of the other view. + @param relation Whether the offset should be at least, at most, or exactly equal to the given value. + @return The constraint added. + */ +- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(ALView *)otherView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation +{ + return [self autoConstrainAttribute:(ALAttribute)edge toAttribute:(ALAttribute)toEdge ofView:otherView withOffset:offset relation:relation]; +} + + +#pragma mark Align Axes + +/** + Aligns an axis of the view to the same axis of another view. + + @param axis The axis of this view and the other view to align. + @param otherView The other view to align to. Must be in the same view hierarchy as this view. + @return The constraint added. + */ +- (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(ALView *)otherView +{ + return [self autoAlignAxis:axis toSameAxisOfView:otherView withOffset:0.0]; +} + +/** + Aligns an axis of the view to the same axis of another view with an offset. + + @param axis The axis of this view and the other view to align. + @param otherView The other view to align to. Must be in the same view hierarchy as this view. + @param offset The offset between the axis of this view and the axis of the other view. + @return The constraint added. + */ +- (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(ALView *)otherView withOffset:(CGFloat)offset +{ + return [self autoConstrainAttribute:(ALAttribute)axis toAttribute:(ALAttribute)axis ofView:otherView withOffset:offset]; +} + +/** + Aligns an axis of the view to the same axis of another view with a multiplier. + + @param axis The axis of this view and the other view to align. + @param otherView The other view to align to. Must be in the same view hierarchy as this view. + @param multiplier The multiplier between the axis of this view and the axis of the other view. + @return The constraint added. + */ +- (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(ALView *)otherView withMultiplier:(CGFloat)multiplier +{ + return [self autoConstrainAttribute:(ALAttribute)axis toAttribute:(ALAttribute)axis ofView:otherView withMultiplier:multiplier]; +} + + +#pragma mark Match Dimensions + +/** + Matches a dimension of the view to a given dimension of another view. + + @param dimension The dimension of this view to pin. + @param toDimension The dimension of the other view to pin to. + @param otherView The other view to match to. Must be in the same view hierarchy as this view. + @return The constraint added. + */ +- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)otherView +{ + return [self autoMatchDimension:dimension toDimension:toDimension ofView:otherView withOffset:0.0]; +} + +/** + Matches a dimension of the view to a given dimension of another view with an offset. + + @param dimension The dimension of this view to pin. + @param toDimension The dimension of the other view to pin to. + @param otherView The other view to match to. Must be in the same view hierarchy as this view. + @param offset The offset between the dimension of this view and the dimension of the other view. + @return The constraint added. + */ +- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)otherView withOffset:(CGFloat)offset +{ + return [self autoMatchDimension:dimension toDimension:toDimension ofView:otherView withOffset:offset relation:NSLayoutRelationEqual]; +} + +/** + Matches a dimension of the view to a given dimension of another view with an offset as a maximum or minimum. + + @param dimension The dimension of this view to pin. + @param toDimension The dimension of the other view to pin to. + @param otherView The other view to match to. Must be in the same view hierarchy as this view. + @param offset The offset between the dimension of this view and the dimension of the other view. + @param relation Whether the offset should be at least, at most, or exactly equal to the given value. + @return The constraint added. + */ +- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)otherView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation +{ + return [self autoConstrainAttribute:(ALAttribute)dimension toAttribute:(ALAttribute)toDimension ofView:otherView withOffset:offset relation:relation]; +} + +/** + Matches a dimension of the view to a multiple of a given dimension of another view. + + @param dimension The dimension of this view to pin. + @param toDimension The dimension of the other view to pin to. + @param otherView The other view to match to. Must be in the same view hierarchy as this view. + @param multiplier The multiple of the other view's given dimension that this view's given dimension should be. + @return The constraint added. + */ +- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)otherView withMultiplier:(CGFloat)multiplier +{ + return [self autoMatchDimension:dimension toDimension:toDimension ofView:otherView withMultiplier:multiplier relation:NSLayoutRelationEqual]; +} + +/** + Matches a dimension of the view to a multiple of a given dimension of another view as a maximum or minimum. + + @param dimension The dimension of this view to pin. + @param toDimension The dimension of the other view to pin to. + @param otherView The other view to match to. Must be in the same view hierarchy as this view. + @param multiplier The multiple of the other view's given dimension that this view's given dimension should be. + @param relation Whether the multiple should be at least, at most, or exactly equal to the given value. + @return The constraint added. + */ +- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)otherView withMultiplier:(CGFloat)multiplier relation:(NSLayoutRelation)relation +{ + return [self autoConstrainAttribute:(ALAttribute)dimension toAttribute:(ALAttribute)toDimension ofView:otherView withMultiplier:multiplier relation:relation]; +} + + +#pragma mark Set Dimensions + +/** + Sets the view to a specific size. + + @param size The size to set this view's dimensions to. + @return An array of constraints added. + */ +- (__NSArray_of(NSLayoutConstraint *) *)autoSetDimensionsToSize:(CGSize)size +{ + __NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new]; + [constraints addObject:[self autoSetDimension:ALDimensionWidth toSize:size.width]]; + [constraints addObject:[self autoSetDimension:ALDimensionHeight toSize:size.height]]; + return constraints; +} + +/** + Sets the given dimension of the view to a specific size. + + @param dimension The dimension of this view to set. + @param size The size to set the given dimension to. + @return The constraint added. + */ +- (NSLayoutConstraint *)autoSetDimension:(ALDimension)dimension toSize:(CGFloat)size +{ + return [self autoSetDimension:dimension toSize:size relation:NSLayoutRelationEqual]; +} + +/** + Sets the given dimension of the view to a specific size as a maximum or minimum. + + @param dimension The dimension of this view to set. + @param size The size to set the given dimension to. + @param relation Whether the size should be at least, at most, or exactly equal to the given value. + @return The constraint added. + */ +- (NSLayoutConstraint *)autoSetDimension:(ALDimension)dimension toSize:(CGFloat)size relation:(NSLayoutRelation)relation +{ + self.translatesAutoresizingMaskIntoConstraints = NO; + NSLayoutAttribute layoutAttribute = [NSLayoutConstraint al_layoutAttributeForAttribute:(ALAttribute)dimension]; + NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:layoutAttribute relatedBy:relation toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0.0 constant:size]; + [constraint autoInstall]; + return constraint; +} + + +#pragma mark Set Content Compression Resistance & Hugging + +/** + Sets the priority of content compression resistance for an axis. + NOTE: This method must be called from within the block passed into the method +[autoSetPriority:forConstraints:] + + @param axis The axis to set the content compression resistance priority for. + */ +- (void)autoSetContentCompressionResistancePriorityForAxis:(ALAxis)axis +{ + NSAssert([NSLayoutConstraint al_isExecutingPriorityConstraintsBlock], @"%@ should only be called from within the block passed into the method +[autoSetPriority:forConstraints:]", NSStringFromSelector(_cmd)); + if ([NSLayoutConstraint al_isExecutingPriorityConstraintsBlock]) { + self.translatesAutoresizingMaskIntoConstraints = NO; + ALLayoutConstraintAxis constraintAxis = [NSLayoutConstraint al_constraintAxisForAxis:axis]; +#if TARGET_OS_IPHONE + [self setContentCompressionResistancePriority:[NSLayoutConstraint al_currentGlobalConstraintPriority] forAxis:constraintAxis]; +#else + [self setContentCompressionResistancePriority:[NSLayoutConstraint al_currentGlobalConstraintPriority] forOrientation:constraintAxis]; +#endif /* TARGET_OS_IPHONE */ + } +} + +/** + Sets the priority of content hugging for an axis. + NOTE: This method must be called from within the block passed into the method +[autoSetPriority:forConstraints:] + + @param axis The axis to set the content hugging priority for. + */ +- (void)autoSetContentHuggingPriorityForAxis:(ALAxis)axis +{ + NSAssert([NSLayoutConstraint al_isExecutingPriorityConstraintsBlock], @"%@ should only be called from within the block passed into the method +[autoSetPriority:forConstraints:]", NSStringFromSelector(_cmd)); + if ([NSLayoutConstraint al_isExecutingPriorityConstraintsBlock]) { + self.translatesAutoresizingMaskIntoConstraints = NO; + ALLayoutConstraintAxis constraintAxis = [NSLayoutConstraint al_constraintAxisForAxis:axis]; +#if TARGET_OS_IPHONE + [self setContentHuggingPriority:[NSLayoutConstraint al_currentGlobalConstraintPriority] forAxis:constraintAxis]; +#else + [self setContentHuggingPriority:[NSLayoutConstraint al_currentGlobalConstraintPriority] forOrientation:constraintAxis]; +#endif /* TARGET_OS_IPHONE */ + } +} + + +#pragma mark Constrain Any Attributes + +/** + Constrains an attribute of the view to a given attribute of another view. + This method can be used to constrain different types of attributes across two views. + + @param attribute Any attribute of this view to constrain. + @param toAttribute Any attribute of the other view to constrain to. + @param otherView The other view to constrain to. Must be in the same view hierarchy as this view. + @return The constraint added. + */ +- (NSLayoutConstraint *)autoConstrainAttribute:(ALAttribute)attribute toAttribute:(ALAttribute)toAttribute ofView:(ALView *)otherView +{ + return [self autoConstrainAttribute:attribute toAttribute:toAttribute ofView:otherView withOffset:0.0]; +} + +/** + Constrains an attribute of the view to a given attribute of another view with an offset. + This method can be used to constrain different types of attributes across two views. + + @param attribute Any attribute of this view to constrain. + @param toAttribute Any attribute of the other view to constrain to. + @param otherView The other view to constrain to. Must be in the same view hierarchy as this view. + @param offset The offset between the attribute of this view and the attribute of the other view. + @return The constraint added. + */ +- (NSLayoutConstraint *)autoConstrainAttribute:(ALAttribute)attribute toAttribute:(ALAttribute)toAttribute ofView:(ALView *)otherView withOffset:(CGFloat)offset +{ + return [self autoConstrainAttribute:attribute toAttribute:toAttribute ofView:otherView withOffset:offset relation:NSLayoutRelationEqual]; +} + +/** + Constrains an attribute of the view to a given attribute of another view with an offset as a maximum or minimum. + This method can be used to constrain different types of attributes across two views. + + @param attribute Any attribute of this view to constrain. + @param toAttribute Any attribute of the other view to constrain to. + @param otherView The other view to constrain to. Must be in the same view hierarchy as this view. + @param offset The offset between the attribute of this view and the attribute of the other view. + @param relation Whether the offset should be at least, at most, or exactly equal to the given value. + @return The constraint added. + */ +- (NSLayoutConstraint *)autoConstrainAttribute:(ALAttribute)attribute toAttribute:(ALAttribute)toAttribute ofView:(ALView *)otherView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation +{ + self.translatesAutoresizingMaskIntoConstraints = NO; + NSLayoutAttribute layoutAttribute = [NSLayoutConstraint al_layoutAttributeForAttribute:attribute]; + NSLayoutAttribute toLayoutAttribute = [NSLayoutConstraint al_layoutAttributeForAttribute:toAttribute]; + NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:layoutAttribute relatedBy:relation toItem:otherView attribute:toLayoutAttribute multiplier:1.0 constant:offset]; + [constraint autoInstall]; + return constraint; +} + +/** + Constrains an attribute of the view to a given attribute of another view with a multiplier. + This method can be used to constrain different types of attributes across two views. + + @param attribute Any attribute of this view to constrain. + @param toAttribute Any attribute of the other view to constrain to. + @param otherView The other view to constrain to. Must be in the same view hierarchy as this view. + @param multiplier The multiplier between the attribute of this view and the attribute of the other view. + @return The constraint added. + */ +- (NSLayoutConstraint *)autoConstrainAttribute:(ALAttribute)attribute toAttribute:(ALAttribute)toAttribute ofView:(ALView *)otherView withMultiplier:(CGFloat)multiplier +{ + return [self autoConstrainAttribute:attribute toAttribute:toAttribute ofView:otherView withMultiplier:multiplier relation:NSLayoutRelationEqual]; +} + +/** + Constrains an attribute of the view to a given attribute of another view with a multiplier as a maximum or minimum. + This method can be used to constrain different types of attributes across two views. + + @param attribute Any attribute of this view to constrain. + @param toAttribute Any attribute of the other view to constrain to. + @param otherView The other view to constrain to. Must be in the same view hierarchy as this view. + @param multiplier The multiplier between the attribute of this view and the attribute of the other view. + @param relation Whether the multiplier should be at least, at most, or exactly equal to the given value. + @return The constraint added. + */ +- (NSLayoutConstraint *)autoConstrainAttribute:(ALAttribute)attribute toAttribute:(ALAttribute)toAttribute ofView:(ALView *)otherView withMultiplier:(CGFloat)multiplier relation:(NSLayoutRelation)relation +{ + self.translatesAutoresizingMaskIntoConstraints = NO; + NSLayoutAttribute layoutAttribute = [NSLayoutConstraint al_layoutAttributeForAttribute:attribute]; + NSLayoutAttribute toLayoutAttribute = [NSLayoutConstraint al_layoutAttributeForAttribute:toAttribute]; + NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:layoutAttribute relatedBy:relation toItem:otherView attribute:toLayoutAttribute multiplier:multiplier constant:0.0]; + [constraint autoInstall]; + return constraint; +} + + +#pragma mark Pin to Layout Guides + +#if TARGET_OS_IPHONE + +/** + Pins the top edge of the view to the top layout guide of the given view controller with an inset. + For compatibility with iOS 6 (where layout guides do not exist), this method will simply pin the top edge of + the view to the top edge of the given view controller's view with an inset. + + @param viewController The view controller whose topLayoutGuide should be used to pin to. + @param inset The amount to inset this view's top edge from the layout guide. + @return The constraint added. + */ +- (NSLayoutConstraint *)autoPinToTopLayoutGuideOfViewController:(UIViewController *)viewController withInset:(CGFloat)inset +{ + return [self autoPinToTopLayoutGuideOfViewController:viewController withInset:inset relation:NSLayoutRelationEqual]; +} + +- (NSLayoutConstraint *)autoPinToTopLayoutGuideOfViewController:(UIViewController *)viewController withInset:(CGFloat)inset relation:(NSLayoutRelation)relation +{ + if (__PureLayout_MinSysVer_iOS_7_0) { + self.translatesAutoresizingMaskIntoConstraints = NO; + NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeTop relatedBy:relation toItem:viewController.topLayoutGuide attribute:NSLayoutAttributeBottom multiplier:1.0 constant:inset]; + [viewController.view al_addConstraint:constraint]; // Can't use autoInstall because the layout guide is not a view + return constraint; + } else { + // iOS 6 fallback + return [self autoPinEdge:ALEdgeTop toEdge:ALEdgeTop ofView:viewController.view withOffset:inset relation:relation]; + } +} + +/** + Pins the bottom edge of the view to the bottom layout guide of the given view controller with an inset. + For compatibility with iOS 6 (where layout guides do not exist), this method will simply pin the bottom edge of + the view to the bottom edge of the given view controller's view with an inset. + + @param viewController The view controller whose bottomLayoutGuide should be used to pin to. + @param inset The amount to inset this view's bottom edge from the layout guide. + @return The constraint added. + */ +- (NSLayoutConstraint *)autoPinToBottomLayoutGuideOfViewController:(UIViewController *)viewController withInset:(CGFloat)inset +{ + return [self autoPinToBottomLayoutGuideOfViewController:viewController withInset:inset relation:NSLayoutRelationEqual]; +} + +- (NSLayoutConstraint *)autoPinToBottomLayoutGuideOfViewController:(UIViewController *)viewController withInset:(CGFloat)inset relation:(NSLayoutRelation)relation +{ + // The bottom inset (and relation, if an inequality) is inverted to become an offset + inset = -inset; + if (relation == NSLayoutRelationLessThanOrEqual) { + relation = NSLayoutRelationGreaterThanOrEqual; + } else if (relation == NSLayoutRelationGreaterThanOrEqual) { + relation = NSLayoutRelationLessThanOrEqual; + } + if (__PureLayout_MinSysVer_iOS_7_0) { + self.translatesAutoresizingMaskIntoConstraints = NO; + NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeBottom relatedBy:relation toItem:viewController.bottomLayoutGuide attribute:NSLayoutAttributeTop multiplier:1.0 constant:inset]; + [viewController.view al_addConstraint:constraint]; // Can't use autoInstall because the layout guide is not a view + return constraint; + } else { + // iOS 6 fallback + return [self autoPinEdge:ALEdgeBottom toEdge:ALEdgeBottom ofView:viewController.view withOffset:inset relation:relation]; + } +} + +#endif /* TARGET_OS_IPHONE */ + + +#pragma mark Internal Methods + +/** + Adds the given constraint to this view after applying the global state to the constraint. + NOTE: This method is compatible with all versions of iOS, and should be used for older versions before the active + property on NSLayoutConstraint was introduced. + + This method should be the only one that calls the UIView/NSView addConstraint: method directly. + + @param constraint The constraint to set the global priority on and then add to this view. + */ +- (void)al_addConstraint:(NSLayoutConstraint *)constraint +{ + [NSLayoutConstraint al_applyGlobalStateToConstraint:constraint]; + if ([NSLayoutConstraint al_preventAutomaticConstraintInstallation]) { + [[NSLayoutConstraint al_currentArrayOfCreatedConstraints] addObject:constraint]; + } else { + [self addConstraint:constraint]; + } +} + +/** + Returns the common superview for this view and the given other view. + Raises an exception if this view and the other view do not share a common superview. + + @return The common superview for the two views. + */ +- (ALView *)al_commonSuperviewWithView:(ALView *)otherView +{ + ALView *commonSuperview = nil; + ALView *startView = self; + do { +#if TARGET_OS_IPHONE + if ([otherView isDescendantOfView:startView]) { + commonSuperview = startView; + } +#else + if ([otherView isDescendantOf:startView]) { + commonSuperview = startView; + } +#endif /* TARGET_OS_IPHONE */ + startView = startView.superview; + } while (startView && !commonSuperview); + NSAssert(commonSuperview, @"Can't constrain two views that do not share a common superview. Make sure that both views have been added into the same view hierarchy."); + return commonSuperview; +} + +/** + Aligns this view to another view with an alignment attribute. + + @param attribute The attribute to use to align the two views. + @param otherView The other view to align to. + @param axis The axis along which the views are distributed, used to validate the alignment attribute. + @return The constraint added. + */ +- (NSLayoutConstraint *)al_alignAttribute:(ALAttribute)attribute toView:(ALView *)otherView forAxis:(ALAxis)axis +{ + NSLayoutConstraint *constraint = nil; + switch (attribute) { + case ALAttributeVertical: + NSAssert(axis == ALAxisVertical, @"Cannot align views that are distributed horizontally with ALAttributeVertical."); + constraint = [self autoAlignAxis:ALAxisVertical toSameAxisOfView:otherView]; + break; + case ALAttributeHorizontal: + NSAssert(axis != ALAxisVertical, @"Cannot align views that are distributed vertically with ALAttributeHorizontal."); + constraint = [self autoAlignAxis:ALAxisHorizontal toSameAxisOfView:otherView]; + break; + case ALAttributeBaseline: // same value as ALAttributeLastBaseline + NSAssert(axis != ALAxisVertical, @"Cannot align views that are distributed vertically with ALAttributeBaseline."); + constraint = [self autoAlignAxis:ALAxisBaseline toSameAxisOfView:otherView]; + break; +#if __PureLayout_MinBaseSDK_iOS_8_0 + case ALAttributeFirstBaseline: + NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALAttributeFirstBaseline is only supported on iOS 8.0 or higher."); + NSAssert(axis != ALAxisVertical, @"Cannot align views that are distributed vertically with ALAttributeFirstBaseline."); + constraint = [self autoAlignAxis:ALAxisFirstBaseline toSameAxisOfView:otherView]; + break; +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ + case ALAttributeTop: + NSAssert(axis != ALAxisVertical, @"Cannot align views that are distributed vertically with ALAttributeTop."); + constraint = [self autoPinEdge:ALEdgeTop toEdge:ALEdgeTop ofView:otherView]; + break; + case ALAttributeLeft: + NSAssert(axis == ALAxisVertical, @"Cannot align views that are distributed horizontally with ALAttributeLeft."); + constraint = [self autoPinEdge:ALEdgeLeft toEdge:ALEdgeLeft ofView:otherView]; + break; + case ALAttributeBottom: + NSAssert(axis != ALAxisVertical, @"Cannot align views that are distributed vertically with ALAttributeBottom."); + constraint = [self autoPinEdge:ALEdgeBottom toEdge:ALEdgeBottom ofView:otherView]; + break; + case ALAttributeRight: + NSAssert(axis == ALAxisVertical, @"Cannot align views that are distributed horizontally with ALAttributeRight."); + constraint = [self autoPinEdge:ALEdgeRight toEdge:ALEdgeRight ofView:otherView]; + break; + case ALAttributeLeading: + NSAssert(axis == ALAxisVertical, @"Cannot align views that are distributed horizontally with ALAttributeLeading."); + constraint = [self autoPinEdge:ALEdgeLeading toEdge:ALEdgeLeading ofView:otherView]; + break; + case ALAttributeTrailing: + NSAssert(axis == ALAxisVertical, @"Cannot align views that are distributed horizontally with ALAttributeTrailing."); + constraint = [self autoPinEdge:ALEdgeTrailing toEdge:ALEdgeTrailing ofView:otherView]; + break; + + // All of the below attributes are invalid as alignment options. Listing them explicitly (even though they just fall through to the default case) to avoid an incomplete switch statement warning from the compiler. + case ALAttributeWidth: + case ALAttributeHeight: +#if __PureLayout_MinBaseSDK_iOS_8_0 + case ALAttributeMarginLeft: + case ALAttributeMarginRight: + case ALAttributeMarginTop: + case ALAttributeMarginBottom: + case ALAttributeMarginLeading: + case ALAttributeMarginTrailing: + case ALAttributeMarginAxisVertical: + case ALAttributeMarginAxisHorizontal: +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ + default: + NSAssert(nil, @"Unsupported attribute for alignment."); + break; + } + return constraint; +} + +@end diff --git a/Pods/PureLayout/PureLayout/PureLayout/NSArray+PureLayout.h b/Pods/PureLayout/PureLayout/PureLayout/NSArray+PureLayout.h new file mode 100755 index 0000000..3815dc4 --- /dev/null +++ b/Pods/PureLayout/PureLayout/PureLayout/NSArray+PureLayout.h @@ -0,0 +1,115 @@ +// +// NSArray+PureLayout.h +// https://github.com/smileyborg/PureLayout +// +// Copyright (c) 2012 Richard Turton +// Copyright (c) 2013-2015 Tyler Fox +// +// This code is distributed under the terms and conditions of the MIT license. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +// + +#import "PureLayoutDefines.h" + + +__PL_ASSUME_NONNULL_BEGIN + +#pragma mark NSArray+PureLayout + +/** + A category on NSArray that provides a simple yet powerful interface to: + - Manage an array of Auto Layout constraints + - Apply constraints to an array of views + */ +@interface NSArray (PureLayout) + + +#pragma mark Array of Constraints + +/** Activates the constraints in this array. */ +- (void)autoInstallConstraints; + +/** Deactivates the constraints in this array. */ +- (void)autoRemoveConstraints; + +#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 + +/** Sets the string as the identifier for the constraints in this array. Available in iOS 7.0 and OS X 10.9 and later. */ +- (instancetype)autoIdentifyConstraints:(NSString *)identifier; + +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */ + + +#pragma mark Array of Views + +/** Aligns views in this array to one another along a given edge. */ +- (__NSArray_of(NSLayoutConstraint *) *)autoAlignViewsToEdge:(ALEdge)edge; + +/** Aligns views in this array to one another along a given axis. */ +- (__NSArray_of(NSLayoutConstraint *) *)autoAlignViewsToAxis:(ALAxis)axis; + +/** Matches a given dimension of all the views in this array. */ +- (__NSArray_of(NSLayoutConstraint *) *)autoMatchViewsDimension:(ALDimension)dimension; + +/** Sets the given dimension of all the views in this array to a given size. */ +- (__NSArray_of(NSLayoutConstraint *) *)autoSetViewsDimension:(ALDimension)dimension toSize:(CGFloat)size; + +/** Sets all of the views in this array to a given size. */ +- (__NSArray_of(NSLayoutConstraint *) *)autoSetViewsDimensionsToSize:(CGSize)size; + + +/** Distributes the views in this array equally along the selected axis in their superview. + Views will be the same size (variable) in the dimension along the axis and will have spacing (fixed) between them. */ +- (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis + alignedTo:(ALAttribute)alignment + withFixedSpacing:(CGFloat)spacing; + +/** Distributes the views in this array equally along the selected axis in their superview. + Views will be the same size (variable) in the dimension along the axis and will have spacing (fixed) between them, with optional insets from the first and last views to their superview. */ +- (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis + alignedTo:(ALAttribute)alignment + withFixedSpacing:(CGFloat)spacing + insetSpacing:(BOOL)shouldSpaceInsets; + +/** Distributes the views in this array equally along the selected axis in their superview. + Views will have spacing (fixed) between them, with optional insets from the first and last views to their superview, and optionally constrained to the same size in the dimension along the axis. */ +- (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis + alignedTo:(ALAttribute)alignment + withFixedSpacing:(CGFloat)spacing + insetSpacing:(BOOL)shouldSpaceInsets + matchedSizes:(BOOL)shouldMatchSizes; + + +/** Distributes the views in this array equally along the selected axis in their superview. + Views will be the same size (fixed) in the dimension along the axis and will have spacing (variable) between them. */ +- (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis + alignedTo:(ALAttribute)alignment + withFixedSize:(CGFloat)size; + +/** Distributes the views in this array equally along the selected axis in their superview. + Views will be the same size (fixed) in the dimension along the axis and will have spacing (variable) between them, with optional insets from the first and last views to their superview. */ +- (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis + alignedTo:(ALAttribute)alignment + withFixedSize:(CGFloat)size + insetSpacing:(BOOL)shouldSpaceInsets; + +@end + +__PL_ASSUME_NONNULL_END diff --git a/Pods/PureLayout/PureLayout/PureLayout/NSArray+PureLayout.m b/Pods/PureLayout/PureLayout/PureLayout/NSArray+PureLayout.m new file mode 100755 index 0000000..bea0789 --- /dev/null +++ b/Pods/PureLayout/PureLayout/PureLayout/NSArray+PureLayout.m @@ -0,0 +1,505 @@ +// +// NSArray+PureLayout.m +// https://github.com/smileyborg/PureLayout +// +// Copyright (c) 2012 Richard Turton +// Copyright (c) 2013-2015 Tyler Fox +// +// This code is distributed under the terms and conditions of the MIT license. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +// + +#import "NSArray+PureLayout.h" +#import "ALView+PureLayout.h" +#import "NSLayoutConstraint+PureLayout.h" +#import "PureLayout+Internal.h" + + +#pragma mark - NSArray+PureLayout + +@implementation NSArray (PureLayout) + + +#pragma mark Array of Constraints + +/** + Activates the constraints in this array. + */ +- (void)autoInstallConstraints +{ +#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 + if ([NSLayoutConstraint respondsToSelector:@selector(activateConstraints:)]) { + for (id object in self) { + if ([object isKindOfClass:[NSLayoutConstraint class]]) { + [NSLayoutConstraint al_applyGlobalStateToConstraint:object]; + } + } + if ([NSLayoutConstraint al_preventAutomaticConstraintInstallation]) { + [[NSLayoutConstraint al_currentArrayOfCreatedConstraints] addObjectsFromArray:self]; + } else { + [NSLayoutConstraint activateConstraints:self]; + } + return; + } +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */ + + for (id object in self) { + if ([object isKindOfClass:[NSLayoutConstraint class]]) { + [((NSLayoutConstraint *)object) autoInstall]; + } + } +} + +/** + Deactivates the constraints in this array. + */ +- (void)autoRemoveConstraints +{ +#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 + if ([NSLayoutConstraint respondsToSelector:@selector(deactivateConstraints:)]) { + [NSLayoutConstraint deactivateConstraints:self]; + return; + } +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */ + + for (id object in self) { + if ([object isKindOfClass:[NSLayoutConstraint class]]) { + [((NSLayoutConstraint *)object) autoRemove]; + } + } +} + +#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 + +/** + Sets the string as the identifier for the constraints in this array. Available in iOS 7.0 and OS X 10.9 and later. + The identifier will be printed along with each constraint's description. + This is helpful to document the constraints' purpose and aid in debugging. + + @param identifier A string used to identify the constraints in this array. + @return This array. + */ +- (instancetype)autoIdentifyConstraints:(NSString *)identifier +{ + for (id object in self) { + if ([object isKindOfClass:[NSLayoutConstraint class]]) { + [((NSLayoutConstraint *)object) autoIdentify:identifier]; + } + } + return self; +} + +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */ + + +#pragma mark Array of Views + +/** + Aligns views in this array to one another along a given edge. + Note: This array must contain at least 2 views, and all views must share a common superview. + + @param edge The edge to which the views will be aligned. + @return An array of constraints added. + */ +- (__NSArray_of(NSLayoutConstraint *) *)autoAlignViewsToEdge:(ALEdge)edge +{ + NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views."); + __NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new]; + ALView *previousView = nil; + for (id object in self) { + if ([object isKindOfClass:[ALView class]]) { + ALView *view = (ALView *)object; + view.translatesAutoresizingMaskIntoConstraints = NO; + if (previousView) { + [constraints addObject:[view autoPinEdge:edge toEdge:edge ofView:previousView]]; + } + previousView = view; + } + } + return constraints; +} + +/** + Aligns views in this array to one another along a given axis. + Note: This array must contain at least 2 views, and all views must share a common superview. + + @param axis The axis to which the views will be aligned. + @return An array of constraints added. + */ +- (__NSArray_of(NSLayoutConstraint *) *)autoAlignViewsToAxis:(ALAxis)axis +{ + NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views."); + __NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new]; + ALView *previousView = nil; + for (id object in self) { + if ([object isKindOfClass:[ALView class]]) { + ALView *view = (ALView *)object; + view.translatesAutoresizingMaskIntoConstraints = NO; + if (previousView) { + [constraints addObject:[view autoAlignAxis:axis toSameAxisOfView:previousView]]; + } + previousView = view; + } + } + return constraints; +} + +/** + Matches a given dimension of all the views in this array. + Note: This array must contain at least 2 views, and all views must share a common superview. + + @param dimension The dimension to match for all of the views. + @return An array of constraints added. + */ +- (__NSArray_of(NSLayoutConstraint *) *)autoMatchViewsDimension:(ALDimension)dimension +{ + NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views."); + __NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new]; + ALView *previousView = nil; + for (id object in self) { + if ([object isKindOfClass:[ALView class]]) { + ALView *view = (ALView *)object; + view.translatesAutoresizingMaskIntoConstraints = NO; + if (previousView) { + [constraints addObject:[view autoMatchDimension:dimension toDimension:dimension ofView:previousView]]; + } + previousView = view; + } + } + return constraints; +} + +/** + Sets the given dimension of all the views in this array to a given size. + Note: This array must contain at least 1 view. + + @param dimension The dimension of each of the views to set. + @param size The size to set the given dimension of each view to. + @return An array of constraints added. + */ +- (__NSArray_of(NSLayoutConstraint *) *)autoSetViewsDimension:(ALDimension)dimension toSize:(CGFloat)size +{ + NSAssert([self al_containsMinimumNumberOfViews:1], @"This array must contain at least 1 view."); + __NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new]; + for (id object in self) { + if ([object isKindOfClass:[ALView class]]) { + ALView *view = (ALView *)object; + view.translatesAutoresizingMaskIntoConstraints = NO; + [constraints addObject:[view autoSetDimension:dimension toSize:size]]; + } + } + return constraints; +} + +/** + Sets all of the views in this array to a given size. + Note: This array must contain at least 1 view. + + @param size The size to set each view's dimensions to. + @return An array of constraints added. + */ +- (__NSArray_of(NSLayoutConstraint *) *)autoSetViewsDimensionsToSize:(CGSize)size +{ + __NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new]; + [constraints addObjectsFromArray:[self autoSetViewsDimension:ALDimensionWidth toSize:size.width]]; + [constraints addObjectsFromArray:[self autoSetViewsDimension:ALDimensionHeight toSize:size.height]]; + return constraints; +} + + +/** + Distributes the views in this array equally along the selected axis in their superview. + Views will be the same size (variable) in the dimension along the axis and will have spacing (fixed) between them, + including from the first and last views to their superview. + + @param axis The axis along which to distribute the views. + @param alignment The attribute to use to align all the views to one another. + @param spacing The fixed amount of spacing between each view. + @return An array of constraints added. + */ +- (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis + alignedTo:(ALAttribute)alignment + withFixedSpacing:(CGFloat)spacing +{ + return [self autoDistributeViewsAlongAxis:axis + alignedTo:alignment + withFixedSpacing:spacing + insetSpacing:YES]; +} + +/** + Distributes the views in this array equally along the selected axis in their superview. + Views will be the same size (variable) in the dimension along the axis and will have spacing (fixed) between them. + The first and last views can optionally be inset from their superview by the same amount of spacing as between views. + + @param axis The axis along which to distribute the views. + @param alignment The attribute to use to align all the views to one another. + @param spacing The fixed amount of spacing between each view. + @param shouldSpaceInsets Whether the first and last views should be equally inset from their superview. + @return An array of constraints added. + */ +- (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis + alignedTo:(ALAttribute)alignment + withFixedSpacing:(CGFloat)spacing + insetSpacing:(BOOL)shouldSpaceInsets +{ + return [self autoDistributeViewsAlongAxis:axis + alignedTo:alignment + withFixedSpacing:spacing + insetSpacing:shouldSpaceInsets + matchedSizes:YES]; +} + +/** + Distributes the views in this array equally along the selected axis in their superview. + Views will have fixed spacing between them, and can optionally be constrained to the same size in the dimension along the axis. + The first and last views can optionally be inset from their superview by the same amount of spacing as between views. + + @param axis The axis along which to distribute the views. + @param alignment The attribute to use to align all the views to one another. + @param spacing The fixed amount of spacing between each view. + @param shouldSpaceInsets Whether the first and last views should be equally inset from their superview. + @param shouldMatchSizes Whether all views will be constrained to be the same size in the dimension along the axis. + NOTE: All views must specify an intrinsic content size if passing NO, otherwise the layout will be ambiguous! + @return An array of constraints added. + */ +- (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis + alignedTo:(ALAttribute)alignment + withFixedSpacing:(CGFloat)spacing + insetSpacing:(BOOL)shouldSpaceInsets + matchedSizes:(BOOL)shouldMatchSizes +{ + NSAssert([self al_containsMinimumNumberOfViews:1], @"This array must contain at least 1 view to distribute."); + ALDimension matchedDimension; + ALEdge firstEdge, lastEdge; + switch (axis) { + case ALAxisHorizontal: + case ALAxisBaseline: // same value as ALAxisLastBaseline +#if __PureLayout_MinBaseSDK_iOS_8_0 + case ALAxisFirstBaseline: +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ + matchedDimension = ALDimensionWidth; + firstEdge = ALEdgeLeading; + lastEdge = ALEdgeTrailing; + break; + case ALAxisVertical: + matchedDimension = ALDimensionHeight; + firstEdge = ALEdgeTop; + lastEdge = ALEdgeBottom; + break; + default: + NSAssert(nil, @"Not a valid ALAxis."); + return nil; + } + CGFloat leadingSpacing = shouldSpaceInsets ? spacing : 0.0; + CGFloat trailingSpacing = shouldSpaceInsets ? spacing : 0.0; + + __NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new]; + ALView *previousView = nil; + for (id object in self) { + if ([object isKindOfClass:[ALView class]]) { + ALView *view = (ALView *)object; + view.translatesAutoresizingMaskIntoConstraints = NO; + if (previousView) { + // Second, Third, ... View + [constraints addObject:[view autoPinEdge:firstEdge toEdge:lastEdge ofView:previousView withOffset:spacing]]; + if (shouldMatchSizes) { + [constraints addObject:[view autoMatchDimension:matchedDimension toDimension:matchedDimension ofView:previousView]]; + } + [constraints addObject:[view al_alignAttribute:alignment toView:previousView forAxis:axis]]; + } + else { + // First view + [constraints addObject:[view autoPinEdgeToSuperviewEdge:firstEdge withInset:leadingSpacing]]; + } + previousView = view; + } + } + if (previousView) { + // Last View + [constraints addObject:[previousView autoPinEdgeToSuperviewEdge:lastEdge withInset:trailingSpacing]]; + } + return constraints; +} + +/** + Distributes the views in this array equally along the selected axis in their superview. + Views will be the same size (fixed) in the dimension along the axis and will have spacing (variable) between them, + including from the first and last views to their superview. + + @param axis The axis along which to distribute the views. + @param alignment The attribute to use to align all the views to one another. + @param size The fixed size of each view in the dimension along the given axis. + @return An array of constraints added. + */ +- (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis + alignedTo:(ALAttribute)alignment + withFixedSize:(CGFloat)size +{ + return [self autoDistributeViewsAlongAxis:axis + alignedTo:alignment + withFixedSize:size + insetSpacing:YES]; +} + +/** + Distributes the views in this array equally along the selected axis in their superview. + Views will be the same size (fixed) in the dimension along the axis and will have spacing (variable) between them. + The first and last views can optionally be inset from their superview by the same amount of spacing as between views. + + @param axis The axis along which to distribute the views. + @param alignment The attribute to use to align all the views to one another. + @param size The fixed size of each view in the dimension along the given axis. + @param shouldSpaceInsets Whether the first and last views should be equally inset from their superview. + @return An array of constraints added. + */ +- (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis + alignedTo:(ALAttribute)alignment + withFixedSize:(CGFloat)size + insetSpacing:(BOOL)shouldSpaceInsets +{ + NSAssert([self al_containsMinimumNumberOfViews:1], @"This array must contain at least 1 view to distribute."); + ALDimension fixedDimension; + NSLayoutAttribute attribute; + switch (axis) { + case ALAxisHorizontal: + case ALAxisBaseline: // same value as ALAxisLastBaseline +#if __PureLayout_MinBaseSDK_iOS_8_0 + case ALAxisFirstBaseline: +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ + fixedDimension = ALDimensionWidth; + attribute = NSLayoutAttributeCenterX; + break; + case ALAxisVertical: + fixedDimension = ALDimensionHeight; + attribute = NSLayoutAttributeCenterY; + break; + default: + NSAssert(nil, @"Not a valid ALAxis."); + return nil; + } +#if TARGET_OS_IPHONE +# if !defined(PURELAYOUT_APP_EXTENSIONS) + BOOL isRightToLeftLayout = [[UIApplication sharedApplication] userInterfaceLayoutDirection] == UIUserInterfaceLayoutDirectionRightToLeft; +# else + // App Extensions may not access -[UIApplication sharedApplication]; fall back to checking the bundle's preferred localization character direction + BOOL isRightToLeftLayout = [NSLocale characterDirectionForLanguage:[[NSBundle mainBundle] preferredLocalizations][0]] == NSLocaleLanguageDirectionRightToLeft; +# endif /* !defined(PURELAYOUT_APP_EXTENSIONS) */ +#else + BOOL isRightToLeftLayout = [[NSApplication sharedApplication] userInterfaceLayoutDirection] == NSUserInterfaceLayoutDirectionRightToLeft; +#endif /* TARGET_OS_IPHONE */ + BOOL shouldFlipOrder = isRightToLeftLayout && (axis != ALAxisVertical); // imitate the effect of leading/trailing when distributing horizontally + + __NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new]; + __NSArray_of(ALView *) *views = [self al_copyViewsOnly]; + NSUInteger numberOfViews = [views count]; + ALView *commonSuperview = [views al_commonSuperviewOfViews]; + ALView *previousView = nil; + for (NSUInteger i = 0; i < numberOfViews; i++) { + ALView *view = shouldFlipOrder ? views[numberOfViews - i - 1] : views[i]; + view.translatesAutoresizingMaskIntoConstraints = NO; + [constraints addObject:[view autoSetDimension:fixedDimension toSize:size]]; + CGFloat multiplier, constant; + if (shouldSpaceInsets) { + multiplier = (i * 2.0 + 2.0) / (numberOfViews + 1.0); + constant = (multiplier - 1.0) * size / 2.0; + } else { + multiplier = (i * 2.0) / (numberOfViews - 1.0); + constant = (-multiplier + 1.0) * size / 2.0; + } + // If the multiplier is very close to 0, set it to the minimum value to prevent the second item in the constraint from being lost. Filed as rdar://19168380 + if (fabs(multiplier) < kMULTIPLIER_MIN_VALUE) { + multiplier = kMULTIPLIER_MIN_VALUE; + } + NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:view attribute:attribute relatedBy:NSLayoutRelationEqual toItem:commonSuperview attribute:attribute multiplier:multiplier constant:constant]; + [constraint autoInstall]; + [constraints addObject:constraint]; + if (previousView) { + [constraints addObject:[view al_alignAttribute:alignment toView:previousView forAxis:axis]]; + } + previousView = view; + } + return constraints; +} + +#pragma mark Internal Helper Methods + +/** + Returns the common superview for the views in this array. If there is only one view in the array, its superview will be returned. + Raises an exception if the views in this array do not share a common superview. + + @return The common superview for the views in this array. + */ +- (ALView *)al_commonSuperviewOfViews +{ + ALView *commonSuperview = nil; + ALView *previousView = nil; + for (id object in self) { + if ([object isKindOfClass:[ALView class]]) { + ALView *view = (ALView *)object; + if (previousView) { + commonSuperview = [view al_commonSuperviewWithView:commonSuperview]; + } else { + commonSuperview = view.superview; + } + previousView = view; + } + } + NSAssert(commonSuperview, @"Can't constrain views that do not share a common superview. Make sure that all the views in this array have been added into the same view hierarchy."); + return commonSuperview; +} + +/** + Determines whether this array contains a minimum number of views. + + @param minimumNumberOfViews The minimum number of views to check for. + @return YES if this array contains at least the minimum number of views, NO otherwise. + */ +- (BOOL)al_containsMinimumNumberOfViews:(NSUInteger)minimumNumberOfViews +{ + NSUInteger numberOfViews = 0; + for (id object in self) { + if ([object isKindOfClass:[ALView class]]) { + numberOfViews++; + if (numberOfViews >= minimumNumberOfViews) { + return YES; + } + } + } + return numberOfViews >= minimumNumberOfViews; +} + +/** + Creates a copy of this array containing only the view objects in it. + + @return A new array containing only the views that are in this array. + */ +- (__NSArray_of(ALView *) *)al_copyViewsOnly +{ + __NSMutableArray_of(ALView *) *viewsOnlyArray = [NSMutableArray arrayWithCapacity:[self count]]; + for (id object in self) { + if ([object isKindOfClass:[ALView class]]) { + [viewsOnlyArray addObject:object]; + } + } + return viewsOnlyArray; +} + +@end diff --git a/Pods/PureLayout/PureLayout/PureLayout/NSLayoutConstraint+PureLayout.h b/Pods/PureLayout/PureLayout/PureLayout/NSLayoutConstraint+PureLayout.h new file mode 100755 index 0000000..01a1dc6 --- /dev/null +++ b/Pods/PureLayout/PureLayout/PureLayout/NSLayoutConstraint+PureLayout.h @@ -0,0 +1,84 @@ +// +// NSLayoutConstraint+PureLayout.h +// https://github.com/smileyborg/PureLayout +// +// Copyright (c) 2013-2015 Tyler Fox +// +// This code is distributed under the terms and conditions of the MIT license. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +// + +#import "PureLayoutDefines.h" + + +__PL_ASSUME_NONNULL_BEGIN + +#pragma mark NSLayoutConstraint+PureLayout + +/** + A category on NSLayoutConstraint that allows constraints to be easily installed & removed. + */ +@interface NSLayoutConstraint (PureLayout) + + +#pragma mark Batch Constraint Creation + +/** Creates all of the constraints in the block, then installs (activates) them all at once. + All constraints created from calls to the PureLayout API in the block are returned in a single array. + This may be more efficient than installing (activating) each constraint one-by-one. */ ++ (__NSArray_of(NSLayoutConstraint *) *)autoCreateAndInstallConstraints:(ALConstraintsBlock)block; + +/** Creates all of the constraints in the block but prevents them from being automatically installed (activated). + All constraints created from calls to the PureLayout API in the block are returned in a single array. */ ++ (__NSArray_of(NSLayoutConstraint *) *)autoCreateConstraintsWithoutInstalling:(ALConstraintsBlock)block; + + +#pragma mark Set Priority For Constraints + +/** Sets the constraint priority to the given value for all constraints created using the PureLayout API within the given constraints block. + NOTE: This method will have no effect (and will NOT set the priority) on constraints created or added without using the PureLayout API! */ ++ (void)autoSetPriority:(ALLayoutPriority)priority forConstraints:(ALConstraintsBlock)block; + + +#pragma mark Identify Constraints + +#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 + +/** Sets the identifier for all constraints created using the PureLayout API within the given constraints block. + NOTE: This method will have no effect (and will NOT set the identifier) on constraints created or added without using the PureLayout API! */ ++ (void)autoSetIdentifier:(NSString *)identifier forConstraints:(ALConstraintsBlock)block; + +/** Sets the string as the identifier for this constraint. Available in iOS 7.0 and OS X 10.9 and later. */ +- (instancetype)autoIdentify:(NSString *)identifier; + +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */ + + +#pragma mark Install & Remove Constraints + +/** Activates the the constraint. */ +- (void)autoInstall; + +/** Deactivates the constraint. */ +- (void)autoRemove; + +@end + +__PL_ASSUME_NONNULL_END diff --git a/Pods/PureLayout/PureLayout/PureLayout/NSLayoutConstraint+PureLayout.m b/Pods/PureLayout/PureLayout/PureLayout/NSLayoutConstraint+PureLayout.m new file mode 100755 index 0000000..6c3cef2 --- /dev/null +++ b/Pods/PureLayout/PureLayout/PureLayout/NSLayoutConstraint+PureLayout.m @@ -0,0 +1,552 @@ +// +// NSLayoutConstraint+PureLayout.m +// https://github.com/smileyborg/PureLayout +// +// Copyright (c) 2013-2015 Tyler Fox +// +// This code is distributed under the terms and conditions of the MIT license. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +// + +#import "NSLayoutConstraint+PureLayout.h" +#import "ALView+PureLayout.h" +#import "NSArray+PureLayout.h" +#import "PureLayout+Internal.h" + + +#pragma mark - NSLayoutConstraint+PureLayout + +@implementation NSLayoutConstraint (PureLayout) + +#pragma mark Batch Constraint Creation + +/** + A global variable that stores a stack of arrays of constraints created without being immediately installed. + When executing a constraints block passed into the +[autoCreateConstraintsWithoutInstalling:] method, a new + mutable array is pushed onto this stack, and all constraints created with PureLayout in the block are added + to this array. When the block finishes executing, the array is popped off this stack. Automatic constraint + installation is prevented if this stack contains at least 1 array. + + NOTE: Access to this variable is not synchronized (and should only be done on the main thread). + */ +static __NSMutableArray_of(__NSMutableArray_of(NSLayoutConstraint *) *) *_al_arraysOfCreatedConstraints = nil; + +/** + A global variable that is set to YES when installing a batch of constraints collected from a call to +[autoCreateAndInstallConstraints]. + When this flag is YES, constraints are installed immediately without checking for or adding to the +[al_currentArrayOfCreatedConstraints]. + This is necessary to properly handle nested calls to +[autoCreateAndInstallConstraints], where calls whose block contains other call(s) + should not return constraints from within the blocks of nested call(s). + */ +static BOOL _al_isInstallingCreatedConstraints = NO; + +/** + Accessor for the global state that stores arrays of constraints created without being installed. + */ ++ (__NSMutableArray_of(__NSMutableArray_of(NSLayoutConstraint *) *) *)al_arraysOfCreatedConstraints +{ + NSAssert([NSThread isMainThread], @"PureLayout is not thread safe, and must be used exclusively from the main thread."); + if (!_al_arraysOfCreatedConstraints) { + _al_arraysOfCreatedConstraints = [NSMutableArray new]; + } + return _al_arraysOfCreatedConstraints; +} + +/** + Accessor for the current mutable array of constraints created without being immediately installed. + */ ++ (__NSMutableArray_of(NSLayoutConstraint *) *)al_currentArrayOfCreatedConstraints +{ + return [[self al_arraysOfCreatedConstraints] lastObject]; +} + +/** + Accessor for the global state that determines whether automatic constraint installation should be prevented. + */ ++ (BOOL)al_preventAutomaticConstraintInstallation +{ + return (_al_isInstallingCreatedConstraints == NO) && ([[self al_arraysOfCreatedConstraints] count] > 0); +} + +/** + Creates all of the constraints in the block, then installs (activates) them all at once. + All constraints created from calls to the PureLayout API in the block are returned in a single array. + This may be more efficient than installing (activating) each constraint one-by-one. + + Note: calls to this method may be nested. The constraints returned from a call will NOT include constraints + created in nested calls; constraints are only returned from the inner-most call they are created within. + + @param block A block of method calls to the PureLayout API that create constraints. + @return An array of the constraints that were created from calls to the PureLayout API inside the block. + */ ++ (__NSArray_of(NSLayoutConstraint *) *)autoCreateAndInstallConstraints:(ALConstraintsBlock)block +{ + NSArray *createdConstraints = [self autoCreateConstraintsWithoutInstalling:block]; + _al_isInstallingCreatedConstraints = YES; + [createdConstraints autoInstallConstraints]; + _al_isInstallingCreatedConstraints = NO; + return createdConstraints; +} + +/** + Creates all of the constraints in the block but prevents them from being automatically installed (activated). + All constraints created from calls to the PureLayout API in the block are returned in a single array. + + Note: calls to this method may be nested. The constraints returned from a call will NOT include constraints + created in nested calls; constraints are only returned from the inner-most call they are created within. + + @param block A block of method calls to the PureLayout API that create constraints. + @return An array of the constraints that were created from calls to the PureLayout API inside the block. + */ ++ (__NSArray_of(NSLayoutConstraint *) *)autoCreateConstraintsWithoutInstalling:(ALConstraintsBlock)block +{ + NSAssert(block, @"The constraints block cannot be nil."); + NSArray *createdConstraints = nil; + if (block) { + [[self al_arraysOfCreatedConstraints] addObject:[NSMutableArray new]]; + block(); + createdConstraints = [self al_currentArrayOfCreatedConstraints]; + [[self al_arraysOfCreatedConstraints] removeLastObject]; + } + return createdConstraints; +} + + +#pragma mark Set Priority For Constraints + +/** + A global variable that stores a stack of layout priorities to set on constraints. + When executing a constraints block passed into the +[autoSetPriority:forConstraints:] method, the priority for + that call is pushed onto this stack, and when the block finishes executing, that priority is popped off this + stack. If this stack contains at least 1 priority, the priority at the top of the stack will be set for all + constraints created by this library (even if automatic constraint installation is being prevented). + NOTE: Access to this variable is not synchronized (and should only be done on the main thread). + */ +static __NSMutableArray_of(NSNumber *) *_al_globalConstraintPriorities = nil; + +/** + Accessor for the global stack of layout priorities. + */ ++ (__NSMutableArray_of(NSNumber *) *)al_globalConstraintPriorities +{ + NSAssert([NSThread isMainThread], @"PureLayout is not thread safe, and must be used exclusively from the main thread."); + if (!_al_globalConstraintPriorities) { + _al_globalConstraintPriorities = [NSMutableArray new]; + } + return _al_globalConstraintPriorities; +} + +/** + Returns the current layout priority to use for constraints. + When executing a constraints block passed into +[autoSetPriority:forConstraints:], this will return + the priority for the current block. Otherwise, the default Required priority is returned. + */ ++ (ALLayoutPriority)al_currentGlobalConstraintPriority +{ + __NSMutableArray_of(NSNumber *) *globalConstraintPriorities = [self al_globalConstraintPriorities]; + if ([globalConstraintPriorities count] == 0) { + return ALLayoutPriorityRequired; + } + return [[globalConstraintPriorities lastObject] floatValue]; +} + +/** + Accessor for the global state that determines if we're currently in the scope of a priority constraints block. + */ ++ (BOOL)al_isExecutingPriorityConstraintsBlock +{ + return [[self al_globalConstraintPriorities] count] > 0; +} + +/** + Sets the constraint priority to the given value for all constraints created using the PureLayout + API within the given constraints block. + + NOTE: This method will have no effect (and will NOT set the priority) on constraints created or added + without using the PureLayout API! + + @param priority The layout priority to be set on all constraints created in the constraints block. + @param block A block of method calls to the PureLayout API that create and install constraints. + */ ++ (void)autoSetPriority:(ALLayoutPriority)priority forConstraints:(ALConstraintsBlock)block +{ + NSAssert(block, @"The constraints block cannot be nil."); + if (block) { + [[self al_globalConstraintPriorities] addObject:@(priority)]; + block(); + [[self al_globalConstraintPriorities] removeLastObject]; + } +} + + +#pragma mark Identify Constraints + +#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 + +/** + A global variable that stores a stack of identifier strings to set on constraints. + When executing a constraints block passed into the +[autoSetIdentifier:forConstraints:] method, the identifier for + that call is pushed onto this stack, and when the block finishes executing, that identifier is popped off this + stack. If this stack contains at least 1 identifier, the identifier at the top of the stack will be set for all + constraints created by this library (even if automatic constraint installation is being prevented). + NOTE: Access to this variable is not synchronized (and should only be done on the main thread). + */ +static __NSMutableArray_of(NSString *) *_al_globalConstraintIdentifiers = nil; + +/** + Accessor for the global state of constraint identifiers. + */ ++ (__NSMutableArray_of(NSString *) *)al_globalConstraintIdentifiers +{ + NSAssert([NSThread isMainThread], @"PureLayout is not thread safe, and must be used exclusively from the main thread."); + if (!_al_globalConstraintIdentifiers) { + _al_globalConstraintIdentifiers = [NSMutableArray new]; + } + return _al_globalConstraintIdentifiers; +} + +/** + Returns the current identifier string to use for constraints. + When executing a constraints block passed into +[autoSetIdentifier:forConstraints:], this will return + the identifier for the current block. Otherwise, nil is returned. + */ ++ (NSString *)al_currentGlobalConstraintIdentifier +{ + __NSMutableArray_of(NSString *) *globalConstraintIdentifiers = [self al_globalConstraintIdentifiers]; + if ([globalConstraintIdentifiers count] == 0) { + return nil; + } + return [globalConstraintIdentifiers lastObject]; +} + +/** + Sets the identifier for all constraints created using the PureLayout API within the given constraints block. + + NOTE: This method will have no effect (and will NOT set the identifier) on constraints created or added + without using the PureLayout API! + + @param identifier A string used to identify all constraints created in the constraints block. + @param block A block of method calls to the PureLayout API that create and install constraints. + */ ++ (void)autoSetIdentifier:(NSString *)identifier forConstraints:(ALConstraintsBlock)block +{ + NSAssert(block, @"The constraints block cannot be nil."); + NSAssert(identifier, @"The identifier string cannot be nil."); + if (block) { + if (identifier) { + [[self al_globalConstraintIdentifiers] addObject:identifier]; + } + block(); + if (identifier) { + [[self al_globalConstraintIdentifiers] removeLastObject]; + } + } +} + +/** + Sets the string as the identifier for this constraint. Available in iOS 7.0 and OS X 10.9 and later. + The identifier will be printed along with the constraint's description. + This is helpful to document a constraint's purpose and aid in debugging. + + @param identifier A string used to identify this constraint. + @return This constraint. + */ +- (instancetype)autoIdentify:(NSString *)identifier +{ + if ([self respondsToSelector:@selector(setIdentifier:)]) { + self.identifier = identifier; + } + return self; +} + +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */ + + +#pragma mark Install & Remove Constraints + +/** + Activates the constraint. + */ +- (void)autoInstall +{ +#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 + if ([self respondsToSelector:@selector(setActive:)]) { + [NSLayoutConstraint al_applyGlobalStateToConstraint:self]; + if ([NSLayoutConstraint al_preventAutomaticConstraintInstallation]) { + [[NSLayoutConstraint al_currentArrayOfCreatedConstraints] addObject:self]; + } else { + self.active = YES; + } + return; + } +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */ + + NSAssert(self.firstItem || self.secondItem, @"Can't install a constraint with nil firstItem and secondItem."); + if (self.firstItem) { + if (self.secondItem) { + NSAssert([self.firstItem isKindOfClass:[ALView class]] && [self.secondItem isKindOfClass:[ALView class]], @"Can only automatically install a constraint if both items are views."); + ALView *commonSuperview = [self.firstItem al_commonSuperviewWithView:self.secondItem]; + [commonSuperview al_addConstraint:self]; + } else { + NSAssert([self.firstItem isKindOfClass:[ALView class]], @"Can only automatically install a constraint if the item is a view."); + [self.firstItem al_addConstraint:self]; + } + } else { + NSAssert([self.secondItem isKindOfClass:[ALView class]], @"Can only automatically install a constraint if the item is a view."); + [self.secondItem al_addConstraint:self]; + } +} + +/** + Deactivates the constraint. + */ +- (void)autoRemove +{ +#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 + if ([self respondsToSelector:@selector(setActive:)]) { + self.active = NO; + return; + } +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */ + + if (self.secondItem) { + ALView *commonSuperview = [self.firstItem al_commonSuperviewWithView:self.secondItem]; + while (commonSuperview) { + if ([commonSuperview.constraints containsObject:self]) { + [commonSuperview removeConstraint:self]; + return; + } + commonSuperview = commonSuperview.superview; + } + } + else { + [self.firstItem removeConstraint:self]; + return; + } + NSAssert(nil, @"Failed to remove constraint: %@", self); +} + + +#pragma mark Internal Methods + +/** + Applies the global constraint priority and identifier to the given constraint. + This should be done before installing all constraints. + + @param constraint The constraint to set the global priority and identifier on. + */ ++ (void)al_applyGlobalStateToConstraint:(NSLayoutConstraint *)constraint +{ + if ([NSLayoutConstraint al_isExecutingPriorityConstraintsBlock]) { + constraint.priority = [NSLayoutConstraint al_currentGlobalConstraintPriority]; + } +#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 + NSString *globalConstraintIdentifier = [NSLayoutConstraint al_currentGlobalConstraintIdentifier]; + if (globalConstraintIdentifier) { + [constraint autoIdentify:globalConstraintIdentifier]; + } +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */ +} + +/** + Returns the corresponding NSLayoutAttribute for the given ALAttribute. + + @return The layout attribute for the given ALAttribute. + */ ++ (NSLayoutAttribute)al_layoutAttributeForAttribute:(ALAttribute)attribute +{ + NSLayoutAttribute layoutAttribute = NSLayoutAttributeNotAnAttribute; + switch (attribute) { + case ALEdgeLeft: + layoutAttribute = NSLayoutAttributeLeft; + break; + case ALEdgeRight: + layoutAttribute = NSLayoutAttributeRight; + break; + case ALEdgeTop: + layoutAttribute = NSLayoutAttributeTop; + break; + case ALEdgeBottom: + layoutAttribute = NSLayoutAttributeBottom; + break; + case ALEdgeLeading: + layoutAttribute = NSLayoutAttributeLeading; + break; + case ALEdgeTrailing: + layoutAttribute = NSLayoutAttributeTrailing; + break; + case ALDimensionWidth: + layoutAttribute = NSLayoutAttributeWidth; + break; + case ALDimensionHeight: + layoutAttribute = NSLayoutAttributeHeight; + break; + case ALAxisVertical: + layoutAttribute = NSLayoutAttributeCenterX; + break; + case ALAxisHorizontal: + layoutAttribute = NSLayoutAttributeCenterY; + break; + case ALAxisBaseline: // same value as ALAxisLastBaseline + layoutAttribute = NSLayoutAttributeBaseline; + break; +#if __PureLayout_MinBaseSDK_iOS_8_0 + case ALAxisFirstBaseline: + NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALAxisFirstBaseline is only supported on iOS 8.0 or higher."); + layoutAttribute = NSLayoutAttributeFirstBaseline; + break; + case ALMarginLeft: + NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALEdgeLeftMargin is only supported on iOS 8.0 or higher."); + layoutAttribute = NSLayoutAttributeLeftMargin; + break; + case ALMarginRight: + NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALEdgeRightMargin is only supported on iOS 8.0 or higher."); + layoutAttribute = NSLayoutAttributeRightMargin; + break; + case ALMarginTop: + NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALEdgeTopMargin is only supported on iOS 8.0 or higher."); + layoutAttribute = NSLayoutAttributeTopMargin; + break; + case ALMarginBottom: + NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALEdgeBottomMargin is only supported on iOS 8.0 or higher."); + layoutAttribute = NSLayoutAttributeBottomMargin; + break; + case ALMarginLeading: + NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALEdgeLeadingMargin is only supported on iOS 8.0 or higher."); + layoutAttribute = NSLayoutAttributeLeadingMargin; + break; + case ALMarginTrailing: + NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALEdgeTrailingMargin is only supported on iOS 8.0 or higher."); + layoutAttribute = NSLayoutAttributeTrailingMargin; + break; + case ALMarginAxisVertical: + NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALAxisVerticalMargin is only supported on iOS 8.0 or higher."); + layoutAttribute = NSLayoutAttributeCenterXWithinMargins; + break; + case ALMarginAxisHorizontal: + NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALAxisHorizontalMargin is only supported on iOS 8.0 or higher."); + layoutAttribute = NSLayoutAttributeCenterYWithinMargins; + break; +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ + default: + NSAssert(nil, @"Not a valid ALAttribute."); + break; + } + return layoutAttribute; +} + +/** + Returns the corresponding ALLayoutConstraintAxis for the given ALAxis. + + @return The constraint axis for the given axis. + */ ++ (ALLayoutConstraintAxis)al_constraintAxisForAxis:(ALAxis)axis +{ + ALLayoutConstraintAxis constraintAxis; + switch (axis) { + case ALAxisVertical: + constraintAxis = ALLayoutConstraintAxisVertical; + break; + case ALAxisHorizontal: + case ALAxisBaseline: // same value as ALAxisLastBaseline +#if __PureLayout_MinBaseSDK_iOS_8_0 + case ALAxisFirstBaseline: +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ + constraintAxis = ALLayoutConstraintAxisHorizontal; + break; + default: + NSAssert(nil, @"Not a valid ALAxis."); + constraintAxis = ALLayoutConstraintAxisHorizontal; // default to an arbitrary value to satisfy the compiler + break; + } + return constraintAxis; +} + +#if __PureLayout_MinBaseSDK_iOS_8_0 + +/** + Returns the corresponding margin for the given edge. + + @param edge The edge to convert to the corresponding margin. + @return The margin for the given edge. + */ ++ (ALMargin)al_marginForEdge:(ALEdge)edge +{ + NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"Margin attributes are only supported on iOS 8.0 or higher."); + ALMargin margin; + switch (edge) { + case ALEdgeLeft: + margin = ALMarginLeft; + break; + case ALEdgeRight: + margin = ALMarginRight; + break; + case ALEdgeTop: + margin = ALMarginTop; + break; + case ALEdgeBottom: + margin = ALMarginBottom; + break; + case ALEdgeLeading: + margin = ALMarginLeading; + break; + case ALEdgeTrailing: + margin = ALMarginTrailing; + break; + default: + NSAssert(nil, @"Not a valid ALEdge."); + margin = ALMarginLeft; // default to an arbitrary value to satisfy the compiler + break; + } + return margin; +} + +/** + Returns the corresponding margin axis for the given axis. + + @param axis The axis to convert to the corresponding margin axis. + @return The margin axis for the given axis. + */ ++ (ALMarginAxis)al_marginAxisForAxis:(ALAxis)axis +{ + NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"Margin attributes are only supported on iOS 8.0 or higher."); + ALMarginAxis marginAxis; + switch (axis) { + case ALAxisVertical: + marginAxis = ALMarginAxisVertical; + break; + case ALAxisHorizontal: + marginAxis = ALMarginAxisHorizontal; + break; + case ALAxisBaseline: + case ALAxisFirstBaseline: + NSAssert(nil, @"The baseline axis attributes do not have corresponding margin axis attributes."); + marginAxis = ALMarginAxisVertical; // default to an arbitrary value to satisfy the compiler + break; + default: + NSAssert(nil, @"Not a valid ALAxis."); + marginAxis = ALMarginAxisVertical; // default to an arbitrary value to satisfy the compiler + break; + } + return marginAxis; +} + +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ + +@end diff --git a/Pods/PureLayout/PureLayout/PureLayout/PureLayout+Internal.h b/Pods/PureLayout/PureLayout/PureLayout/PureLayout+Internal.h new file mode 100644 index 0000000..48335d4 --- /dev/null +++ b/Pods/PureLayout/PureLayout/PureLayout/PureLayout+Internal.h @@ -0,0 +1,87 @@ +// +// PureLayout+Internal.h +// https://github.com/smileyborg/PureLayout +// +// Copyright (c) 2014-2015 Tyler Fox +// +// This code is distributed under the terms and conditions of the MIT license. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +// + +#import "PureLayoutDefines.h" + + +// Using generics with NSMutableArray is so common in the internal implementation of PureLayout that it gets a dedicated preprocessor macro for better readability. +#define __NSMutableArray_of(type) __PL_GENERICS(NSMutableArray, type) + +__PL_ASSUME_NONNULL_BEGIN + +/** A constant that represents the smallest valid positive value for the multiplier of a constraint, + since a value of 0 will cause the second item to be lost in the internal auto layout engine. */ +static const CGFloat kMULTIPLIER_MIN_VALUE = (CGFloat)0.00001; // very small floating point numbers (e.g. CGFLOAT_MIN) can cause problems + + +/** + A category that exposes the internal (private) helper methods of the ALView+PureLayout category. + */ +@interface ALView (PureLayoutInternal) + +- (void)al_addConstraint:(NSLayoutConstraint *)constraint; +- (ALView *)al_commonSuperviewWithView:(ALView *)otherView; +- (NSLayoutConstraint *)al_alignAttribute:(ALAttribute)attribute toView:(ALView *)otherView forAxis:(ALAxis)axis; + +@end + + +/** + A category that exposes the internal (private) helper methods of the NSArray+PureLayout category. + */ +@interface NSArray (PureLayoutInternal) + +- (ALView *)al_commonSuperviewOfViews; +- (BOOL)al_containsMinimumNumberOfViews:(NSUInteger)minimumNumberOfViews; +- (__NSArray_of(ALView *) *)al_copyViewsOnly; + +@end + + +/** + A category that exposes the internal (private) helper methods of the NSLayoutConstraint+PureLayout category. + */ +@interface NSLayoutConstraint (PureLayoutInternal) + ++ (BOOL)al_preventAutomaticConstraintInstallation; ++ (__NSMutableArray_of(NSLayoutConstraint *) *)al_currentArrayOfCreatedConstraints; ++ (BOOL)al_isExecutingPriorityConstraintsBlock; ++ (ALLayoutPriority)al_currentGlobalConstraintPriority; +#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 ++ (NSString *)al_currentGlobalConstraintIdentifier; +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */ ++ (void)al_applyGlobalStateToConstraint:(NSLayoutConstraint *)constraint; ++ (NSLayoutAttribute)al_layoutAttributeForAttribute:(ALAttribute)attribute; ++ (ALLayoutConstraintAxis)al_constraintAxisForAxis:(ALAxis)axis; +#if __PureLayout_MinBaseSDK_iOS_8_0 ++ (ALMargin)al_marginForEdge:(ALEdge)edge; ++ (ALMarginAxis)al_marginAxisForAxis:(ALAxis)axis; +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ + +@end + +__PL_ASSUME_NONNULL_END diff --git a/Pods/PureLayout/PureLayout/PureLayout/PureLayout.h b/Pods/PureLayout/PureLayout/PureLayout/PureLayout.h new file mode 100755 index 0000000..ed9b416 --- /dev/null +++ b/Pods/PureLayout/PureLayout/PureLayout/PureLayout.h @@ -0,0 +1,43 @@ +// +// PureLayout.h +// https://github.com/smileyborg/PureLayout +// +// Copyright (c) 2014-2015 Tyler Fox +// +// This code is distributed under the terms and conditions of the MIT license. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +// + +#ifndef PureLayout_h +#define PureLayout_h + +#import + +//! Project version number for PureLayout. +FOUNDATION_EXPORT double PureLayoutVersionNumber; + +//! Project version string for PureLayout. +FOUNDATION_EXPORT const unsigned char PureLayoutVersionString[]; + +#import "ALView+PureLayout.h" +#import "NSArray+PureLayout.h" +#import "NSLayoutConstraint+PureLayout.h" + +#endif /* PureLayout_h */ diff --git a/Pods/PureLayout/PureLayout/PureLayout/PureLayoutDefines.h b/Pods/PureLayout/PureLayout/PureLayout/PureLayoutDefines.h new file mode 100755 index 0000000..46f4ffe --- /dev/null +++ b/Pods/PureLayout/PureLayout/PureLayout/PureLayoutDefines.h @@ -0,0 +1,224 @@ +// +// PureLayoutDefines.h +// https://github.com/smileyborg/PureLayout +// +// Copyright (c) 2014-2015 Tyler Fox +// +// This code is distributed under the terms and conditions of the MIT license. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +// + +#ifndef PureLayoutDefines_h +#define PureLayoutDefines_h + +#import + +// Define some preprocessor macros to check for a minimum Base SDK. These are used to prevent compile-time errors in older versions of Xcode. +#define __PureLayout_MinBaseSDK_iOS_8_0 (TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1) +#define __PureLayout_MinBaseSDK_OSX_10_10 (!TARGET_OS_IPHONE && __MAC_OS_X_VERSION_MAX_ALLOWED > __MAC_10_9) + +// Define some preprocessor macros to check for a minimum System Version. These are used to prevent runtime crashes on older versions of iOS/OS X. +#define __PureLayout_MinSysVer_iOS_7_0 (TARGET_OS_IPHONE && floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) +#define __PureLayout_MinSysVer_iOS_8_0 (TARGET_OS_IPHONE && floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_7_1) +#define __PureLayout_MinSysVer_OSX_10_9 (!TARGET_OS_IPHONE && floor(NSFoundationVersionNumber) > NSFoundationVersionNumber10_8_4) + +// Define some preprocessor macros that allow nullability annotations to be adopted in a backwards-compatible manner. +#if __has_feature(nullability) +# define __PL_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN +# define __PL_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END +#else +# define __PL_ASSUME_NONNULL_BEGIN +# define __PL_ASSUME_NONNULL_END +#endif + +// Define some preprocessor macros that allow generics to be adopted in a backwards-compatible manner. +#if __has_feature(objc_generics) +# define __PL_GENERICS(class, ...) class<__VA_ARGS__> +#else +# define __PL_GENERICS(class, ...) class +#endif + +// Using generics with NSArray is so common in PureLayout that it gets a dedicated preprocessor macro for better readability. +#define __NSArray_of(type) __PL_GENERICS(NSArray, type) + +// Define generic AL-prefixed macros for the types/constants/etc that have slight naming variations across iOS and OS X, which allows the same code to be platform-independent. +#if TARGET_OS_IPHONE +# import +# define ALView UIView +# define ALEdgeInsets UIEdgeInsets +# define ALEdgeInsetsZero UIEdgeInsetsZero +# define ALEdgeInsetsMake UIEdgeInsetsMake +# define ALLayoutConstraintAxis UILayoutConstraintAxis +# define ALLayoutConstraintOrientation ALLayoutConstraintAxis +# define ALLayoutConstraintAxisHorizontal UILayoutConstraintAxisHorizontal +# define ALLayoutConstraintAxisVertical UILayoutConstraintAxisVertical +# define ALLayoutConstraintOrientationHorizontal ALLayoutConstraintAxisHorizontal +# define ALLayoutConstraintOrientationVertical ALLayoutConstraintAxisVertical +# define ALLayoutPriority UILayoutPriority +# define ALLayoutPriorityRequired UILayoutPriorityRequired +# define ALLayoutPriorityDefaultHigh UILayoutPriorityDefaultHigh +# define ALLayoutPriorityDefaultLow UILayoutPriorityDefaultLow +# define ALLayoutPriorityFittingSizeLevel UILayoutPriorityFittingSizeLevel +# define ALLayoutPriorityFittingSizeCompression ALLayoutPriorityFittingSizeLevel +#else +# import +# define ALView NSView +# define ALEdgeInsets NSEdgeInsets +# define ALEdgeInsetsZero NSEdgeInsetsMake(0, 0, 0, 0) +# define ALEdgeInsetsMake NSEdgeInsetsMake +# define ALLayoutConstraintOrientation NSLayoutConstraintOrientation +# define ALLayoutConstraintAxis ALLayoutConstraintOrientation +# define ALLayoutConstraintOrientationHorizontal NSLayoutConstraintOrientationHorizontal +# define ALLayoutConstraintOrientationVertical NSLayoutConstraintOrientationVertical +# define ALLayoutConstraintAxisHorizontal ALLayoutConstraintOrientationHorizontal +# define ALLayoutConstraintAxisVertical ALLayoutConstraintOrientationVertical +# define ALLayoutPriority NSLayoutPriority +# define ALLayoutPriorityRequired NSLayoutPriorityRequired +# define ALLayoutPriorityDefaultHigh NSLayoutPriorityDefaultHigh +# define ALLayoutPriorityDefaultLow NSLayoutPriorityDefaultLow +# define ALLayoutPriorityFittingSizeCompression NSLayoutPriorityFittingSizeCompression +# define ALLayoutPriorityFittingSizeLevel ALLayoutPriorityFittingSizeCompression +#endif /* TARGET_OS_IPHONE */ + + +#pragma mark PureLayout Attributes + +/** Constants that represent edges of a view. */ +typedef NS_ENUM(NSInteger, ALEdge) { + /** The left edge of the view. */ + ALEdgeLeft = NSLayoutAttributeLeft, + /** The right edge of the view. */ + ALEdgeRight = NSLayoutAttributeRight, + /** The top edge of the view. */ + ALEdgeTop = NSLayoutAttributeTop, + /** The bottom edge of the view. */ + ALEdgeBottom = NSLayoutAttributeBottom, + /** The leading edge of the view (left edge for left-to-right languages like English, right edge for right-to-left languages like Arabic). */ + ALEdgeLeading = NSLayoutAttributeLeading, + /** The trailing edge of the view (right edge for left-to-right languages like English, left edge for right-to-left languages like Arabic). */ + ALEdgeTrailing = NSLayoutAttributeTrailing +}; + +/** Constants that represent dimensions of a view. */ +typedef NS_ENUM(NSInteger, ALDimension) { + /** The width of the view. */ + ALDimensionWidth = NSLayoutAttributeWidth, + /** The height of the view. */ + ALDimensionHeight = NSLayoutAttributeHeight +}; + +/** Constants that represent axes of a view. */ +typedef NS_ENUM(NSInteger, ALAxis) { + /** A vertical line equidistant from the view's left and right edges. */ + ALAxisVertical = NSLayoutAttributeCenterX, + /** A horizontal line equidistant from the view's top and bottom edges. */ + ALAxisHorizontal = NSLayoutAttributeCenterY, + + /** A horizontal line at the baseline of the last line of text in the view. (For views that do not draw text, will be equivalent to ALEdgeBottom.) Same as ALAxisLastBaseline. */ + ALAxisBaseline = NSLayoutAttributeBaseline, + /** A horizontal line at the baseline of the last line of text in the view. (For views that do not draw text, will be equivalent to ALEdgeBottom.) */ + ALAxisLastBaseline = ALAxisBaseline, + #if __PureLayout_MinBaseSDK_iOS_8_0 + /** A horizontal line at the baseline of the first line of text in a view. (For views that do not draw text, will be equivalent to ALEdgeTop.) Available in iOS 8.0 and later. */ + ALAxisFirstBaseline = NSLayoutAttributeFirstBaseline + #endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ +}; + +#if __PureLayout_MinBaseSDK_iOS_8_0 + +/** Constants that represent layout margins of a view. Available in iOS 8.0 and later. */ +typedef NS_ENUM(NSInteger, ALMargin) { + /** The left margin of the view, based on the view's layoutMargins left inset. */ + ALMarginLeft = NSLayoutAttributeLeftMargin, + /** The right margin of the view, based on the view's layoutMargins right inset. */ + ALMarginRight = NSLayoutAttributeRightMargin, + /** The top margin of the view, based on the view's layoutMargins top inset. */ + ALMarginTop = NSLayoutAttributeTopMargin, + /** The bottom margin of the view, based on the view's layoutMargins bottom inset. */ + ALMarginBottom = NSLayoutAttributeBottomMargin, + /** The leading margin of the view, based on the view's layoutMargins left/right (depending on language direction) inset. */ + ALMarginLeading = NSLayoutAttributeLeadingMargin, + /** The trailing margin of the view, based on the view's layoutMargins left/right (depending on language direction) inset. */ + ALMarginTrailing = NSLayoutAttributeTrailingMargin +}; + +/** Constants that represent axes of the layout margins of a view. Available in iOS 8.0 and later. */ +typedef NS_ENUM(NSInteger, ALMarginAxis) { + /** A vertical line equidistant from the view's left and right margins. */ + ALMarginAxisVertical = NSLayoutAttributeCenterXWithinMargins, + /** A horizontal line equidistant from the view's top and bottom margins. */ + ALMarginAxisHorizontal = NSLayoutAttributeCenterYWithinMargins +}; + +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ + +/** An attribute of a view that can be used in auto layout constraints. These constants are identical to the more specific enum types: + ALEdge, ALAxis, ALDimension, ALMargin, ALMarginAxis. It is safe to cast a more specific enum type to the ALAttribute type. */ +typedef NS_ENUM(NSInteger, ALAttribute) { + /** The left edge of the view. */ + ALAttributeLeft = ALEdgeLeft, + /** The right edge of the view. */ + ALAttributeRight = ALEdgeRight, + /** The top edge of the view. */ + ALAttributeTop = ALEdgeTop, + /** The bottom edge of the view. */ + ALAttributeBottom = ALEdgeBottom, + /** The leading edge of the view (left edge for left-to-right languages like English, right edge for right-to-left languages like Arabic). */ + ALAttributeLeading = ALEdgeLeading, + /** The trailing edge of the view (right edge for left-to-right languages like English, left edge for right-to-left languages like Arabic). */ + ALAttributeTrailing = ALEdgeTrailing, + /** The width of the view. */ + ALAttributeWidth = ALDimensionWidth, + /** The height of the view. */ + ALAttributeHeight = ALDimensionHeight, + /** A vertical line equidistant from the view's left and right edges. */ + ALAttributeVertical = ALAxisVertical, + /** A horizontal line equidistant from the view's top and bottom edges. */ + ALAttributeHorizontal = ALAxisHorizontal, + /** A horizontal line at the baseline of the last line of text in the view. (For views that do not draw text, will be equivalent to ALEdgeBottom.) Same as ALAxisLastBaseline. */ + ALAttributeBaseline = ALAxisBaseline, + /** A horizontal line at the baseline of the last line of text in the view. (For views that do not draw text, will be equivalent to ALEdgeBottom.) */ + ALAttributeLastBaseline = ALAxisLastBaseline, +#if __PureLayout_MinBaseSDK_iOS_8_0 + /** A horizontal line at the baseline of the first line of text in a view. (For views that do not draw text, will be equivalent to ALEdgeTop.) Available in iOS 8.0 and later. */ + ALAttributeFirstBaseline = ALAxisFirstBaseline, + /** The left margin of the view, based on the view's layoutMargins left inset. */ + ALAttributeMarginLeft = ALMarginLeft, + /** The right margin of the view, based on the view's layoutMargins right inset. */ + ALAttributeMarginRight = ALMarginRight, + /** The top margin of the view, based on the view's layoutMargins top inset. */ + ALAttributeMarginTop = ALMarginTop, + /** The bottom margin of the view, based on the view's layoutMargins bottom inset. */ + ALAttributeMarginBottom = ALMarginBottom, + /** The leading margin of the view, based on the view's layoutMargins left/right (depending on language direction) inset. */ + ALAttributeMarginLeading = ALMarginLeading, + /** The trailing margin of the view, based on the view's layoutMargins left/right (depending on language direction) inset. */ + ALAttributeMarginTrailing = ALMarginTrailing, + /** A vertical line equidistant from the view's left and right margins. */ + ALAttributeMarginAxisVertical = ALMarginAxisVertical, + /** A horizontal line equidistant from the view's top and bottom margins. */ + ALAttributeMarginAxisHorizontal = ALMarginAxisHorizontal +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ +}; + +/** A block containing method calls to the PureLayout API. Takes no arguments and has no return value. */ +typedef void(^ALConstraintsBlock)(void); + +#endif /* PureLayoutDefines_h */ diff --git a/Pods/PureLayout/README.md b/Pods/PureLayout/README.md new file mode 100644 index 0000000..64a8611 --- /dev/null +++ b/Pods/PureLayout/README.md @@ -0,0 +1,219 @@ +# [![PureLayout](https://github.com/smileyborg/PureLayout/blob/master/Images/PureLayout.png?raw=true)](#) +[![Build Status](http://img.shields.io/travis/smileyborg/PureLayout.svg?style=flat)](https://travis-ci.org/smileyborg/PureLayout) [![Test Coverage](http://img.shields.io/coveralls/smileyborg/PureLayout.svg?style=flat)](https://coveralls.io/r/smileyborg/PureLayout) [![Version](http://img.shields.io/cocoapods/v/PureLayout.svg?style=flat)](http://cocoapods.org/?q=PureLayout) [![Platform](http://img.shields.io/cocoapods/p/PureLayout.svg?style=flat)](http://cocoapods.org/?q=PureLayout) [![License](http://img.shields.io/cocoapods/l/PureLayout.svg?style=flat)](LICENSE) + +The ultimate API for iOS & OS X Auto Layout — impressively simple, immensely powerful. PureLayout extends `UIView`/`NSView`, `NSArray`, and `NSLayoutConstraint` with a comprehensive Auto Layout API that is modeled after Apple's own frameworks. PureLayout is a cross-platform Objective-C library that works (and looks!) great in Swift. It is fully backwards-compatible with all versions of iOS and OS X that support Auto Layout. + +Writing Auto Layout code from scratch isn't easy. PureLayout provides a fully capable and developer-friendly interface for Auto Layout. It is designed for clarity and simplicity, and takes inspiration from the AutoLayout UI options available in Interface Builder while delivering far more flexibility. The API is also highly efficient, as it adds only a thin layer of third party code and is engineered for maximum performance. + +### Table of Contents + 1. [Setup](#setup) + 1. [API Cheat Sheet](#api-cheat-sheet) + 1. [Usage](#usage) + * [Sample Code](#sample-code-swift) + * [Example Apps](#example-apps) + 1. [PureLayout vs. the rest](#purelayout-vs-the-rest) + 1. [Problems, Suggestions, Pull Requests?](#problems-suggestions-pull-requests) + +## Setup +### Compatibility +The current release of PureLayout supports all versions of iOS and OS X since the introduction of Auto Layout on each platform, in both Swift and Objective-C, with a single codebase! + +* Xcode + * Language Support: **Swift** *(any version)*, **Objective-C** + * Fully Compatible With: **Xcode 7.0** + * Minimum Supported Version: **Xcode 5.0** +* iOS + * Fully Compatible With: **iOS 9.0** + * Minimum Deployment Target: **iOS 6.0** +* OS X + * Fully Compatible With: **OS X 10.11** + * Minimum Deployment Target: **OS X 10.7** + +### Using [CocoaPods](http://cocoapods.org) +1. Add the pod `PureLayout` to your [Podfile](http://guides.cocoapods.org/using/the-podfile.html). + + ```ruby + pod 'PureLayout' + ``` + +1. Run `pod install` from Terminal, then open your app's `.xcworkspace` file to launch Xcode. +1. Import the `PureLayout.h` umbrella header. + * With `use_frameworks!` in your Podfile + * Swift: `import PureLayout` + * Objective-C: `#import ` (or with Modules enabled: `@import PureLayout;`) + * Without `use_frameworks!` in your Podfile + * Swift: Add `#import "PureLayout.h"` to your bridging header. + * Objective-C: `#import "PureLayout.h"` + +That's it - now go write some beautiful Auto Layout code! + +### Using [Carthage](https://github.com/Carthage/Carthage) +1. Add the `smileyborg/PureLayout` project to your [Cartfile](https://github.com/Carthage/Carthage/blob/master/Documentation/Artifacts.md#cartfile). + + ```ogdl + github "smileyborg/PureLayout" + ``` + +1. Run `carthage update`, then follow the [additional steps required](https://github.com/Carthage/Carthage#adding-frameworks-to-an-application) to add the framework into your project. +1. Import the PureLayout framework/module. + * Swift: `import PureLayout` + * Objective-C: `#import ` (or with Modules enabled: `@import PureLayout;`) + +That's it - now go write some beautiful Auto Layout code! + +### Manually from GitHub +1. Download the source files in the [PureLayout subdirectory](PureLayout/PureLayout). +1. Add the source files to your Xcode project. +1. Import the `PureLayout.h` header. + * Swift: Add `#import "PureLayout.h"` to your bridging header. + * Objective-C: `#import "PureLayout.h"` + +That's it - now go write some beautiful Auto Layout code! + +### App Extensions +To use PureLayout in an App Extension, you need to do a bit of extra configuration to prevent usage of unavailable APIs. [Click here](https://github.com/smileyborg/PureLayout/wiki/App-Extensions) for more info. + +### Releases +Releases are tagged in the git commit history using [semantic versioning](http://semver.org). Check out the [releases and release notes](https://github.com/smileyborg/PureLayout/releases) for each version. + +## API Cheat Sheet +This is just a handy overview of the core API methods. Explore the [header files](PureLayout/PureLayout) for the full API, and find the complete documentation above the implementation of each method in the corresponding .m file. A couple of notes: + +* All of the public API methods are namespaced with the prefix `auto...`, which also makes it easy for Xcode to autocomplete as you type. +* Methods that create constraints also automatically install (activate) the constraint(s), then return the new constraint(s) for you to optionally store for later adjustment or removal. +* Many methods below also have a variant which includes a `relation:` parameter to make the constraint an inequality. + +### Attributes + +PureLayout defines view attributes that are used to create auto layout constraints. Here is an [illustration of the most common attributes](Images/PureLayout-CommonAttributes.png). + +There are 5 specific attribute types, which are used throughout most of the API: + +* `ALEdge` +* `ALDimension` +* `ALAxis` +* `ALMargin` *available in iOS 8.0 and higher only* +* `ALMarginAxis` *available in iOS 8.0 and higher only* + +Additionally, there is one generic attribute type, `ALAttribute`, which is effectively a union of all the specific types. You can think of this as the "supertype" of all of the specific attribute types, which means that it is always safe to cast a specific type to the generic `ALAttribute` type. (Note that the reverse is not true -- casting a generic ALAttribute to a specific attribute type is unsafe!) + +### [`UIView`/`NSView`](PureLayout/PureLayout/ALView%2BPureLayout.h) +``` +- autoSetContent(CompressionResistance|Hugging)PriorityForAxis: +- autoCenterInSuperview(Margins): // Margins variant iOS 8.0+ only +- autoAlignAxisToSuperview(Margin)Axis: // Margin variant iOS 8.0+ only +- autoPinEdgeToSuperview(Edge:|Margin:)(withInset:) // Margin variant iOS 8.0+ only +- autoPinEdgesToSuperview(Edges|Margins)(WithInsets:)(excludingEdge:) // Margins variant iOS 8.0+ only +- autoPinEdge:toEdge:ofView:(withOffset:) +- autoAlignAxis:toSameAxisOfView:(withOffset:|withMultiplier:) +- autoMatchDimension:toDimension:ofView:(withOffset:|withMultiplier:) +- autoSetDimension(s)ToSize: +- autoConstrainAttribute:toAttribute:ofView:(withOffset:|withMultiplier:) +- autoPinTo(Top|Bottom)LayoutGuideOfViewController:withInset: // iOS only +``` + +### [`NSArray`](PureLayout/PureLayout/NSArray%2BPureLayout.h) +``` +// Arrays of Constraints +- autoInstallConstraints +- autoRemoveConstraints +- autoIdentifyConstraints: // iOS 7.0+, OS X 10.9+ only + +// Arrays of Views +- autoAlignViewsToEdge: +- autoAlignViewsToAxis: +- autoMatchViewsDimension: +- autoSetViewsDimension:toSize: +- autoSetViewsDimensionsToSize: +- autoDistributeViewsAlongAxis:alignedTo:withFixedSpacing:(insetSpacing:)(matchedSizes:) +- autoDistributeViewsAlongAxis:alignedTo:withFixedSize:(insetSpacing:) +``` + +### [`NSLayoutConstraint`](PureLayout/PureLayout/NSLayoutConstraint%2BPureLayout.h) +``` ++ autoCreateAndInstallConstraints: ++ autoCreateConstraintsWithoutInstalling: ++ autoSetPriority:forConstraints: ++ autoSetIdentifier:forConstraints: // iOS 7.0+, OS X 10.9+ only +- autoIdentify: // iOS 7.0+, OS X 10.9+ only +- autoInstall +- autoRemove +``` + +## Usage +### Sample Code (Swift) +PureLayout dramatically simplifies writing Auto Layout code. Let's take a quick look at some examples, using PureLayout from Swift. + +Here's a constraint between two views created (and automatically activated) using PureLayout: + +```swift +view1.autoPinEdge(.Top, toEdge: .Bottom, ofView: view2) +``` + +Without PureLayout, here's the equivalent code you'd have to write using Apple's Foundation API directly: + +```swift +NSLayoutConstraint(item: view1, attribute: .Top, relatedBy: .Equal, toItem: view2, attribute: .Bottom, multiplier: 1.0, constant: 0.0).active = true +``` + +Many APIs of PureLayout create multiple constraints for you under the hood, letting you write highly readable layout code: + +```swift +// 2 constraints created & activated in one line! +logoImageView.autoCenterInSuperview() + +// 4 constraints created & activated in one line! +textContentView.autoPinEdgesToSuperviewEdgesWithInsets(UIEdgeInsets(top: 20.0, left: 5.0, bottom: 10.0, right: 5.0)) +``` + +PureLayout always returns the constraints it creates so you have full control: + +```swift +let constraint = skinnyView.autoMatchDimension(.Height, toDimension: .Width, ofView: tallView) +``` + +PureLayout supports all Auto Layout features including inequalities, priorities, layout margins, identifiers, and much more. It's a comprehensive, developer-friendly way to use Auto Layout. + +Check out the example apps below for many more demos of PureLayout in use. + +### Example Apps +Open the project included in the repository (requires Xcode 6 or higher). It contains [iOS](PureLayout/Example-iOS) (`Example-iOS` scheme) and [OS X](PureLayout/Example-Mac) (`Example-Mac` scheme) demos of the library being used in various scenarios. The demos in the iOS example app make a great introductory tutorial to PureLayout -- run each demo, review the code used to implement it, then practice by making some changes of your own to the demo code. + +Each demo in the iOS example app has a Swift and Objective-C version. **To compile & run the Swift demos, you must use Xcode 7.0 or higher (Swift 2.0) and choose the `Example-iOS-Xcode7` scheme.** When you run the example app, you can easily switch between using the Swift and Objective-C versions of the demos. To see the constraints in action while running the iOS demos, try using different device simulators, rotating the device to different orientations, as well as toggling the taller in-call status bar in the iOS Simulator. + +On OS X, while running the app, press any key to cycle through the demos. You can resize the window to see the constraints in action. + +### Tips and Tricks +Check out some [Tips and Tricks](https://github.com/smileyborg/PureLayout/wiki/Tips-and-Tricks) to keep in mind when using the API. + +## PureLayout vs. the rest +There are quite a few different ways to implement Auto Layout. Here is a quick overview of the available options: + +* Apple [NSLayoutConstraint SDK API](https://developer.apple.com/library/ios/documentation/AppKit/Reference/NSLayoutConstraint_Class/index.html#//apple_ref/occ/clm/NSLayoutConstraint/constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:) + * Pros: Raw power + * Cons: Extremely verbose; tedious to write; difficult to read +* Apple [Visual Format Language](https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/VisualFormatLanguage/VisualFormatLanguage.html) + * Pros: Concise; convenient + * Cons: Doesn't support some use cases; lacks compile-time checking and safety; must learn syntax; hard to debug +* Apple Interface Builder + * Pros: Visual; interactive; provides compile-time layout checking + * Cons: Difficult for complex layouts; cannot dynamically set constraints at runtime; encourages hardcoded magic numbers; not always WYSIWYG +* Apple [NSLayoutAnchor SDK API](https://developer.apple.com/library/prerelease/ios/documentation/AppKit/Reference/NSLayoutAnchor_ClassReference/index.html) + * Pros: Clean, readable, and type-safe API for creating individual constraints + * Cons: Only available in iOS 9.0 and OS X 10.11 and higher; requires manually activating each constraint; no API for creating multiple constraints at once +* **PureLayout** + * Pros: Compatible with Objective-C and Swift codebases; consistent with Cocoa API style; cross-platform API and implementation shared across iOS and OS X; fully backwards-compatible to iOS 6 & OS X 10.7; easy to use; type-safe; efficient + * Cons: Not the most concise expression of layout code +* High-level Auto Layout Libraries/DSLs ([Cartography](https://github.com/robb/Cartography), [SnapKit](https://github.com/SnapKit/SnapKit), [KeepLayout](https://github.com/iMartinKiss/KeepLayout)) + * Pros: Very clean, concise, and convenient + * Cons: Unique API style is foreign to Apple's APIs; mixed compatibility with Objective-C & Swift; greater dependency on third party code + +PureLayout takes a balanced approach to Auto Layout that makes it well suited for any project. + +## Problems, Suggestions, Pull Requests? +Please open a [new Issue here](https://github.com/smileyborg/PureLayout/issues/new) if you run into a problem specific to PureLayout, have a feature request, or want to share a comment. Note that general Auto Layout questions should be asked on [Stack Overflow](http://stackoverflow.com). + +Pull requests are encouraged and greatly appreciated! Please try to maintain consistency with the existing code style. If you're considering taking on significant changes or additions to the project, please communicate in advance by opening a new Issue. This allows everyone to get onboard with upcoming changes, ensures that changes align with the project's design philosophy, and avoids duplicated work. + +## Meta +Designed & maintained by Tyler Fox ([@smileyborg](https://twitter.com/smileyborg)). Distributed with the MIT license. diff --git a/Pods/Target Support Files/Pods/Info.plist b/Pods/Target Support Files/Pods/Info.plist new file mode 100644 index 0000000..6974542 --- /dev/null +++ b/Pods/Target Support Files/Pods/Info.plist @@ -0,0 +1,26 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIdentifier + org.cocoapods.${PRODUCT_NAME:rfc1034identifier} + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ${PRODUCT_NAME} + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0.0 + CFBundleSignature + ???? + CFBundleVersion + ${CURRENT_PROJECT_VERSION} + NSPrincipalClass + + + diff --git a/Pods/Target Support Files/Pods/Pods-acknowledgements.markdown b/Pods/Target Support Files/Pods/Pods-acknowledgements.markdown new file mode 100644 index 0000000..3d79025 --- /dev/null +++ b/Pods/Target Support Files/Pods/Pods-acknowledgements.markdown @@ -0,0 +1,16 @@ +# Acknowledgements +This application makes use of the following third party libraries: + +## PureLayout + +This code is distributed under the terms and conditions of the MIT license. + +Copyright (c) 2014-2015 Tyler Fox + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Generated by CocoaPods - http://cocoapods.org diff --git a/Pods/Target Support Files/Pods/Pods-acknowledgements.plist b/Pods/Target Support Files/Pods/Pods-acknowledgements.plist new file mode 100644 index 0000000..26ec4e4 --- /dev/null +++ b/Pods/Target Support Files/Pods/Pods-acknowledgements.plist @@ -0,0 +1,46 @@ + + + + + PreferenceSpecifiers + + + FooterText + This application makes use of the following third party libraries: + Title + Acknowledgements + Type + PSGroupSpecifier + + + FooterText + This code is distributed under the terms and conditions of the MIT license. + +Copyright (c) 2014-2015 Tyler Fox + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + Title + PureLayout + Type + PSGroupSpecifier + + + FooterText + Generated by CocoaPods - http://cocoapods.org + Title + + Type + PSGroupSpecifier + + + StringsTable + Acknowledgements + Title + Acknowledgements + + diff --git a/Pods/Target Support Files/Pods/Pods-dummy.m b/Pods/Target Support Files/Pods/Pods-dummy.m new file mode 100644 index 0000000..ade64bd --- /dev/null +++ b/Pods/Target Support Files/Pods/Pods-dummy.m @@ -0,0 +1,5 @@ +#import +@interface PodsDummy_Pods : NSObject +@end +@implementation PodsDummy_Pods +@end diff --git a/Pods/Target Support Files/Pods/Pods-frameworks.sh b/Pods/Target Support Files/Pods/Pods-frameworks.sh new file mode 100755 index 0000000..212af00 --- /dev/null +++ b/Pods/Target Support Files/Pods/Pods-frameworks.sh @@ -0,0 +1,59 @@ +#!/bin/sh +set -e + +echo "mkdir -p ${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" +mkdir -p "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" + +SWIFT_STDLIB_PATH="${DT_TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}" + +install_framework() +{ + if [ -r "${BUILT_PRODUCTS_DIR}/$1" ]; then + local source="${BUILT_PRODUCTS_DIR}/$1" + else + local source="${BUILT_PRODUCTS_DIR}/$(basename "$1")" + fi + + local destination="${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" + + if [ -L "${source}" ]; then + echo "Symlinked..." + source="$(readlink "${source}")" + fi + + # use filter instead of exclude so missing patterns dont' throw errors + echo "rsync -av --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${source}\" \"${destination}\"" + rsync -av --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${source}" "${destination}" + + # Resign the code if required by the build settings to avoid unstable apps + code_sign_if_enabled "${destination}/$(basename "$1")" + + # Embed linked Swift runtime libraries + local basename + basename="$(basename "$1" | sed -E s/\\..+// && exit ${PIPESTATUS[0]})" + local swift_runtime_libs + swift_runtime_libs=$(xcrun otool -LX "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/${basename}.framework/${basename}" | grep --color=never @rpath/libswift | sed -E s/@rpath\\/\(.+dylib\).*/\\1/g | uniq -u && exit ${PIPESTATUS[0]}) + for lib in $swift_runtime_libs; do + echo "rsync -auv \"${SWIFT_STDLIB_PATH}/${lib}\" \"${destination}\"" + rsync -auv "${SWIFT_STDLIB_PATH}/${lib}" "${destination}" + code_sign_if_enabled "${destination}/${lib}" + done +} + +# Signs a framework with the provided identity +code_sign_if_enabled() { + if [ -n "${EXPANDED_CODE_SIGN_IDENTITY}" -a "${CODE_SIGNING_REQUIRED}" != "NO" -a "${CODE_SIGNING_ALLOWED}" != "NO" ]; then + # Use the current code_sign_identitiy + echo "Code Signing $1 with Identity ${EXPANDED_CODE_SIGN_IDENTITY_NAME}" + echo "/usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} --preserve-metadata=identifier,entitlements \"$1\"" + /usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} --preserve-metadata=identifier,entitlements "$1" + fi +} + + +if [[ "$CONFIGURATION" == "Debug" ]]; then + install_framework 'Pods/PureLayout.framework' +fi +if [[ "$CONFIGURATION" == "Release" ]]; then + install_framework 'Pods/PureLayout.framework' +fi diff --git a/Pods/Target Support Files/Pods/Pods-resources.sh b/Pods/Target Support Files/Pods/Pods-resources.sh new file mode 100755 index 0000000..ea685a2 --- /dev/null +++ b/Pods/Target Support Files/Pods/Pods-resources.sh @@ -0,0 +1,95 @@ +#!/bin/sh +set -e + +mkdir -p "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" + +RESOURCES_TO_COPY=${PODS_ROOT}/resources-to-copy-${TARGETNAME}.txt +> "$RESOURCES_TO_COPY" + +XCASSET_FILES=() + +realpath() { + DIRECTORY="$(cd "${1%/*}" && pwd)" + FILENAME="${1##*/}" + echo "$DIRECTORY/$FILENAME" +} + +install_resource() +{ + case $1 in + *.storyboard) + echo "ibtool --reference-external-strings-file --errors --warnings --notices --output-format human-readable-text --compile ${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$1\" .storyboard`.storyboardc ${PODS_ROOT}/$1 --sdk ${SDKROOT}" + ibtool --reference-external-strings-file --errors --warnings --notices --output-format human-readable-text --compile "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$1\" .storyboard`.storyboardc" "${PODS_ROOT}/$1" --sdk "${SDKROOT}" + ;; + *.xib) + echo "ibtool --reference-external-strings-file --errors --warnings --notices --output-format human-readable-text --compile ${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$1\" .xib`.nib ${PODS_ROOT}/$1 --sdk ${SDKROOT}" + ibtool --reference-external-strings-file --errors --warnings --notices --output-format human-readable-text --compile "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$1\" .xib`.nib" "${PODS_ROOT}/$1" --sdk "${SDKROOT}" + ;; + *.framework) + echo "mkdir -p ${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" + mkdir -p "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" + echo "rsync -av ${PODS_ROOT}/$1 ${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" + rsync -av "${PODS_ROOT}/$1" "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" + ;; + *.xcdatamodel) + echo "xcrun momc \"${PODS_ROOT}/$1\" \"${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$1"`.mom\"" + xcrun momc "${PODS_ROOT}/$1" "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$1" .xcdatamodel`.mom" + ;; + *.xcdatamodeld) + echo "xcrun momc \"${PODS_ROOT}/$1\" \"${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$1" .xcdatamodeld`.momd\"" + xcrun momc "${PODS_ROOT}/$1" "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$1" .xcdatamodeld`.momd" + ;; + *.xcmappingmodel) + echo "xcrun mapc \"${PODS_ROOT}/$1\" \"${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$1" .xcmappingmodel`.cdm\"" + xcrun mapc "${PODS_ROOT}/$1" "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$1" .xcmappingmodel`.cdm" + ;; + *.xcassets) + ABSOLUTE_XCASSET_FILE=$(realpath "${PODS_ROOT}/$1") + XCASSET_FILES+=("$ABSOLUTE_XCASSET_FILE") + ;; + /*) + echo "$1" + echo "$1" >> "$RESOURCES_TO_COPY" + ;; + *) + echo "${PODS_ROOT}/$1" + echo "${PODS_ROOT}/$1" >> "$RESOURCES_TO_COPY" + ;; + esac +} + +mkdir -p "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" +rsync -avr --copy-links --no-relative --exclude '*/.svn/*' --files-from="$RESOURCES_TO_COPY" / "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" +if [[ "${ACTION}" == "install" ]]; then + mkdir -p "${INSTALL_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" + rsync -avr --copy-links --no-relative --exclude '*/.svn/*' --files-from="$RESOURCES_TO_COPY" / "${INSTALL_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" +fi +rm -f "$RESOURCES_TO_COPY" + +if [[ -n "${WRAPPER_EXTENSION}" ]] && [ "`xcrun --find actool`" ] && [ -n "$XCASSET_FILES" ] +then + case "${TARGETED_DEVICE_FAMILY}" in + 1,2) + TARGET_DEVICE_ARGS="--target-device ipad --target-device iphone" + ;; + 1) + TARGET_DEVICE_ARGS="--target-device iphone" + ;; + 2) + TARGET_DEVICE_ARGS="--target-device ipad" + ;; + *) + TARGET_DEVICE_ARGS="--target-device mac" + ;; + esac + + # Find all other xcassets (this unfortunately includes those of path pods and other targets). + OTHER_XCASSETS=$(find "$PWD" -iname "*.xcassets" -type d) + while read line; do + if [[ $line != "`realpath $PODS_ROOT`*" ]]; then + XCASSET_FILES+=("$line") + fi + done <<<"$OTHER_XCASSETS" + + printf "%s\0" "${XCASSET_FILES[@]}" | xargs -0 xcrun actool --output-format human-readable-text --notices --warnings --platform "${PLATFORM_NAME}" --minimum-deployment-target "${IPHONEOS_DEPLOYMENT_TARGET}" ${TARGET_DEVICE_ARGS} --compress-pngs --compile "${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" +fi diff --git a/Pods/Target Support Files/Pods/Pods-umbrella.h b/Pods/Target Support Files/Pods/Pods-umbrella.h new file mode 100644 index 0000000..21dcfd2 --- /dev/null +++ b/Pods/Target Support Files/Pods/Pods-umbrella.h @@ -0,0 +1,6 @@ +#import + + +FOUNDATION_EXPORT double PodsVersionNumber; +FOUNDATION_EXPORT const unsigned char PodsVersionString[]; + diff --git a/Pods/Target Support Files/Pods/Pods.debug.xcconfig b/Pods/Target Support Files/Pods/Pods.debug.xcconfig new file mode 100644 index 0000000..eb4d3d2 --- /dev/null +++ b/Pods/Target Support Files/Pods/Pods.debug.xcconfig @@ -0,0 +1,6 @@ +GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 +LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks' +OTHER_CFLAGS = $(inherited) -iquote "$CONFIGURATION_BUILD_DIR/PureLayout.framework/Headers" +OTHER_LDFLAGS = $(inherited) -framework "PureLayout" +PODS_FRAMEWORK_BUILD_PATH = $(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/Pods +PODS_ROOT = ${SRCROOT}/Pods \ No newline at end of file diff --git a/Pods/Target Support Files/Pods/Pods.modulemap b/Pods/Target Support Files/Pods/Pods.modulemap new file mode 100644 index 0000000..8413413 --- /dev/null +++ b/Pods/Target Support Files/Pods/Pods.modulemap @@ -0,0 +1,6 @@ +framework module Pods { + umbrella header "Pods-umbrella.h" + + export * + module * { export * } +} diff --git a/Pods/Target Support Files/Pods/Pods.release.xcconfig b/Pods/Target Support Files/Pods/Pods.release.xcconfig new file mode 100644 index 0000000..eb4d3d2 --- /dev/null +++ b/Pods/Target Support Files/Pods/Pods.release.xcconfig @@ -0,0 +1,6 @@ +GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 +LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks' +OTHER_CFLAGS = $(inherited) -iquote "$CONFIGURATION_BUILD_DIR/PureLayout.framework/Headers" +OTHER_LDFLAGS = $(inherited) -framework "PureLayout" +PODS_FRAMEWORK_BUILD_PATH = $(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/Pods +PODS_ROOT = ${SRCROOT}/Pods \ No newline at end of file diff --git a/Pods/Target Support Files/PureLayout/Info.plist b/Pods/Target Support Files/PureLayout/Info.plist new file mode 100644 index 0000000..dc92af9 --- /dev/null +++ b/Pods/Target Support Files/PureLayout/Info.plist @@ -0,0 +1,26 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIdentifier + org.cocoapods.${PRODUCT_NAME:rfc1034identifier} + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ${PRODUCT_NAME} + CFBundlePackageType + FMWK + CFBundleShortVersionString + 3.0.0 + CFBundleSignature + ???? + CFBundleVersion + ${CURRENT_PROJECT_VERSION} + NSPrincipalClass + + + diff --git a/Pods/Target Support Files/PureLayout/PureLayout-Private.xcconfig b/Pods/Target Support Files/PureLayout/PureLayout-Private.xcconfig new file mode 100644 index 0000000..a7833f5 --- /dev/null +++ b/Pods/Target Support Files/PureLayout/PureLayout-Private.xcconfig @@ -0,0 +1,5 @@ +#include "PureLayout.xcconfig" +GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 +HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Private/PureLayout" "${PODS_ROOT}/Headers/Public" +PODS_ROOT = ${SRCROOT} +SKIP_INSTALL = YES \ No newline at end of file diff --git a/Pods/Target Support Files/PureLayout/PureLayout-dummy.m b/Pods/Target Support Files/PureLayout/PureLayout-dummy.m new file mode 100644 index 0000000..de09ca1 --- /dev/null +++ b/Pods/Target Support Files/PureLayout/PureLayout-dummy.m @@ -0,0 +1,5 @@ +#import +@interface PodsDummy_PureLayout : NSObject +@end +@implementation PodsDummy_PureLayout +@end diff --git a/Pods/Target Support Files/PureLayout/PureLayout-prefix.pch b/Pods/Target Support Files/PureLayout/PureLayout-prefix.pch new file mode 100644 index 0000000..aa992a4 --- /dev/null +++ b/Pods/Target Support Files/PureLayout/PureLayout-prefix.pch @@ -0,0 +1,4 @@ +#ifdef __OBJC__ +#import +#endif + diff --git a/Pods/Target Support Files/PureLayout/PureLayout-umbrella.h b/Pods/Target Support Files/PureLayout/PureLayout-umbrella.h new file mode 100644 index 0000000..b50c609 --- /dev/null +++ b/Pods/Target Support Files/PureLayout/PureLayout-umbrella.h @@ -0,0 +1,12 @@ +#import + +#import "ALView+PureLayout.h" +#import "NSArray+PureLayout.h" +#import "NSLayoutConstraint+PureLayout.h" +#import "PureLayout+Internal.h" +#import "PureLayout.h" +#import "PureLayoutDefines.h" + +FOUNDATION_EXPORT double PureLayoutVersionNumber; +FOUNDATION_EXPORT const unsigned char PureLayoutVersionString[]; + diff --git a/Pods/Target Support Files/PureLayout/PureLayout.modulemap b/Pods/Target Support Files/PureLayout/PureLayout.modulemap new file mode 100644 index 0000000..fd62d58 --- /dev/null +++ b/Pods/Target Support Files/PureLayout/PureLayout.modulemap @@ -0,0 +1,6 @@ +framework module PureLayout { + umbrella header "PureLayout-umbrella.h" + + export * + module * { export * } +} diff --git a/Pods/Target Support Files/PureLayout/PureLayout.xcconfig b/Pods/Target Support Files/PureLayout/PureLayout.xcconfig new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md index d390e27..60f865d 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,23 @@ TableViewCellWithAutoLayoutiOS8 =========================== -Sample project demonstrating self-sizing table view cells in iOS 8, using Auto Layout in UITableViewCell to achieve dynamic layouts with variable row heights. This project requires Xcode 6 and iOS 8, and is a universal app that will run on iPhone and iPad. +*Note: This sample project requires __Xcode 7__ and __iOS 8__. For a sample project demonstrating the iOS 7 compatible implementation, [click here](https://github.com/smileyborg/TableViewCellWithAutoLayout).* + +Sample project demonstrating self-sizing table view cells in iOS 8, using Auto Layout in UITableViewCell to achieve dynamic layouts with variable row heights. This project is a universal app that will run on iPhone and iPad. This implementation is only compatible with iOS 8 and later. + +There are two branches in this repository: + +1. **master** (this branch) - A Swift 2.0 implementation +2. **[objective-c](https://github.com/smileyborg/TableViewCellWithAutoLayoutiOS8/tree/objective-c)** - An Objective-C implementation + +To build & run the app, you should open the `TableViewCellWithAutoLayout.xcworkspace` in Xcode. This sample project displays a table view with cells that each contain a single-line title label and a multi-line body label (each cell's body label displays a random number of lorem ipsum words). -This project utilizes the open source [UIView+AutoLayout API](https://github.com/smileyborg/UIView-AutoLayout) to easily set up constraints in code. +This project utilizes the open source [PureLayout](https://github.com/smileyborg/PureLayout) library to easily set up constraints in code. See the original post on Stack Overflow for more info: http://stackoverflow.com/questions/18746929/using-auto-layout-in-uitableview-for-dynamic-cell-layouts-variable-row-heights -If you have questions or run into issues, please [open a new Issue on this GitHub project](https://github.com/smileyborg/TableViewCellWithAutoLayoutiOS8/issues/new) or reach out to me on Twitter [@smileyborg](https://twitter.com/smileyborg). +If you have questions or run into issues, please [open a new Issue on this GitHub project](https://github.com/smileyborg/TableViewCellWithAutoLayoutiOS8/issues/new). diff --git a/TableViewCellWithAutoLayout.xcodeproj/project.pbxproj b/TableViewCellWithAutoLayout.xcodeproj/project.pbxproj index b58bc0d..a87308f 100644 --- a/TableViewCellWithAutoLayout.xcodeproj/project.pbxproj +++ b/TableViewCellWithAutoLayout.xcodeproj/project.pbxproj @@ -7,22 +7,23 @@ objects = { /* Begin PBXBuildFile section */ + 5A3B25361945F89500838EF4 /* NibTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A3B25351945F89500838EF4 /* NibTableViewCell.swift */; }; + 5A3B25381945F8AC00838EF4 /* NibTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 5A3B25371945F8AC00838EF4 /* NibTableViewCell.xib */; }; + 65C7B47C160366D672EF8E13 /* Pods.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E94577F57ED7FB9D3081729B /* Pods.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; 99BCDCA518008C0000B8E66B /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 99BCDCA418008C0000B8E66B /* Foundation.framework */; }; 99BCDCA718008C0000B8E66B /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 99BCDCA618008C0000B8E66B /* CoreGraphics.framework */; }; 99BCDCA918008C0000B8E66B /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 99BCDCA818008C0000B8E66B /* UIKit.framework */; }; 99BCDCAF18008C0000B8E66B /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 99BCDCAD18008C0000B8E66B /* InfoPlist.strings */; }; - 99BCDCB118008C0000B8E66B /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 99BCDCB018008C0000B8E66B /* main.m */; }; - 99BCDCB518008C0000B8E66B /* RJAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 99BCDCB418008C0000B8E66B /* RJAppDelegate.m */; }; 99BCDCB718008C0000B8E66B /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 99BCDCB618008C0000B8E66B /* Images.xcassets */; }; 99BCDCBE18008C0000B8E66B /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 99BCDCBD18008C0000B8E66B /* XCTest.framework */; }; 99BCDCBF18008C0000B8E66B /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 99BCDCA418008C0000B8E66B /* Foundation.framework */; }; 99BCDCC018008C0000B8E66B /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 99BCDCA818008C0000B8E66B /* UIKit.framework */; }; 99BCDCC818008C0000B8E66B /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 99BCDCC618008C0000B8E66B /* InfoPlist.strings */; }; 99BCDCCA18008C0000B8E66B /* TableViewCellWithAutoLayoutTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 99BCDCC918008C0000B8E66B /* TableViewCellWithAutoLayoutTests.m */; }; - 99BCDCDA18008C1700B8E66B /* RJModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 99BCDCD518008C1700B8E66B /* RJModel.m */; }; - 99BCDCDB18008C1700B8E66B /* RJTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 99BCDCD718008C1700B8E66B /* RJTableViewCell.m */; }; - 99BCDCDC18008C1700B8E66B /* RJTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 99BCDCD918008C1700B8E66B /* RJTableViewController.m */; }; - B147F1841867A715002B0C25 /* UIView+AutoLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = B147F1831867A715002B0C25 /* UIView+AutoLayout.m */; }; + A7C103221943F73D006A9720 /* TableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7C103211943F73D006A9720 /* TableViewCell.swift */; }; + A7F5DDAA194408D9008E238B /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7F5DDA9194408D9008E238B /* AppDelegate.swift */; }; + A7F5DDAC19440B7B008E238B /* Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7F5DDAB19440B7B008E238B /* Model.swift */; }; + A7F5DDAE194417DC008E238B /* TableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7F5DDAD194417DC008E238B /* TableViewController.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -36,30 +37,29 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 57612988E552EA49095C8330 /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = ""; }; + 5A3B25351945F89500838EF4 /* NibTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NibTableViewCell.swift; sourceTree = ""; }; + 5A3B25371945F8AC00838EF4 /* NibTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = NibTableViewCell.xib; sourceTree = ""; }; 99BCDCA118008C0000B8E66B /* TableViewCellWithAutoLayout.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TableViewCellWithAutoLayout.app; sourceTree = BUILT_PRODUCTS_DIR; }; 99BCDCA418008C0000B8E66B /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 99BCDCA618008C0000B8E66B /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; 99BCDCA818008C0000B8E66B /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 99BCDCAC18008C0000B8E66B /* TableViewCellWithAutoLayout-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "TableViewCellWithAutoLayout-Info.plist"; sourceTree = ""; }; 99BCDCAE18008C0000B8E66B /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; - 99BCDCB018008C0000B8E66B /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 99BCDCB218008C0000B8E66B /* TableViewCellWithAutoLayout-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "TableViewCellWithAutoLayout-Prefix.pch"; sourceTree = ""; }; - 99BCDCB318008C0000B8E66B /* RJAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RJAppDelegate.h; sourceTree = ""; }; - 99BCDCB418008C0000B8E66B /* RJAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RJAppDelegate.m; sourceTree = ""; }; 99BCDCB618008C0000B8E66B /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 99BCDCBC18008C0000B8E66B /* TableViewCellWithAutoLayoutTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TableViewCellWithAutoLayoutTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 99BCDCBD18008C0000B8E66B /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; }; 99BCDCC518008C0000B8E66B /* TableViewCellWithAutoLayoutTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "TableViewCellWithAutoLayoutTests-Info.plist"; sourceTree = ""; }; 99BCDCC718008C0000B8E66B /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 99BCDCC918008C0000B8E66B /* TableViewCellWithAutoLayoutTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TableViewCellWithAutoLayoutTests.m; sourceTree = ""; }; - 99BCDCD418008C1700B8E66B /* RJModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RJModel.h; sourceTree = ""; }; - 99BCDCD518008C1700B8E66B /* RJModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RJModel.m; sourceTree = ""; }; - 99BCDCD618008C1700B8E66B /* RJTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RJTableViewCell.h; sourceTree = ""; }; - 99BCDCD718008C1700B8E66B /* RJTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RJTableViewCell.m; sourceTree = ""; }; - 99BCDCD818008C1700B8E66B /* RJTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RJTableViewController.h; sourceTree = ""; }; - 99BCDCD918008C1700B8E66B /* RJTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RJTableViewController.m; sourceTree = ""; }; - B147F1821867A715002B0C25 /* UIView+AutoLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+AutoLayout.h"; sourceTree = ""; }; - B147F1831867A715002B0C25 /* UIView+AutoLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+AutoLayout.m"; sourceTree = ""; }; + A7C103201943F73C006A9720 /* TableViewCellWithAutoLayout-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "TableViewCellWithAutoLayout-Bridging-Header.h"; sourceTree = ""; }; + A7C103211943F73D006A9720 /* TableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableViewCell.swift; sourceTree = ""; }; + A7F5DDA9194408D9008E238B /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + A7F5DDAB19440B7B008E238B /* Model.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Model.swift; sourceTree = ""; }; + A7F5DDAD194417DC008E238B /* TableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableViewController.swift; sourceTree = ""; }; + E8389E598E67F5F16660D9AC /* Pods.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.release.xcconfig; path = "Pods/Target Support Files/Pods/Pods.release.xcconfig"; sourceTree = ""; }; + E94577F57ED7FB9D3081729B /* Pods.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods.framework; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -70,6 +70,7 @@ 99BCDCA718008C0000B8E66B /* CoreGraphics.framework in Frameworks */, 99BCDCA918008C0000B8E66B /* UIKit.framework in Frameworks */, 99BCDCA518008C0000B8E66B /* Foundation.framework in Frameworks */, + 65C7B47C160366D672EF8E13 /* Pods.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -93,6 +94,7 @@ 99BCDCC318008C0000B8E66B /* TableViewCellWithAutoLayoutTests */, 99BCDCA318008C0000B8E66B /* Frameworks */, 99BCDCA218008C0000B8E66B /* Products */, + B388C4772DBE5FA65C4D24F3 /* Pods */, ); sourceTree = ""; }; @@ -112,6 +114,7 @@ 99BCDCA618008C0000B8E66B /* CoreGraphics.framework */, 99BCDCA818008C0000B8E66B /* UIKit.framework */, 99BCDCBD18008C0000B8E66B /* XCTest.framework */, + E94577F57ED7FB9D3081729B /* Pods.framework */, ); name = Frameworks; sourceTree = ""; @@ -119,9 +122,7 @@ 99BCDCAA18008C0000B8E66B /* TableViewCellWithAutoLayout */ = { isa = PBXGroup; children = ( - B147F1811867A715002B0C25 /* UIView+AutoLayout */, - 99BCDCB318008C0000B8E66B /* RJAppDelegate.h */, - 99BCDCB418008C0000B8E66B /* RJAppDelegate.m */, + A7F5DDA9194408D9008E238B /* AppDelegate.swift */, 99BCDCB618008C0000B8E66B /* Images.xcassets */, 99BCDCD318008C1700B8E66B /* TableViewController */, 99BCDCAB18008C0000B8E66B /* Supporting Files */, @@ -134,7 +135,6 @@ children = ( 99BCDCAC18008C0000B8E66B /* TableViewCellWithAutoLayout-Info.plist */, 99BCDCAD18008C0000B8E66B /* InfoPlist.strings */, - 99BCDCB018008C0000B8E66B /* main.m */, 99BCDCB218008C0000B8E66B /* TableViewCellWithAutoLayout-Prefix.pch */, ); name = "Supporting Files"; @@ -161,23 +161,39 @@ 99BCDCD318008C1700B8E66B /* TableViewController */ = { isa = PBXGroup; children = ( - 99BCDCD418008C1700B8E66B /* RJModel.h */, - 99BCDCD518008C1700B8E66B /* RJModel.m */, - 99BCDCD618008C1700B8E66B /* RJTableViewCell.h */, - 99BCDCD718008C1700B8E66B /* RJTableViewCell.m */, - 99BCDCD818008C1700B8E66B /* RJTableViewController.h */, - 99BCDCD918008C1700B8E66B /* RJTableViewController.m */, + A7C103201943F73C006A9720 /* TableViewCellWithAutoLayout-Bridging-Header.h */, + A7F5DDAB19440B7B008E238B /* Model.swift */, + A7F5DDAD194417DC008E238B /* TableViewController.swift */, + B13F6E9E1947D6DE00FF3B42 /* Programmatic */, + B13F6E9F1947D6EB00FF3B42 /* Interface Builder */, ); path = TableViewController; sourceTree = ""; }; - B147F1811867A715002B0C25 /* UIView+AutoLayout */ = { + B13F6E9E1947D6DE00FF3B42 /* Programmatic */ = { isa = PBXGroup; children = ( - B147F1821867A715002B0C25 /* UIView+AutoLayout.h */, - B147F1831867A715002B0C25 /* UIView+AutoLayout.m */, + A7C103211943F73D006A9720 /* TableViewCell.swift */, ); - path = "UIView+AutoLayout"; + name = Programmatic; + sourceTree = ""; + }; + B13F6E9F1947D6EB00FF3B42 /* Interface Builder */ = { + isa = PBXGroup; + children = ( + 5A3B25351945F89500838EF4 /* NibTableViewCell.swift */, + 5A3B25371945F8AC00838EF4 /* NibTableViewCell.xib */, + ); + name = "Interface Builder"; + sourceTree = ""; + }; + B388C4772DBE5FA65C4D24F3 /* Pods */ = { + isa = PBXGroup; + children = ( + 57612988E552EA49095C8330 /* Pods.debug.xcconfig */, + E8389E598E67F5F16660D9AC /* Pods.release.xcconfig */, + ); + name = Pods; sourceTree = ""; }; /* End PBXGroup section */ @@ -187,9 +203,12 @@ isa = PBXNativeTarget; buildConfigurationList = 99BCDCCD18008C0000B8E66B /* Build configuration list for PBXNativeTarget "TableViewCellWithAutoLayout" */; buildPhases = ( + FE8D2EDAD3B843D5ABF88A67 /* Check Pods Manifest.lock */, 99BCDC9D18008C0000B8E66B /* Sources */, 99BCDC9E18008C0000B8E66B /* Frameworks */, 99BCDC9F18008C0000B8E66B /* Resources */, + 5737466CF2C0FC46426305CF /* Embed Pods Frameworks */, + 4306B9C3FDF52317D88B94F0 /* Copy Pods Resources */, ); buildRules = ( ); @@ -225,8 +244,9 @@ isa = PBXProject; attributes = { CLASSPREFIX = RJ; - LastUpgradeCheck = 0500; - ORGANIZATIONNAME = RobotJackalope; + LastSwiftUpdateCheck = 0700; + LastUpgradeCheck = 0700; + ORGANIZATIONNAME = smileyborg; TargetAttributes = { 99BCDCBB18008C0000B8E66B = { TestTargetID = 99BCDCA018008C0000B8E66B; @@ -257,6 +277,7 @@ buildActionMask = 2147483647; files = ( 99BCDCAF18008C0000B8E66B /* InfoPlist.strings in Resources */, + 5A3B25381945F8AC00838EF4 /* NibTableViewCell.xib in Resources */, 99BCDCB718008C0000B8E66B /* Images.xcassets in Resources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -271,17 +292,64 @@ }; /* End PBXResourcesBuildPhase section */ +/* Begin PBXShellScriptBuildPhase section */ + 4306B9C3FDF52317D88B94F0 /* Copy Pods Resources */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Copy Pods Resources"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods/Pods-resources.sh\"\n"; + showEnvVarsInLog = 0; + }; + 5737466CF2C0FC46426305CF /* Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Embed Pods Frameworks"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods/Pods-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; + FE8D2EDAD3B843D5ABF88A67 /* Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Check Pods Manifest.lock"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; + showEnvVarsInLog = 0; + }; +/* End PBXShellScriptBuildPhase section */ + /* Begin PBXSourcesBuildPhase section */ 99BCDC9D18008C0000B8E66B /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 99BCDCB518008C0000B8E66B /* RJAppDelegate.m in Sources */, - B147F1841867A715002B0C25 /* UIView+AutoLayout.m in Sources */, - 99BCDCDC18008C1700B8E66B /* RJTableViewController.m in Sources */, - 99BCDCB118008C0000B8E66B /* main.m in Sources */, - 99BCDCDA18008C1700B8E66B /* RJModel.m in Sources */, - 99BCDCDB18008C1700B8E66B /* RJTableViewCell.m in Sources */, + 5A3B25361945F89500838EF4 /* NibTableViewCell.swift in Sources */, + A7F5DDAE194417DC008E238B /* TableViewController.swift in Sources */, + A7F5DDAA194408D9008E238B /* AppDelegate.swift in Sources */, + A7F5DDAC19440B7B008E238B /* Model.swift in Sources */, + A7C103221943F73D006A9720 /* TableViewCell.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -327,7 +395,6 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; @@ -342,6 +409,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; + ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_OPTIMIZATION_LEVEL = 0; @@ -367,7 +435,6 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; @@ -399,28 +466,39 @@ }; 99BCDCCE18008C0000B8E66B /* Debug */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 57612988E552EA49095C8330 /* Pods.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; + CLANG_ENABLE_MODULES = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "TableViewCellWithAutoLayout/TableViewCellWithAutoLayout-Prefix.pch"; INFOPLIST_FILE = "TableViewCellWithAutoLayout/TableViewCellWithAutoLayout-Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.smileyborg.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "TableViewCellWithAutoLayout/TableViewController/TableViewCellWithAutoLayout-Bridging-Header.h"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; WRAPPER_EXTENSION = app; }; name = Debug; }; 99BCDCCF18008C0000B8E66B /* Release */ = { isa = XCBuildConfiguration; + baseConfigurationReference = E8389E598E67F5F16660D9AC /* Pods.release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; + CLANG_ENABLE_MODULES = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "TableViewCellWithAutoLayout/TableViewCellWithAutoLayout-Prefix.pch"; INFOPLIST_FILE = "TableViewCellWithAutoLayout/TableViewCellWithAutoLayout-Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.smileyborg.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "TableViewCellWithAutoLayout/TableViewController/TableViewCellWithAutoLayout-Bridging-Header.h"; WRAPPER_EXTENSION = app; }; name = Release; @@ -428,7 +506,6 @@ 99BCDCD118008C0000B8E66B /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/TableViewCellWithAutoLayout.app/TableViewCellWithAutoLayout"; FRAMEWORK_SEARCH_PATHS = ( "$(SDKROOT)/Developer/Library/Frameworks", @@ -442,6 +519,7 @@ "$(inherited)", ); INFOPLIST_FILE = "TableViewCellWithAutoLayoutTests/TableViewCellWithAutoLayoutTests-Info.plist"; + PRODUCT_BUNDLE_IDENTIFIER = "com.smileyborg.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; TEST_HOST = "$(BUNDLE_LOADER)"; WRAPPER_EXTENSION = xctest; @@ -451,7 +529,6 @@ 99BCDCD218008C0000B8E66B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/TableViewCellWithAutoLayout.app/TableViewCellWithAutoLayout"; FRAMEWORK_SEARCH_PATHS = ( "$(SDKROOT)/Developer/Library/Frameworks", @@ -461,6 +538,7 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "TableViewCellWithAutoLayout/TableViewCellWithAutoLayout-Prefix.pch"; INFOPLIST_FILE = "TableViewCellWithAutoLayoutTests/TableViewCellWithAutoLayoutTests-Info.plist"; + PRODUCT_BUNDLE_IDENTIFIER = "com.smileyborg.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; TEST_HOST = "$(BUNDLE_LOADER)"; WRAPPER_EXTENSION = xctest; diff --git a/TableViewCellWithAutoLayout.xcworkspace/contents.xcworkspacedata b/TableViewCellWithAutoLayout.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..8ff91bb --- /dev/null +++ b/TableViewCellWithAutoLayout.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,10 @@ + + + + + + + diff --git a/TableViewCellWithAutoLayout/AppDelegate.swift b/TableViewCellWithAutoLayout/AppDelegate.swift new file mode 100644 index 0000000..6b0a6d7 --- /dev/null +++ b/TableViewCellWithAutoLayout/AppDelegate.swift @@ -0,0 +1,51 @@ +// +// AppDelegate.swift +// TableViewCellWithAutoLayout +// +// Copyright (c) 2014 Tyler Fox +// + +import UIKit + +@UIApplicationMain +class AppDelegate: UIResponder, UIApplicationDelegate +{ + var window: UIWindow? + + func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool + { + // Override point for customization after application launch. + window = UIWindow(frame: UIScreen.mainScreen().bounds) + let viewController = TableViewController(style: .Plain) + window!.rootViewController = UINavigationController(rootViewController: viewController) + window!.makeKeyAndVisible() + return true + } + + func applicationWillResignActive(application: UIApplication) + { + // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. + // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. + } + + func applicationDidEnterBackground(application: UIApplication) + { + // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. + // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. + } + + func applicationWillEnterForeground(application: UIApplication) + { + // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. + } + + func applicationDidBecomeActive(application: UIApplication) + { + // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. + } + + func applicationWillTerminate(application: UIApplication) + { + // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. + } +} diff --git a/TableViewCellWithAutoLayout/Images.xcassets/AppIcon.appiconset/Contents.json b/TableViewCellWithAutoLayout/Images.xcassets/AppIcon.appiconset/Contents.json index 91bf9c1..b7f3352 100644 --- a/TableViewCellWithAutoLayout/Images.xcassets/AppIcon.appiconset/Contents.json +++ b/TableViewCellWithAutoLayout/Images.xcassets/AppIcon.appiconset/Contents.json @@ -15,6 +15,11 @@ "size" : "60x60", "scale" : "2x" }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "3x" + }, { "idiom" : "ipad", "size" : "29x29", diff --git a/TableViewCellWithAutoLayout/Images.xcassets/LaunchImage.launchimage/Contents.json b/TableViewCellWithAutoLayout/Images.xcassets/LaunchImage.launchimage/Contents.json index 6f870a4..a0326e6 100644 --- a/TableViewCellWithAutoLayout/Images.xcassets/LaunchImage.launchimage/Contents.json +++ b/TableViewCellWithAutoLayout/Images.xcassets/LaunchImage.launchimage/Contents.json @@ -1,20 +1,47 @@ { "images" : [ { + "extent" : "full-screen", + "idiom" : "iphone", + "subtype" : "736h", + "filename" : "Default-736h@3x.png", + "minimum-system-version" : "8.0", "orientation" : "portrait", + "scale" : "3x" + }, + { + "orientation" : "landscape", "idiom" : "iphone", "extent" : "full-screen", - "minimum-system-version" : "7.0", + "minimum-system-version" : "8.0", + "subtype" : "736h", + "scale" : "3x" + }, + { + "extent" : "full-screen", + "idiom" : "iphone", + "subtype" : "667h", + "filename" : "Default-667h@2x.png", + "minimum-system-version" : "8.0", + "orientation" : "portrait", "scale" : "2x" }, { "orientation" : "portrait", "idiom" : "iphone", - "subtype" : "retina4", "extent" : "full-screen", "minimum-system-version" : "7.0", "scale" : "2x" }, + { + "extent" : "full-screen", + "idiom" : "iphone", + "subtype" : "retina4", + "filename" : "Default-568h@2x.png", + "minimum-system-version" : "7.0", + "orientation" : "portrait", + "scale" : "2x" + }, { "orientation" : "portrait", "idiom" : "ipad", diff --git a/TableViewCellWithAutoLayout/Images.xcassets/LaunchImage.launchimage/Default-568h@2x.png b/TableViewCellWithAutoLayout/Images.xcassets/LaunchImage.launchimage/Default-568h@2x.png new file mode 100644 index 0000000..ff53e81 Binary files /dev/null and b/TableViewCellWithAutoLayout/Images.xcassets/LaunchImage.launchimage/Default-568h@2x.png differ diff --git a/TableViewCellWithAutoLayout/Images.xcassets/LaunchImage.launchimage/Default-667h@2x.png b/TableViewCellWithAutoLayout/Images.xcassets/LaunchImage.launchimage/Default-667h@2x.png new file mode 100644 index 0000000..a3dafc0 Binary files /dev/null and b/TableViewCellWithAutoLayout/Images.xcassets/LaunchImage.launchimage/Default-667h@2x.png differ diff --git a/TableViewCellWithAutoLayout/Images.xcassets/LaunchImage.launchimage/Default-736h@3x.png b/TableViewCellWithAutoLayout/Images.xcassets/LaunchImage.launchimage/Default-736h@3x.png new file mode 100644 index 0000000..f89a1b8 Binary files /dev/null and b/TableViewCellWithAutoLayout/Images.xcassets/LaunchImage.launchimage/Default-736h@3x.png differ diff --git a/TableViewCellWithAutoLayout/RJAppDelegate.h b/TableViewCellWithAutoLayout/RJAppDelegate.h deleted file mode 100644 index 0344e59..0000000 --- a/TableViewCellWithAutoLayout/RJAppDelegate.h +++ /dev/null @@ -1,34 +0,0 @@ -// -// RJAppDelegate.h -// TableViewCellWithAutoLayout -// -// Created by Kevin Muldoon & Tyler Fox on 10/5/13. -// Copyright (c) 2013 RobotJackalope. All rights reserved. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// - -#import - -@interface RJAppDelegate : UIResponder - -@property (strong, nonatomic) UIWindow *window; -@property (strong, nonatomic) UINavigationController *navigationController; - -@end diff --git a/TableViewCellWithAutoLayout/RJAppDelegate.m b/TableViewCellWithAutoLayout/RJAppDelegate.m deleted file mode 100644 index efd5a90..0000000 --- a/TableViewCellWithAutoLayout/RJAppDelegate.m +++ /dev/null @@ -1,70 +0,0 @@ -// -// RJAppDelegate.m -// TableViewCellWithAutoLayout -// -// Created by Kevin Muldoon & Tyler Fox on 10/5/13. -// Copyright (c) 2013 RobotJackalope. All rights reserved. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// - -#import "RJAppDelegate.h" -#import "RJTableViewController.h" - -@implementation RJAppDelegate - -- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions -{ - self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; - // Override point for customization after application launch. - RJTableViewController *viewController = [[RJTableViewController alloc] initWithStyle:UITableViewStylePlain]; - self.navigationController = [[UINavigationController alloc] initWithRootViewController:viewController]; - self.window.rootViewController = self.navigationController; - [self.window makeKeyAndVisible]; - return YES; -} - -- (void)applicationWillResignActive:(UIApplication *)application -{ - // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. - // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. -} - -- (void)applicationDidEnterBackground:(UIApplication *)application -{ - // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. - // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. -} - -- (void)applicationWillEnterForeground:(UIApplication *)application -{ - // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. -} - -- (void)applicationDidBecomeActive:(UIApplication *)application -{ - // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. -} - -- (void)applicationWillTerminate:(UIApplication *)application -{ - // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. -} - -@end diff --git a/TableViewCellWithAutoLayout/TableViewCellWithAutoLayout-Info.plist b/TableViewCellWithAutoLayout/TableViewCellWithAutoLayout-Info.plist index e3bddf9..6a012bd 100644 --- a/TableViewCellWithAutoLayout/TableViewCellWithAutoLayout-Info.plist +++ b/TableViewCellWithAutoLayout/TableViewCellWithAutoLayout-Info.plist @@ -9,7 +9,7 @@ CFBundleExecutable ${EXECUTABLE_NAME} CFBundleIdentifier - com.robotjackalope.${PRODUCT_NAME:rfc1034identifier} + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/TableViewCellWithAutoLayout/TableViewCellWithAutoLayout-Prefix.pch b/TableViewCellWithAutoLayout/TableViewCellWithAutoLayout-Prefix.pch index f808fee..743435c 100644 --- a/TableViewCellWithAutoLayout/TableViewCellWithAutoLayout-Prefix.pch +++ b/TableViewCellWithAutoLayout/TableViewCellWithAutoLayout-Prefix.pch @@ -13,5 +13,4 @@ #ifdef __OBJC__ #import #import - #import "UIView+AutoLayout.h" #endif diff --git a/TableViewCellWithAutoLayout/TableViewController/Model.swift b/TableViewCellWithAutoLayout/TableViewController/Model.swift new file mode 100644 index 0000000..b7c47d3 --- /dev/null +++ b/TableViewCellWithAutoLayout/TableViewController/Model.swift @@ -0,0 +1,50 @@ +// +// Model.swift +// TableViewCellWithAutoLayout +// +// Copyright (c) 2014 Tyler Fox +// + +import UIKit + +class Model +{ + var dataArray: [(title: String, body: String)] = [] + + init(populated: Bool) + { + if (populated) { + for familyName: AnyObject in UIFont.familyNames() { + if let familyNameString = familyName as? String { + dataArray.append((title: familyNameString, body: randomLoremIpsum())) + } + } + } + } + + func addSingleItem() + { + let fontFamilies = UIFont.familyNames() + + let r = random() % fontFamilies.count + let familyName: AnyObject = fontFamilies[r] + + if let familyNameString = familyName as? String { + dataArray.append((title: familyNameString, body: randomLoremIpsum())) + } + } + + func randomLoremIpsum() -> String + { + let loremIpsum = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent non quam ac massa viverra semper. Maecenas mattis justo ac augue volutpat congue. Maecenas laoreet, nulla eu faucibus gravida, felis orci dictum risus, sed sodales sem eros eget risus. Morbi imperdiet sed diam et sodales. Vestibulum ut est id mauris ultrices gravida. Nulla malesuada metus ut erat malesuada, vitae ornare neque semper. Aenean a commodo justo, vel placerat odio. Curabitur vitae consequat tortor. Aenean eu magna ante. Integer tristique elit ac augue laoreet, eget pulvinar lacus dictum. Cras eleifend lacus eget pharetra elementum. Etiam fermentum eu felis eu tristique. Integer eu purus vitae turpis blandit consectetur. Nulla facilisi. Praesent bibendum massa eu metus pulvinar, quis tristique nunc commodo. Ut varius aliquam elit, a tincidunt elit aliquam non. Nunc ac leo purus. Proin condimentum placerat ligula, at tristique neque scelerisque ut. Suspendisse ut congue enim. Integer id sem nisl. Nam dignissim, lectus et dictum sollicitudin, libero augue ullamcorper justo, nec consectetur dolor arcu sed justo. Proin rutrum pharetra lectus, vel gravida ante venenatis sed. Mauris lacinia urna vehicula felis aliquet venenatis. Suspendisse non pretium sapien. Proin id dolor ultricies, dictum augue non, euismod ante. Vivamus et luctus augue, a luctus mi. Maecenas sit amet felis in magna vestibulum viverra vel ut est. Suspendisse potenti. Morbi nec odio pretium lacus laoreet volutpat sit amet at ipsum. Etiam pretium purus vitae tortor auctor, quis cursus metus vehicula. Integer ultricies facilisis arcu, non congue orci pharetra quis. Vivamus pulvinar ligula neque, et vehicula ipsum euismod quis." + + let loremIpsumArray = loremIpsum.componentsSeparatedByString(" ") + + let minimumNumberOfWords = 3 + let r = max(minimumNumberOfWords, random() % loremIpsumArray.count) // get a random number r, where: minimumNumberOfWords <= r <= loremIpsumArray.count + let loremIpsumRandom = loremIpsumArray[0.. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/TableViewCellWithAutoLayout/TableViewController/RJModel.h b/TableViewCellWithAutoLayout/TableViewController/RJModel.h deleted file mode 100644 index 5f1ab4d..0000000 --- a/TableViewCellWithAutoLayout/TableViewController/RJModel.h +++ /dev/null @@ -1,37 +0,0 @@ -// -// RJSimpleModel.h -// Collection -// -// Created by Kevin Muldoon & Tyler Fox on 10/5/13. -// Copyright (c) 2013 RobotJackalope. All rights reserved. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// - -#import - -@interface RJModel : NSObject - -@property (nonatomic, strong) NSMutableArray *dataSource; - -- (void)populateDataSource; - -- (void)addSingleItemToDataSource; - -@end diff --git a/TableViewCellWithAutoLayout/TableViewController/RJModel.m b/TableViewCellWithAutoLayout/TableViewController/RJModel.m deleted file mode 100644 index a10b7fd..0000000 --- a/TableViewCellWithAutoLayout/TableViewController/RJModel.m +++ /dev/null @@ -1,104 +0,0 @@ -// -// RJSimpleModel.m -// Collection -// -// Created by Kevin Muldoon & Tyler Fox on 10/5/13. -// Copyright (c) 2013 RobotJackalope. All rights reserved. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// - -#import "RJModel.h" - -@implementation RJModel - -- (id)init { - - if (self = [super init]) { - - } - return self; -} - -- (NSMutableArray *)dataSource -{ - if (!_dataSource) { - _dataSource = [NSMutableArray new]; - } - return _dataSource; -} - -- (void)populateDataSource { - - NSArray *fontFamilies = [NSArray arrayWithArray:[UIFont familyNames]]; - NSMutableArray *result = [[NSMutableArray alloc] initWithCapacity:[fontFamilies count]]; - - for ( NSString *familyName in fontFamilies ) { - NSDictionary *dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:familyName, @"title", - [self randomLorumIpsum], @"body", - @"", @"element2", - @"", @"element3", - @"", @"element4", - nil]; - [result addObject:dictionary]; - } - - self.dataSource = result; - -} - -- (void)addSingleItemToDataSource { - - NSArray *fontFamilies = [NSArray arrayWithArray:[UIFont familyNames]]; - - int r = arc4random() % [fontFamilies count]; - NSString *familyName = [fontFamilies objectAtIndex:r]; - - NSDictionary *dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:familyName, @"title", - [self randomLorumIpsum], @"body", - @"", @"element2", - @"", @"element3", - @"", @"element4", - nil]; - - [self.dataSource addObject:dictionary]; - -} - -- (NSString *)randomLorumIpsum { - - NSString *lorumIpsum = @"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent non quam ac massa viverra semper. Maecenas mattis justo ac augue volutpat congue. Maecenas laoreet, nulla eu faucibus gravida, felis orci dictum risus, sed sodales sem eros eget risus. Morbi imperdiet sed diam et sodales. Vestibulum ut est id mauris ultrices gravida. Nulla malesuada metus ut erat malesuada, vitae ornare neque semper. Aenean a commodo justo, vel placerat odio. Curabitur vitae consequat tortor. Aenean eu magna ante. Integer tristique elit ac augue laoreet, eget pulvinar lacus dictum. Cras eleifend lacus eget pharetra elementum. Etiam fermentum eu felis eu tristique. Integer eu purus vitae turpis blandit consectetur. Nulla facilisi. Praesent bibendum massa eu metus pulvinar, quis tristique nunc commodo. Ut varius aliquam elit, a tincidunt elit aliquam non. Nunc ac leo purus. Proin condimentum placerat ligula, at tristique neque scelerisque ut. Suspendisse ut congue enim. Integer id sem nisl. Nam dignissim, lectus et dictum sollicitudin, libero augue ullamcorper justo, nec consectetur dolor arcu sed justo. Proin rutrum pharetra lectus, vel gravida ante venenatis sed. Mauris lacinia urna vehicula felis aliquet venenatis. Suspendisse non pretium sapien. Proin id dolor ultricies, dictum augue non, euismod ante. Vivamus et luctus augue, a luctus mi. Maecenas sit amet felis in magna vestibulum viverra vel ut est. Suspendisse potenti. Morbi nec odio pretium lacus laoreet volutpat sit amet at ipsum. Etiam pretium purus vitae tortor auctor, quis cursus metus vehicula. Integer ultricies facilisis arcu, non congue orci pharetra quis. Vivamus pulvinar ligula neque, et vehicula ipsum euismod quis."; - - // Split lorum ipsum words into an array - // - NSArray *lorumIpsumArray = [lorumIpsum componentsSeparatedByString:@" "]; - - // Randomly choose words for variable length - // - int r = arc4random() % [lorumIpsumArray count]; - r = MAX(3, r); // no less than 3 words - NSArray *lorumIpsumRandom = [lorumIpsumArray objectsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, r)]]; - - // Array to string. Adding '!!!' to end of string to ensure all text is visible. - // - return [NSString stringWithFormat:@"%@!!!", [lorumIpsumRandom componentsJoinedByString:@" "]]; - -} - -@end diff --git a/TableViewCellWithAutoLayout/TableViewController/RJTableViewCell.h b/TableViewCellWithAutoLayout/TableViewController/RJTableViewCell.h deleted file mode 100644 index f0bed4f..0000000 --- a/TableViewCellWithAutoLayout/TableViewController/RJTableViewCell.h +++ /dev/null @@ -1,36 +0,0 @@ -// -// RJCell.h -// TableViewController -// -// Created by Kevin Muldoon & Tyler Fox on 10/5/13. -// Copyright (c) 2013 RobotJackalope. All rights reserved. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// - -#import - -@interface RJTableViewCell : UITableViewCell - -@property (strong, nonatomic) IBOutlet UILabel *titleLabel; -@property (strong, nonatomic) IBOutlet UILabel *bodyLabel; - -- (void)updateFonts; - -@end diff --git a/TableViewCellWithAutoLayout/TableViewController/RJTableViewCell.m b/TableViewCellWithAutoLayout/TableViewController/RJTableViewCell.m deleted file mode 100644 index 4773da0..0000000 --- a/TableViewCellWithAutoLayout/TableViewController/RJTableViewCell.m +++ /dev/null @@ -1,107 +0,0 @@ -// -// RJCell.m -// TableViewController -// -// Created by Kevin Muldoon & Tyler Fox on 10/5/13. -// Copyright (c) 2013 RobotJackalope. All rights reserved. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// - -#import "RJTableViewCell.h" - -#define kLabelHorizontalInsets 15.0f -#define kLabelVerticalInsets 10.0f - -@interface RJTableViewCell () - -@property (nonatomic, assign) BOOL didSetupConstraints; - -@end - -@implementation RJTableViewCell - -- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier -{ - self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; - if (self) { - self.titleLabel = [UILabel newAutoLayoutView]; - [self.titleLabel setLineBreakMode:NSLineBreakByTruncatingTail]; - [self.titleLabel setNumberOfLines:1]; - [self.titleLabel setTextAlignment:NSTextAlignmentLeft]; - [self.titleLabel setTextColor:[UIColor blackColor]]; - self.titleLabel.backgroundColor = [UIColor colorWithRed:0 green:0 blue:1 alpha:0.1]; // light blue - - self.bodyLabel = [UILabel newAutoLayoutView]; - [self.bodyLabel setLineBreakMode:NSLineBreakByTruncatingTail]; - [self.bodyLabel setNumberOfLines:0]; - [self.bodyLabel setTextAlignment:NSTextAlignmentLeft]; - [self.bodyLabel setTextColor:[UIColor darkGrayColor]]; - self.bodyLabel.backgroundColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:0.1]; // light red - - self.contentView.backgroundColor = [UIColor colorWithRed:0 green:1 blue:0 alpha:0.1]; // light green - - [self.contentView addSubview:self.titleLabel]; - [self.contentView addSubview:self.bodyLabel]; - - [self updateFonts]; - } - - return self; -} - -- (void)updateConstraints -{ - [super updateConstraints]; - - if (self.didSetupConstraints) { - return; - } - - // Note: if the constraints you add below require a larger cell size than the current size (which is likely to be the default size {320, 44}), you'll get an exception. - // As a fix, you can temporarily increase the size of the cell's contentView so that this does not occur using code similar to the line below. - // See here for further discussion: https://github.com/Alex311/TableCellWithAutoLayout/commit/bde387b27e33605eeac3465475d2f2ff9775f163#commitcomment-4633188 - // self.contentView.bounds = CGRectMake(0.0f, 0.0f, 99999.0f, 99999.0f); - - [UIView autoSetPriority:UILayoutPriorityRequired forConstraints:^{ - [self.titleLabel autoSetContentCompressionResistancePriorityForAxis:ALAxisVertical]; - }]; - [self.titleLabel autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:kLabelVerticalInsets]; - [self.titleLabel autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:kLabelHorizontalInsets]; - [self.titleLabel autoPinEdgeToSuperviewEdge:ALEdgeTrailing withInset:kLabelHorizontalInsets]; - - [self.bodyLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.titleLabel withOffset:kLabelVerticalInsets]; - - [UIView autoSetPriority:UILayoutPriorityRequired forConstraints:^{ - [self.bodyLabel autoSetContentCompressionResistancePriorityForAxis:ALAxisVertical]; - }]; - [self.bodyLabel autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:kLabelHorizontalInsets]; - [self.bodyLabel autoPinEdgeToSuperviewEdge:ALEdgeTrailing withInset:kLabelHorizontalInsets]; - [self.bodyLabel autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:kLabelVerticalInsets]; - - self.didSetupConstraints = YES; -} - -- (void)updateFonts -{ - self.titleLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline]; - self.bodyLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleCaption2]; -} - -@end diff --git a/TableViewCellWithAutoLayout/TableViewController/RJTableViewController.h b/TableViewCellWithAutoLayout/TableViewController/RJTableViewController.h deleted file mode 100644 index 883ae51..0000000 --- a/TableViewCellWithAutoLayout/TableViewController/RJTableViewController.h +++ /dev/null @@ -1,31 +0,0 @@ -// -// RJTableViewController.h -// TableViewController -// -// Created by Kevin Muldoon & Tyler Fox on 10/5/13. -// Copyright (c) 2013 RobotJackalope. All rights reserved. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// - -#import - -@interface RJTableViewController : UITableViewController - -@end diff --git a/TableViewCellWithAutoLayout/TableViewController/RJTableViewController.m b/TableViewCellWithAutoLayout/TableViewController/RJTableViewController.m deleted file mode 100644 index d920481..0000000 --- a/TableViewCellWithAutoLayout/TableViewController/RJTableViewController.m +++ /dev/null @@ -1,163 +0,0 @@ -// -// RJTableViewController.m -// TableViewController -// -// Created by Kevin Muldoon & Tyler Fox on 10/5/13. -// Copyright (c) 2013 RobotJackalope. All rights reserved. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// - -#import "RJTableViewController.h" -#import "RJModel.h" -#import "RJTableViewCell.h" - -static NSString *CellIdentifier = @"CellIdentifier"; - -@interface RJTableViewController () - -@property (strong, nonatomic) RJModel *model; - -@end - -@implementation RJTableViewController - -- (id)initWithStyle:(UITableViewStyle)style -{ - self = [super initWithStyle:style]; - if (self) { - self.model = [[RJModel alloc] init]; - [self.model populateDataSource]; - } - return self; -} - -- (void)viewDidLoad -{ - [super viewDidLoad]; - - self.title = @"iOS 8 Self Sizing Cells"; - self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:@selector(clear:)]; - self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addRow:)]; - - self.tableView.allowsSelection = NO; - - [self.tableView registerClass:[RJTableViewCell class] forCellReuseIdentifier:CellIdentifier]; - - // Self-sizing table view cells in iOS 8 require that the rowHeight property of the table view be set to the constant UITableViewAutomaticDimension - self.tableView.rowHeight = UITableViewAutomaticDimension; - - // Self-sizing table view cells in iOS 8 are enabled when the estimatedRowHeight property of the table view is set to a non-zero value. - // Setting the estimated row height prevents the table view from calling tableView:heightForRowAtIndexPath: for every row in the table on first load; - // it will only be called as cells are about to scroll onscreen. This is a major performance optimization. - self.tableView.estimatedRowHeight = 44.0; // set this to whatever your "average" cell height is; it doesn't need to be very accurate -} - -- (void)viewDidAppear:(BOOL)animated -{ - [super viewDidAppear:animated]; - - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(contentSizeCategoryChanged:) - name:UIContentSizeCategoryDidChangeNotification - object:nil]; -} - -- (void)viewDidDisappear:(BOOL)animated -{ - [super viewDidDisappear:animated]; - - [[NSNotificationCenter defaultCenter] removeObserver:self - name:UIContentSizeCategoryDidChangeNotification - object:nil]; -} - -// This method is called when the Dynamic Type user setting changes (from the system Settings app) -- (void)contentSizeCategoryChanged:(NSNotification *)notification -{ - [self.tableView reloadData]; -} - -- (void)clear:(id)sender -{ - NSMutableArray *rowsToDelete = [NSMutableArray new]; - for (NSUInteger i = 0; i < [self.model.dataSource count]; i++) { - [rowsToDelete addObject:[NSIndexPath indexPathForRow:i inSection:0]]; - } - - self.model = [[RJModel alloc] init]; - - [self.tableView deleteRowsAtIndexPaths:rowsToDelete withRowAnimation:UITableViewRowAnimationAutomatic]; - - [self.tableView reloadData]; -} - -- (void)addRow:(id)sender -{ - [self.model addSingleItemToDataSource]; - - NSIndexPath *lastIndexPath = [NSIndexPath indexPathForRow:[self.model.dataSource count] - 1 inSection:0]; - [self.tableView insertRowsAtIndexPaths:@[lastIndexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; -} - -#pragma mark - Table view data source - -- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView -{ - return 1; -} - -- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section -{ - return [self.model.dataSource count]; -} - -- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath -{ - RJTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; - - // Configure the cell for this indexPath - [cell updateFonts]; - NSDictionary *dataSourceItem = [self.model.dataSource objectAtIndex:indexPath.row]; - cell.titleLabel.text = [dataSourceItem valueForKey:@"title"]; - cell.bodyLabel.text = [dataSourceItem valueForKey:@"body"]; - - // Make sure the constraints have been added to this cell, since it may have just been created from scratch - [cell setNeedsUpdateConstraints]; - [cell updateConstraintsIfNeeded]; - - return cell; -} - -/* -- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath -{ - // If you are just returning a constant value from this method, you should instead just set the table view's - // estimatedRowHeight property (in viewDidLoad or similar), which is even faster as the table view won't - // have to call this method for every row in the table view. - // - // Only implement this method if you have row heights that vary by extreme amounts and you notice the scroll indicator - // "jumping" as you scroll the table view when using a constant estimatedRowHeight. If you do implement this method, - // be sure to do as little work as possible to get a reasonably-accurate estimate. - - return 44.0; -} -*/ - -@end diff --git a/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift b/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift new file mode 100644 index 0000000..c8a9c54 --- /dev/null +++ b/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift @@ -0,0 +1,95 @@ +// +// TableViewCell.swift +// TableViewCellWithAutoLayout +// +// Copyright (c) 2014 Tyler Fox +// + +import UIKit +import PureLayout + +class TableViewCell: UITableViewCell +{ + // The CGFloat type annotation is necessary for these constants because they are passed as arguments to bridged Objective-C methods, + // and without making the type explicit these will be inferred to be type Double which is not compatible. + let kLabelHorizontalInsets: CGFloat = 15.0 + let kLabelVerticalInsets: CGFloat = 10.0 + + var didSetupConstraints = false + + var titleLabel: UILabel = UILabel.newAutoLayoutView() + var bodyLabel: UILabel = UILabel.newAutoLayoutView() + + override init(style: UITableViewCellStyle, reuseIdentifier: String!) + { + super.init(style: style, reuseIdentifier: reuseIdentifier) + + setupViews() + } + + required init?(coder aDecoder: NSCoder) + { + super.init(coder: aDecoder) + + setupViews() + } + + func setupViews() + { + titleLabel.lineBreakMode = .ByTruncatingTail + titleLabel.numberOfLines = 1 + titleLabel.textAlignment = .Left + titleLabel.textColor = UIColor.blackColor() + titleLabel.backgroundColor = UIColor(red: 0, green: 0, blue: 1, alpha: 0.1) // light blue + + bodyLabel.lineBreakMode = .ByTruncatingTail + bodyLabel.numberOfLines = 0 + bodyLabel.textAlignment = .Left + bodyLabel.textColor = UIColor.darkGrayColor() + bodyLabel.backgroundColor = UIColor(red: 1, green: 0, blue: 0, alpha: 0.1) // light red + + updateFonts() + + contentView.addSubview(titleLabel) + contentView.addSubview(bodyLabel) + + contentView.backgroundColor = UIColor(red: 0, green: 1, blue: 0, alpha: 0.1) // light green + } + + override func updateConstraints() + { + if !didSetupConstraints { + // Note: if the constraints you add below require a larger cell size than the current size (which is likely to be the default size {320, 44}), you'll get an exception. + // As a fix, you can temporarily increase the size of the cell's contentView so that this does not occur using code similar to the line below. + // See here for further discussion: https://github.com/Alex311/TableCellWithAutoLayout/commit/bde387b27e33605eeac3465475d2f2ff9775f163#commitcomment-4633188 + // contentView.bounds = CGRect(x: 0.0, y: 0.0, width: 99999.0, height: 99999.0) + + // Prevent the two UILabels from being compressed below their intrinsic content height + NSLayoutConstraint.autoSetPriority(UILayoutPriorityRequired) { + self.titleLabel.autoSetContentCompressionResistancePriorityForAxis(.Vertical) + self.bodyLabel.autoSetContentCompressionResistancePriorityForAxis(.Vertical) + } + + titleLabel.autoPinEdgeToSuperviewEdge(.Top, withInset: kLabelVerticalInsets) + titleLabel.autoPinEdgeToSuperviewEdge(.Leading, withInset: kLabelHorizontalInsets) + titleLabel.autoPinEdgeToSuperviewEdge(.Trailing, withInset: kLabelHorizontalInsets) + + // This constraint is an inequality so that if the cell is slightly taller than actually required, extra space will go here + bodyLabel.autoPinEdge(.Top, toEdge: .Bottom, ofView: titleLabel, withOffset: 10.0, relation: .GreaterThanOrEqual) + + bodyLabel.autoPinEdgeToSuperviewEdge(.Leading, withInset: kLabelHorizontalInsets) + bodyLabel.autoPinEdgeToSuperviewEdge(.Trailing, withInset: kLabelHorizontalInsets) + bodyLabel.autoPinEdgeToSuperviewEdge(.Bottom, withInset: kLabelVerticalInsets) + + didSetupConstraints = true + } + + super.updateConstraints() + } + + func updateFonts() + { + titleLabel.font = UIFont.preferredFontForTextStyle(UIFontTextStyleHeadline) + bodyLabel.font = UIFont.preferredFontForTextStyle(UIFontTextStyleCaption2) + } +} diff --git a/TableViewCellWithAutoLayout/TableViewController/TableViewCellWithAutoLayout-Bridging-Header.h b/TableViewCellWithAutoLayout/TableViewController/TableViewCellWithAutoLayout-Bridging-Header.h new file mode 100644 index 0000000..e11d920 --- /dev/null +++ b/TableViewCellWithAutoLayout/TableViewController/TableViewCellWithAutoLayout-Bridging-Header.h @@ -0,0 +1,3 @@ +// +// Use this file to import your target's public headers that you would like to expose to Swift. +// diff --git a/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift b/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift new file mode 100644 index 0000000..69de322 --- /dev/null +++ b/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift @@ -0,0 +1,150 @@ +// +// TableViewController.swift +// TableViewCellWithAutoLayout +// +// Copyright (c) 2014 Tyler Fox +// + +import UIKit + +class TableViewController: UITableViewController +{ + let kCellIdentifier = "CellIdentifier" + + var model = Model(populated: true) + + override func viewDidLoad() + { + super.viewDidLoad() + + title = "iOS 8 Self Sizing Cells" + navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Trash, target: self, action: #selector(TableViewController.clear)) + navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Add, target: self, action: #selector(TableViewController.addRow)) + + tableView.allowsSelection = false + + + + /****************************************************************** + SWITCH BETWEEN PROGRAMMATIC AND INTERFACE BUILDER LOADED CELLS + + Uncomment ONE of the two lines below to switch between approaches. + Make sure that the other line commented out - don't uncomment both! + *******************************************************************/ + tableView.registerClass(TableViewCell.self, forCellReuseIdentifier: kCellIdentifier) // uncomment this line to load table view cells programmatically +// tableView.registerNib(UINib(nibName: "NibTableViewCell", bundle: NSBundle.mainBundle()), forCellReuseIdentifier: kCellIdentifier) // uncomment this line to load table view cells from IB + + + + // Self-sizing table view cells in iOS 8 require that the rowHeight property of the table view be set to the constant UITableViewAutomaticDimension + tableView.rowHeight = UITableViewAutomaticDimension + + // Self-sizing table view cells in iOS 8 are enabled when the estimatedRowHeight property of the table view is set to a non-zero value. + // Setting the estimated row height prevents the table view from calling tableView:heightForRowAtIndexPath: for every row in the table on first load; + // it will only be called as cells are about to scroll onscreen. This is a major performance optimization. + tableView.estimatedRowHeight = 44.0 // set this to whatever your "average" cell height is; it doesn't need to be very accurate + } + + override func viewDidAppear(animated: Bool) + { + super.viewDidAppear(animated) + + NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(TableViewController.contentSizeCategoryChanged(_:)), name: UIContentSizeCategoryDidChangeNotification, object: nil) + } + + override func viewDidDisappear(animated: Bool) + { + super.viewDidDisappear(animated) + + NSNotificationCenter.defaultCenter().removeObserver(self, name: UIContentSizeCategoryDidChangeNotification, object: nil) + } + + // This function will be called when the Dynamic Type user setting changes (from the system Settings app) + func contentSizeCategoryChanged(notification: NSNotification) + { + tableView.reloadData() + } + + // Deletes all rows in the table view and replaces the model with a new empty one + func clear() + { + var rowsToDelete: [NSIndexPath] = [] + for i in 0.. Int + { + return 1 + } + + override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int + { + return model.dataArray.count + } + + override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell + { + // This will be the case for programmatically loaded cells (see viewDidLoad to switch approaches) + if let cell: TableViewCell = tableView.dequeueReusableCellWithIdentifier(kCellIdentifier) as? TableViewCell { + // Configure the cell for this indexPath + cell.updateFonts() + let modelItem = model.dataArray[indexPath.row] + cell.titleLabel.text = modelItem.title + cell.bodyLabel.text = modelItem.body + + // Make sure the constraints have been added to this cell, since it may have just been created from scratch + cell.setNeedsUpdateConstraints() + cell.updateConstraintsIfNeeded() + + return cell + } + + // This will be the case for interface builder loaded cells (see viewDidLoad to switch approaches) + if let cell: NibTableViewCell = tableView.dequeueReusableCellWithIdentifier(kCellIdentifier) as? NibTableViewCell { + // Configure the cell for this indexPath + cell.updateFonts() + let modelItem = model.dataArray[indexPath.row] + cell.titleLabel.text = modelItem.title + cell.bodyLabel.text = modelItem.body + + // Make sure the constraints have been added to this cell, since it may have just been created from scratch + cell.setNeedsUpdateConstraints() + cell.updateConstraintsIfNeeded() + + return cell + } + + assert(false, "The dequeued table view cell was of an unknown type!") + return UITableViewCell() + } + + /* + override func tableView(tableView: UITableView!, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath!) -> CGFloat + { + // If you are just returning a constant value from this method, you should instead just set the table view's + // estimatedRowHeight property (in viewDidLoad or similar), which is even faster as the table view won't + // have to call this method for every row in the table view. + // + // Only implement this method if you have row heights that vary by extreme amounts and you notice the scroll indicator + // "jumping" as you scroll the table view when using a constant estimatedRowHeight. If you do implement this method, + // be sure to do as little work as possible to get a reasonably-accurate estimate. + + return 44.0 + } + */ +} diff --git a/TableViewCellWithAutoLayout/UIView+AutoLayout/UIView+AutoLayout.h b/TableViewCellWithAutoLayout/UIView+AutoLayout/UIView+AutoLayout.h deleted file mode 100755 index ea34ad7..0000000 --- a/TableViewCellWithAutoLayout/UIView+AutoLayout/UIView+AutoLayout.h +++ /dev/null @@ -1,278 +0,0 @@ -// -// UIView+AutoLayout.h -// v2.0.0 -// https://github.com/smileyborg/UIView-AutoLayout -// -// Copyright (c) 2012 Richard Turton -// Copyright (c) 2013 Tyler Fox -// -// This code is distributed under the terms and conditions of the MIT license. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -// IN THE SOFTWARE. -// - -#import - -#pragma mark ALAttributes - -typedef NS_ENUM(NSInteger, ALEdge) { - ALEdgeLeft = NSLayoutAttributeLeft, // the left edge of the view - ALEdgeRight = NSLayoutAttributeRight, // the right edge of the view - ALEdgeTop = NSLayoutAttributeTop, // the top edge of the view - ALEdgeBottom = NSLayoutAttributeBottom, // the bottom edge of the view - ALEdgeLeading = NSLayoutAttributeLeading, // the leading edge of the view (left edge for left-to-right languages like English, right edge for right-to-left languages like Arabic) - ALEdgeTrailing = NSLayoutAttributeTrailing // the trailing edge of the view (right edge for left-to-right languages like English, left edge for right-to-left languages like Arabic) -}; - -typedef NS_ENUM(NSInteger, ALDimension) { - ALDimensionWidth = NSLayoutAttributeWidth, // the width of the view - ALDimensionHeight = NSLayoutAttributeHeight // the height of the view -}; - -typedef NS_ENUM(NSInteger, ALAxis) { - ALAxisVertical = NSLayoutAttributeCenterX, // a vertical line through the center of the view - ALAxisHorizontal = NSLayoutAttributeCenterY, // a horizontal line through the center of the view - ALAxisBaseline = NSLayoutAttributeBaseline // a horizontal line at the text baseline (not applicable to all views) -}; - -typedef void(^ALConstraintsBlock)(void); // a block of method calls to the UIView+AutoLayout category API - - -#pragma mark - UIView+AutoLayout - -/** - A category on UIView that provides a simple yet powerful interface for creating Auto Layout constraints. - */ -@interface UIView (AutoLayout) - - -#pragma mark Factory & Initializer Methods - -/** Creates and returns a new view that does not convert the autoresizing mask into constraints. */ -+ (instancetype)newAutoLayoutView; - -/** Initializes and returns a new view that does not convert the autoresizing mask into constraints. */ -- (instancetype)initForAutoLayout; - - -#pragma mark Set Constraint Priority - -/** Sets the constraint priority to the given value for all constraints created using the UIView+AutoLayout category API within the given constraints block. - NOTE: This method will have no effect (and will NOT set the priority) on constraints created or added using the SDK directly within the block! */ -+ (void)autoSetPriority:(UILayoutPriority)priority forConstraints:(ALConstraintsBlock)block; - - -#pragma mark Remove Constraints - -/** Removes the given constraint from the view it has been added to. */ -+ (void)autoRemoveConstraint:(NSLayoutConstraint *)constraint; - -/** Removes the given constraints from the views they have been added to. */ -+ (void)autoRemoveConstraints:(NSArray *)constraints; - -/** Removes all explicit constraints that affect the view. - WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method. - NOTE: This method preserves implicit constraints, such as intrinsic content size constraints, which you usually do not want to remove. */ -- (void)autoRemoveConstraintsAffectingView; - -/** Removes all constraints that affect the view, optionally including implicit constraints. - WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method. - NOTE: Implicit constraints are auto-generated lower priority constraints, and you usually do not want to remove these. */ -- (void)autoRemoveConstraintsAffectingViewIncludingImplicitConstraints:(BOOL)shouldRemoveImplicitConstraints; - -/** Recursively removes all explicit constraints that affect the view and its subviews. - WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method. - NOTE: This method preserves implicit constraints, such as intrinsic content size constraints, which you usually do not want to remove. */ -- (void)autoRemoveConstraintsAffectingViewAndSubviews; - -/** Recursively removes all constraints from the view and its subviews, optionally including implicit constraints. - WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method. - NOTE: Implicit constraints are auto-generated lower priority constraints, and you usually do not want to remove these. */ -- (void)autoRemoveConstraintsAffectingViewAndSubviewsIncludingImplicitConstraints:(BOOL)shouldRemoveImplicitConstraints; - - -#pragma mark Center in Superview - -/** Centers the view in its superview. */ -- (NSArray *)autoCenterInSuperview; - -/** Aligns the view to the same axis of its superview. */ -- (NSLayoutConstraint *)autoAlignAxisToSuperviewAxis:(ALAxis)axis; - - -#pragma mark Pin Edges to Superview - -/** Pins the given edge of the view to the same edge of the superview with an inset. */ -- (NSLayoutConstraint *)autoPinEdgeToSuperviewEdge:(ALEdge)edge withInset:(CGFloat)inset; - -/** Pins the given edge of the view to the same edge of the superview with an inset as a maximum or minimum. */ -- (NSLayoutConstraint *)autoPinEdgeToSuperviewEdge:(ALEdge)edge withInset:(CGFloat)inset relation:(NSLayoutRelation)relation; - -/** Pins the edges of the view to the edges of its superview with the given edge insets. */ -- (NSArray *)autoPinEdgesToSuperviewEdgesWithInsets:(UIEdgeInsets)insets; - -/** Pins 3 of the 4 edges of the view to the edges of its superview with the given edge insets, excluding one edge. */ -- (NSArray *)autoPinEdgesToSuperviewEdgesWithInsets:(UIEdgeInsets)insets excludingEdge:(ALEdge)edge; - - -#pragma mark Pin Edges - -/** Pins an edge of the view to a given edge of another view. */ -- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(UIView *)peerView; - -/** Pins an edge of the view to a given edge of another view with an offset. */ -- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(UIView *)peerView withOffset:(CGFloat)offset; - -/** Pins an edge of the view to a given edge of another view with an offset as a maximum or minimum. */ -- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(UIView *)peerView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation; - - -#pragma mark Align Axes - -/** Aligns an axis of the view to the same axis of another view. */ -- (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(UIView *)peerView; - -/** Aligns an axis of the view to the same axis of another view with an offset. */ -- (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(UIView *)peerView withOffset:(CGFloat)offset; - - -#pragma mark Match Dimensions - -/** Matches a dimension of the view to a given dimension of another view. */ -- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(UIView *)peerView; - -/** Matches a dimension of the view to a given dimension of another view with an offset. */ -- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(UIView *)peerView withOffset:(CGFloat)offset; - -/** Matches a dimension of the view to a given dimension of another view with an offset as a maximum or minimum. */ -- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(UIView *)peerView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation; - -/** Matches a dimension of the view to a multiple of a given dimension of another view. */ -- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(UIView *)peerView withMultiplier:(CGFloat)multiplier; - -/** Matches a dimension of the view to a multiple of a given dimension of another view as a maximum or minimum. */ -- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(UIView *)peerView withMultiplier:(CGFloat)multiplier relation:(NSLayoutRelation)relation; - - -#pragma mark Set Dimensions - -/** Sets the view to a specific size. */ -- (NSArray *)autoSetDimensionsToSize:(CGSize)size; - -/** Sets the given dimension of the view to a specific size. */ -- (NSLayoutConstraint *)autoSetDimension:(ALDimension)dimension toSize:(CGFloat)size; - -/** Sets the given dimension of the view to a specific size as a maximum or minimum. */ -- (NSLayoutConstraint *)autoSetDimension:(ALDimension)dimension toSize:(CGFloat)size relation:(NSLayoutRelation)relation; - - -#pragma mark Set Content Compression Resistance & Hugging - -/** Sets the priority of content compression resistance for an axis. - NOTE: This method must only be called from within the block passed into the method +[UIView autoSetPriority:forConstraints:] */ -- (void)autoSetContentCompressionResistancePriorityForAxis:(ALAxis)axis; - -/** Sets the priority of content hugging for an axis. - NOTE: This method must only be called from within the block passed into the method +[UIView autoSetPriority:forConstraints:] */ -- (void)autoSetContentHuggingPriorityForAxis:(ALAxis)axis; - - -#pragma mark Constrain Any Attributes - -/** Constrains an attribute (any ALEdge, ALAxis, or ALDimension) of the view to a given attribute of another view. */ -- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)attribute toAttribute:(NSInteger)toAttribute ofView:(UIView *)peerView; - -/** Constrains an attribute (any ALEdge, ALAxis, or ALDimension) of the view to a given attribute of another view with an offset. */ -- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)attribute toAttribute:(NSInteger)toAttribute ofView:(UIView *)peerView withOffset:(CGFloat)offset; - -/** Constrains an attribute (any ALEdge, ALAxis, or ALDimension) of the view to a given attribute of another view with an offset as a maximum or minimum. */ -- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)attribute toAttribute:(NSInteger)toAttribute ofView:(UIView *)peerView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation; - -/** Constrains an attribute (any ALEdge, ALAxis, or ALDimension) of the view to a given attribute of another view with a multiplier. */ -- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)attribute toAttribute:(NSInteger)toAttribute ofView:(UIView *)peerView withMultiplier:(CGFloat)multiplier; - -/** Constrains an attribute (any ALEdge, ALAxis, or ALDimension) of the view to a given attribute of another view with a multiplier as a maximum or minimum. */ -- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)attribute toAttribute:(NSInteger)toAttribute ofView:(UIView *)peerView withMultiplier:(CGFloat)multiplier relation:(NSLayoutRelation)relation; - - -#pragma mark Pin to Layout Guides - -/** Pins the top edge of the view to the top layout guide of the given view controller with an inset. */ -- (NSLayoutConstraint *)autoPinToTopLayoutGuideOfViewController:(UIViewController *)viewController withInset:(CGFloat)inset; - -/** Pins the bottom edge of the view to the bottom layout guide of the given view controller with an inset. */ -- (NSLayoutConstraint *)autoPinToBottomLayoutGuideOfViewController:(UIViewController *)viewController withInset:(CGFloat)inset; - -@end - - -#pragma mark - NSArray+AutoLayout - -/** - A category on NSArray that provides a simple yet powerful interface for applying constraints to groups of views. - */ -@interface NSArray (AutoLayout) - - -#pragma mark Constrain Multiple Views - -/** Aligns views in this array to one another along a given edge. */ -- (NSArray *)autoAlignViewsToEdge:(ALEdge)edge; - -/** Aligns views in this array to one another along a given axis. */ -- (NSArray *)autoAlignViewsToAxis:(ALAxis)axis; - -/** Matches a given dimension of all the views in this array. */ -- (NSArray *)autoMatchViewsDimension:(ALDimension)dimension; - -/** Sets the given dimension of all the views in this array to a given size. */ -- (NSArray *)autoSetViewsDimension:(ALDimension)dimension toSize:(CGFloat)size; - - -#pragma mark Distribute Multiple Views - -/** Distributes the views in this array equally along the selected axis in their superview. Views will be the same size (variable) in the dimension along the axis and will have spacing (fixed) between them. */ -- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSpacing:(CGFloat)spacing alignment:(NSLayoutFormatOptions)alignment; - -/** Distributes the views in this array equally along the selected axis in their superview. Views will be the same size (variable) in the dimension along the axis and will have spacing (fixed) between them, with optional insets from the first and last views to their superview. */ -- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSpacing:(CGFloat)spacing insetSpacing:(BOOL)shouldSpaceInsets alignment:(NSLayoutFormatOptions)alignment; - -/** Distributes the views in this array equally along the selected axis in their superview. Views will be the same size (fixed) in the dimension along the axis and will have spacing (variable) between them. */ -- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSize:(CGFloat)size alignment:(NSLayoutFormatOptions)alignment; - -/** Distributes the views in this array equally along the selected axis in their superview. Views will be the same size (fixed) in the dimension along the axis and will have spacing (variable) between them, with optional insets from the first and last views to their superview. */ -- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSize:(CGFloat)size insetSpacing:(BOOL)shouldSpaceInsets alignment:(NSLayoutFormatOptions)alignment; - -@end - - -#pragma mark - NSLayoutConstraint+AutoLayout - -/** - A category on NSLayoutConstraint that allows constraints to be easily removed. - */ -@interface NSLayoutConstraint (AutoLayout) - -/** Adds the constraint to the appropriate view. */ -- (void)autoInstall; - -/** Removes the constraint from the view it has been added to. */ -- (void)autoRemove; - -@end diff --git a/TableViewCellWithAutoLayout/UIView+AutoLayout/UIView+AutoLayout.m b/TableViewCellWithAutoLayout/UIView+AutoLayout/UIView+AutoLayout.m deleted file mode 100755 index d529a38..0000000 --- a/TableViewCellWithAutoLayout/UIView+AutoLayout/UIView+AutoLayout.m +++ /dev/null @@ -1,1318 +0,0 @@ -// -// UIView+AutoLayout.m -// v2.0.0 -// https://github.com/smileyborg/UIView-AutoLayout -// -// Copyright (c) 2012 Richard Turton -// Copyright (c) 2013 Tyler Fox -// -// This code is distributed under the terms and conditions of the MIT license. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -// IN THE SOFTWARE. -// - -#import "UIView+AutoLayout.h" - - -#pragma mark - UIView+AutoLayout - -@implementation UIView (AutoLayout) - - -#pragma mark Factory & Initializer Methods - -/** - Creates and returns a new view that does not convert the autoresizing mask into constraints. - */ -+ (instancetype)newAutoLayoutView -{ - UIView *view = [self new]; - view.translatesAutoresizingMaskIntoConstraints = NO; - return view; -} - -/** - Initializes and returns a new view that does not convert the autoresizing mask into constraints. - */ -- (instancetype)initForAutoLayout -{ - self = [self init]; - if (self) { - self.translatesAutoresizingMaskIntoConstraints = NO; - } - return self; -} - - -#pragma mark Set Constraint Priority - -/** - A global variable that determines the priority of all constraints created and added by this category. - Defaults to Required, will only be a different value while executing a constraints block passed into the - +[UIView autoSetPriority:forConstraints:] method (as that method will reset the value back to Required - before returning). - NOTE: As UIKit is not thread safe, access to this variable is not synchronized (and should only be done - on the main thread). - */ -static UILayoutPriority _al_globalConstraintPriority = UILayoutPriorityRequired; - -/** - A global variable that is set to YES while the constraints block passed in to the - +[UIView autoSetPriority:forConstraints:] method is executing. - NOTE: As UIKit is not thread safe, access to this variable is not synchronized (and should only be done - on the main thread). - */ -static BOOL _al_isExecutingConstraintsBlock = NO; - -/** - Sets the constraint priority to the given value for all constraints created using the UIView+AutoLayout - category API within the given constraints block. - - NOTE: This method will have no effect (and will NOT set the priority) on constraints created or added - using the SDK directly within the block! - - @param priority The layout priority to be set on all constraints in the constraints block. - @param block A block of method calls to the UIView+AutoLayout API that create and add constraints. - */ -+ (void)autoSetPriority:(UILayoutPriority)priority forConstraints:(ALConstraintsBlock)block -{ - NSAssert(block, @"The constraints block cannot be nil."); - if (block) { - _al_globalConstraintPriority = priority; - _al_isExecutingConstraintsBlock = YES; - block(); - _al_isExecutingConstraintsBlock = NO; - _al_globalConstraintPriority = UILayoutPriorityRequired; - } -} - - -#pragma mark Remove Constraints - -/** - Removes the given constraint from the view it has been added to. - - @param constraint The constraint to remove. - */ -+ (void)autoRemoveConstraint:(NSLayoutConstraint *)constraint -{ - if (constraint.secondItem) { - UIView *commonSuperview = [constraint.firstItem al_commonSuperviewWithView:constraint.secondItem]; - while (commonSuperview) { - if ([commonSuperview.constraints containsObject:constraint]) { - [commonSuperview removeConstraint:constraint]; - return; - } - commonSuperview = commonSuperview.superview; - } - } - else { - [constraint.firstItem removeConstraint:constraint]; - return; - } - NSAssert(nil, @"Failed to remove constraint: %@", constraint); -} - -/** - Removes the given constraints from the views they have been added to. - - @param constraints The constraints to remove. - */ -+ (void)autoRemoveConstraints:(NSArray *)constraints -{ - for (id object in constraints) { - if ([object isKindOfClass:[NSLayoutConstraint class]]) { - [self autoRemoveConstraint:((NSLayoutConstraint *)object)]; - } else { - NSAssert(nil, @"All constraints to remove must be instances of NSLayoutConstraint."); - } - } -} - -/** - Removes all explicit constraints that affect the view. - WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method. - It is not recommended to use this method to "reset" a view for reuse in a different way with new constraints. Create a new view instead. - NOTE: This method preserves implicit constraints, such as intrinsic content size constraints, which you usually do not want to remove. - */ -- (void)autoRemoveConstraintsAffectingView -{ - [self autoRemoveConstraintsAffectingViewIncludingImplicitConstraints:NO]; -} - -/** - Removes all constraints that affect the view, optionally including implicit constraints. - WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method. - It is not recommended to use this method to "reset" a view for reuse in a different way with new constraints. Create a new view instead. - NOTE: Implicit constraints are auto-generated lower priority constraints (such as those that attempt to keep a view at - its intrinsic content size by hugging its content & resisting compression), and you usually do not want to remove these. - - @param shouldRemoveImplicitConstraints Whether implicit constraints should be removed or skipped. - */ -- (void)autoRemoveConstraintsAffectingViewIncludingImplicitConstraints:(BOOL)shouldRemoveImplicitConstraints -{ - NSMutableArray *constraintsToRemove = [NSMutableArray new]; - UIView *startView = self; - do { - for (NSLayoutConstraint *constraint in startView.constraints) { - BOOL isImplicitConstraint = [NSStringFromClass([constraint class]) isEqualToString:@"NSContentSizeLayoutConstraint"]; - if (shouldRemoveImplicitConstraints || !isImplicitConstraint) { - if (constraint.firstItem == self || constraint.secondItem == self) { - [constraintsToRemove addObject:constraint]; - } - } - } - startView = startView.superview; - } while (startView); - [UIView autoRemoveConstraints:constraintsToRemove]; -} - -/** - Recursively removes all explicit constraints that affect the view and its subviews. - WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method. - It is not recommended to use this method to "reset" views for reuse in a different way with new constraints. Create a new view instead. - NOTE: This method preserves implicit constraints, such as intrinsic content size constraints, which you usually do not want to remove. - */ -- (void)autoRemoveConstraintsAffectingViewAndSubviews -{ - [self autoRemoveConstraintsAffectingViewAndSubviewsIncludingImplicitConstraints:NO]; -} - -/** - Recursively removes all constraints that affect the view and its subviews, optionally including implicit constraints. - WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method. - It is not recommended to use this method to "reset" views for reuse in a different way with new constraints. Create a new view instead. - NOTE: Implicit constraints are auto-generated lower priority constraints (such as those that attempt to keep a view at - its intrinsic content size by hugging its content & resisting compression), and you usually do not want to remove these. - - @param shouldRemoveImplicitConstraints Whether implicit constraints should be removed or skipped. - */ -- (void)autoRemoveConstraintsAffectingViewAndSubviewsIncludingImplicitConstraints:(BOOL)shouldRemoveImplicitConstraints -{ - [self autoRemoveConstraintsAffectingViewIncludingImplicitConstraints:shouldRemoveImplicitConstraints]; - for (UIView *subview in self.subviews) { - [subview autoRemoveConstraintsAffectingViewAndSubviewsIncludingImplicitConstraints:shouldRemoveImplicitConstraints]; - } -} - - -#pragma mark Center in Superview - -/** - Centers the view in its superview. - - @return An array of constraints added. - */ -- (NSArray *)autoCenterInSuperview -{ - NSMutableArray *constraints = [NSMutableArray new]; - [constraints addObject:[self autoAlignAxisToSuperviewAxis:ALAxisHorizontal]]; - [constraints addObject:[self autoAlignAxisToSuperviewAxis:ALAxisVertical]]; - return constraints; -} - -/** - Aligns the view to the same axis of its superview. - - @param axis The axis of this view and of its superview to align. - @return The constraint added. - */ -- (NSLayoutConstraint *)autoAlignAxisToSuperviewAxis:(ALAxis)axis -{ - self.translatesAutoresizingMaskIntoConstraints = NO; - UIView *superview = self.superview; - NSAssert(superview, @"View's superview must not be nil.\nView: %@", self); - NSLayoutAttribute attribute = [UIView al_attributeForAxis:axis]; - NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:attribute relatedBy:NSLayoutRelationEqual toItem:superview attribute:attribute multiplier:1.0f constant:0.0f]; - [constraint autoInstall]; - return constraint; -} - - -#pragma mark Pin Edges to Superview - -/** - Pins the given edge of the view to the same edge of the superview with an inset. - - @param edge The edge of this view and the superview to pin. - @param inset The amount to inset this view's edge from the superview's edge. - @return The constraint added. - */ -- (NSLayoutConstraint *)autoPinEdgeToSuperviewEdge:(ALEdge)edge withInset:(CGFloat)inset -{ - return [self autoPinEdgeToSuperviewEdge:edge withInset:inset relation:NSLayoutRelationEqual]; -} - -/** - Pins the given edge of the view to the same edge of the superview with an inset as a maximum or minimum. - - @param edge The edge of this view and the superview to pin. - @param inset The amount to inset this view's edge from the superview's edge. - @param relation Whether the inset should be at least, at most, or exactly equal to the given value. - @return The constraint added. - */ -- (NSLayoutConstraint *)autoPinEdgeToSuperviewEdge:(ALEdge)edge withInset:(CGFloat)inset relation:(NSLayoutRelation)relation -{ - self.translatesAutoresizingMaskIntoConstraints = NO; - UIView *superview = self.superview; - NSAssert(superview, @"View's superview must not be nil.\nView: %@", self); - if (edge == ALEdgeBottom || edge == ALEdgeRight || edge == ALEdgeTrailing) { - // The bottom, right, and trailing insets (and relations, if an inequality) are inverted to become offsets - inset = -inset; - if (relation == NSLayoutRelationLessThanOrEqual) { - relation = NSLayoutRelationGreaterThanOrEqual; - } else if (relation == NSLayoutRelationGreaterThanOrEqual) { - relation = NSLayoutRelationLessThanOrEqual; - } - } - return [self autoPinEdge:edge toEdge:edge ofView:superview withOffset:inset relation:relation]; -} - -/** - Pins the edges of the view to the edges of its superview with the given edge insets. - The insets.left corresponds to a leading edge constraint, and insets.right corresponds to a trailing edge constraint. - - @param insets The insets for this view's edges from the superview's edges. - @return An array of constraints added. - */ -- (NSArray *)autoPinEdgesToSuperviewEdgesWithInsets:(UIEdgeInsets)insets -{ - NSMutableArray *constraints = [NSMutableArray new]; - [constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:insets.top]]; - [constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:insets.left]]; - [constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:insets.bottom]]; - [constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeTrailing withInset:insets.right]]; - return constraints; -} - -/** - Pins 3 of the 4 edges of the view to the edges of its superview with the given edge insets, excluding one edge. - The insets.left corresponds to a leading edge constraint, and insets.right corresponds to a trailing edge constraint. - - @param insets The insets for this view's edges from the superview's edges. The inset corresponding to the excluded edge - will be ignored. - @param edge The edge of this view to exclude in pinning to the superview; this method will not apply any constraint to it. - @return An array of constraints added. - */ -- (NSArray *)autoPinEdgesToSuperviewEdgesWithInsets:(UIEdgeInsets)insets excludingEdge:(ALEdge)edge -{ - NSMutableArray *constraints = [NSMutableArray new]; - if (edge != ALEdgeTop) { - [constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:insets.top]]; - } - if (edge != ALEdgeLeading && edge != ALEdgeLeft) { - [constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:insets.left]]; - } - if (edge != ALEdgeBottom) { - [constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:insets.bottom]]; - } - if (edge != ALEdgeTrailing && edge != ALEdgeRight) { - [constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeTrailing withInset:insets.right]]; - } - return constraints; -} - - -#pragma mark Pin Edges - -/** - Pins an edge of the view to a given edge of another view. - - @param edge The edge of this view to pin. - @param toEdge The edge of the peer view to pin to. - @param peerView The peer view to pin to. Must be in the same view hierarchy as this view. - @return The constraint added. - */ -- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(UIView *)peerView -{ - return [self autoPinEdge:edge toEdge:toEdge ofView:peerView withOffset:0.0f]; -} - -/** - Pins an edge of the view to a given edge of another view with an offset. - - @param edge The edge of this view to pin. - @param toEdge The edge of the peer view to pin to. - @param peerView The peer view to pin to. Must be in the same view hierarchy as this view. - @param offset The offset between the edge of this view and the edge of the peer view. - @return The constraint added. - */ -- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(UIView *)peerView withOffset:(CGFloat)offset -{ - return [self autoPinEdge:edge toEdge:toEdge ofView:peerView withOffset:offset relation:NSLayoutRelationEqual]; -} - -/** - Pins an edge of the view to a given edge of another view with an offset as a maximum or minimum. - - @param edge The edge of this view to pin. - @param toEdge The edge of the peer view to pin to. - @param peerView The peer view to pin to. Must be in the same view hierarchy as this view. - @param offset The offset between the edge of this view and the edge of the peer view. - @param relation Whether the offset should be at least, at most, or exactly equal to the given value. - @return The constraint added. - */ -- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(UIView *)peerView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation -{ - self.translatesAutoresizingMaskIntoConstraints = NO; - NSLayoutAttribute attribute = [UIView al_attributeForEdge:edge]; - NSLayoutAttribute toAttribute = [UIView al_attributeForEdge:toEdge]; - NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:attribute relatedBy:relation toItem:peerView attribute:toAttribute multiplier:1.0f constant:offset]; - [constraint autoInstall]; - return constraint; -} - - -#pragma mark Align Axes - -/** - Aligns an axis of the view to the same axis of another view. - - @param axis The axis of this view and the peer view to align. - @param peerView The peer view to align to. Must be in the same view hierarchy as this view. - @return The constraint added. - */ -- (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(UIView *)peerView -{ - return [self autoAlignAxis:axis toSameAxisOfView:peerView withOffset:0.0f]; -} - -/** - Aligns an axis of the view to the same axis of another view with an offset. - - @param axis The axis of this view and the peer view to align. - @param peerView The peer view to align to. Must be in the same view hierarchy as this view. - @param offset The offset between the axis of this view and the axis of the peer view. - @return The constraint added. - */ -- (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(UIView *)peerView withOffset:(CGFloat)offset -{ - self.translatesAutoresizingMaskIntoConstraints = NO; - NSLayoutAttribute attribute = [UIView al_attributeForAxis:axis]; - NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:attribute relatedBy:NSLayoutRelationEqual toItem:peerView attribute:attribute multiplier:1.0f constant:offset]; - [constraint autoInstall]; - return constraint; -} - - -#pragma mark Match Dimensions - -/** - Matches a dimension of the view to a given dimension of another view. - - @param dimension The dimension of this view to pin. - @param toDimension The dimension of the peer view to pin to. - @param peerView The peer view to match to. Must be in the same view hierarchy as this view. - @return The constraint added. - */ -- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(UIView *)peerView -{ - return [self autoMatchDimension:dimension toDimension:toDimension ofView:peerView withOffset:0.0f]; -} - -/** - Matches a dimension of the view to a given dimension of another view with an offset. - - @param dimension The dimension of this view to pin. - @param toDimension The dimension of the peer view to pin to. - @param peerView The peer view to match to. Must be in the same view hierarchy as this view. - @param offset The offset between the dimension of this view and the dimension of the peer view. - @return The constraint added. - */ -- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(UIView *)peerView withOffset:(CGFloat)offset -{ - return [self autoMatchDimension:dimension toDimension:toDimension ofView:peerView withOffset:offset relation:NSLayoutRelationEqual]; -} - -/** - Matches a dimension of the view to a given dimension of another view with an offset as a maximum or minimum. - - @param dimension The dimension of this view to pin. - @param toDimension The dimension of the peer view to pin to. - @param peerView The peer view to match to. Must be in the same view hierarchy as this view. - @param offset The offset between the dimension of this view and the dimension of the peer view. - @param relation Whether the offset should be at least, at most, or exactly equal to the given value. - @return The constraint added. - */ -- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(UIView *)peerView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation -{ - self.translatesAutoresizingMaskIntoConstraints = NO; - NSLayoutAttribute attribute = [UIView al_attributeForDimension:dimension]; - NSLayoutAttribute toAttribute = [UIView al_attributeForDimension:toDimension]; - NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:attribute relatedBy:relation toItem:peerView attribute:toAttribute multiplier:1.0f constant:offset]; - [constraint autoInstall]; - return constraint; -} - -/** - Matches a dimension of the view to a multiple of a given dimension of another view. - - @param dimension The dimension of this view to pin. - @param toDimension The dimension of the peer view to pin to. - @param peerView The peer view to match to. Must be in the same view hierarchy as this view. - @param multiplier The multiple of the peer view's given dimension that this view's given dimension should be. - @return The constraint added. - */ -- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(UIView *)peerView withMultiplier:(CGFloat)multiplier -{ - return [self autoMatchDimension:dimension toDimension:toDimension ofView:peerView withMultiplier:multiplier relation:NSLayoutRelationEqual]; -} - -/** - Matches a dimension of the view to a multiple of a given dimension of another view as a maximum or minimum. - - @param dimension The dimension of this view to pin. - @param toDimension The dimension of the peer view to pin to. - @param peerView The peer view to match to. Must be in the same view hierarchy as this view. - @param multiplier The multiple of the peer view's given dimension that this view's given dimension should be. - @param relation Whether the multiple should be at least, at most, or exactly equal to the given value. - @return The constraint added. - */ -- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(UIView *)peerView withMultiplier:(CGFloat)multiplier relation:(NSLayoutRelation)relation -{ - self.translatesAutoresizingMaskIntoConstraints = NO; - NSLayoutAttribute attribute = [UIView al_attributeForDimension:dimension]; - NSLayoutAttribute toAttribute = [UIView al_attributeForDimension:toDimension]; - NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:attribute relatedBy:relation toItem:peerView attribute:toAttribute multiplier:multiplier constant:0.0f]; - [constraint autoInstall]; - return constraint; -} - - -#pragma mark Set Dimensions - -/** - Sets the view to a specific size. - - @param size The size to set this view's dimensions to. - @return An array of constraints added. - */ -- (NSArray *)autoSetDimensionsToSize:(CGSize)size -{ - NSMutableArray *constraints = [NSMutableArray new]; - [constraints addObject:[self autoSetDimension:ALDimensionWidth toSize:size.width]]; - [constraints addObject:[self autoSetDimension:ALDimensionHeight toSize:size.height]]; - return constraints; -} - -/** - Sets the given dimension of the view to a specific size. - - @param dimension The dimension of this view to set. - @param size The size to set the given dimension to. - @return The constraint added. - */ -- (NSLayoutConstraint *)autoSetDimension:(ALDimension)dimension toSize:(CGFloat)size -{ - return [self autoSetDimension:dimension toSize:size relation:NSLayoutRelationEqual]; -} - -/** - Sets the given dimension of the view to a specific size as a maximum or minimum. - - @param dimension The dimension of this view to set. - @param size The size to set the given dimension to. - @param relation Whether the size should be at least, at most, or exactly equal to the given value. - @return The constraint added. - */ -- (NSLayoutConstraint *)autoSetDimension:(ALDimension)dimension toSize:(CGFloat)size relation:(NSLayoutRelation)relation -{ - self.translatesAutoresizingMaskIntoConstraints = NO; - NSLayoutAttribute attribute = [UIView al_attributeForDimension:dimension]; - NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:attribute relatedBy:relation toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0.0f constant:size]; - [constraint autoInstall]; - return constraint; -} - - -#pragma mark Set Content Compression Resistance & Hugging - -/** - Sets the priority of content compression resistance for an axis. - NOTE: This method must only be called from within the block passed into the method +[UIView autoSetPriority:forConstraints:] - - @param axis The axis to set the content compression resistance priority for. - */ -- (void)autoSetContentCompressionResistancePriorityForAxis:(ALAxis)axis -{ - NSAssert(_al_isExecutingConstraintsBlock, @"%@ should only be called from within the block passed into the method +[UIView autoSetPriority:forConstraints:]", NSStringFromSelector(_cmd)); - if (_al_isExecutingConstraintsBlock) { - self.translatesAutoresizingMaskIntoConstraints = NO; - UILayoutConstraintAxis constraintAxis = [UIView al_constraintAxisForAxis:axis]; - [self setContentCompressionResistancePriority:_al_globalConstraintPriority forAxis:constraintAxis]; - } -} - -/** - Sets the priority of content hugging for an axis. - NOTE: This method must only be called from within the block passed into the method +[UIView autoSetPriority:forConstraints:] - - @param axis The axis to set the content hugging priority for. - */ -- (void)autoSetContentHuggingPriorityForAxis:(ALAxis)axis -{ - NSAssert(_al_isExecutingConstraintsBlock, @"%@ should only be called from within the block passed into the method +[UIView autoSetPriority:forConstraints:]", NSStringFromSelector(_cmd)); - if (_al_isExecutingConstraintsBlock) { - self.translatesAutoresizingMaskIntoConstraints = NO; - UILayoutConstraintAxis constraintAxis = [UIView al_constraintAxisForAxis:axis]; - [self setContentHuggingPriority:_al_globalConstraintPriority forAxis:constraintAxis]; - } -} - - -#pragma mark Constrain Any Attributes - -/** - Constrains an attribute (any ALEdge, ALAxis, or ALDimension) of the view to a given attribute of another view. - This method can be used to constrain different types of attributes across two views. - - @param ALAttribute Any ALEdge, ALAxis, or ALDimension of this view to constrain. - @param toALAttribute Any ALEdge, ALAxis, or ALDimension of the peer view to constrain to. - @param peerView The peer view to constrain to. Must be in the same view hierarchy as this view. - @return The constraint added. - */ -- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)ALAttribute toAttribute:(NSInteger)toALAttribute ofView:(UIView *)peerView -{ - return [self autoConstrainAttribute:ALAttribute toAttribute:toALAttribute ofView:peerView withOffset:0.0f]; -} - -/** - Constrains an attribute (any ALEdge, ALAxis, or ALDimension) of the view to a given attribute of another view with an offset. - This method can be used to constrain different types of attributes across two views. - - @param ALAttribute Any ALEdge, ALAxis, or ALDimension of this view to constrain. - @param toALAttribute Any ALEdge, ALAxis, or ALDimension of the peer view to constrain to. - @param peerView The peer view to constrain to. Must be in the same view hierarchy as this view. - @param offset The offset between the attribute of this view and the attribute of the peer view. - @return The constraint added. - */ -- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)ALAttribute toAttribute:(NSInteger)toALAttribute ofView:(UIView *)peerView withOffset:(CGFloat)offset -{ - return [self autoConstrainAttribute:ALAttribute toAttribute:toALAttribute ofView:peerView withOffset:offset relation:NSLayoutRelationEqual]; -} - -/** - Constrains an attribute (any ALEdge, ALAxis, or ALDimension) of the view to a given attribute of another view with an offset as a maximum or minimum. - This method can be used to constrain different types of attributes across two views. - - @param ALAttribute Any ALEdge, ALAxis, or ALDimension of this view to constrain. - @param toALAttribute Any ALEdge, ALAxis, or ALDimension of the peer view to constrain to. - @param peerView The peer view to constrain to. Must be in the same view hierarchy as this view. - @param offset The offset between the attribute of this view and the attribute of the peer view. - @param relation Whether the offset should be at least, at most, or exactly equal to the given value. - @return The constraint added. - */ -- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)ALAttribute toAttribute:(NSInteger)toALAttribute ofView:(UIView *)peerView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation -{ - self.translatesAutoresizingMaskIntoConstraints = NO; - NSLayoutAttribute attribute = [UIView al_attributeForALAttribute:ALAttribute]; - NSLayoutAttribute toAttribute = [UIView al_attributeForALAttribute:toALAttribute]; - NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:attribute relatedBy:relation toItem:peerView attribute:toAttribute multiplier:1.0f constant:offset]; - [constraint autoInstall]; - return constraint; -} - -/** - Constrains an attribute (any ALEdge, ALAxis, or ALDimension) of the view to a given attribute of another view with a multiplier. - This method can be used to constrain different types of attributes across two views. - - @param ALAttribute Any ALEdge, ALAxis, or ALDimension of this view to constrain. - @param toALAttribute Any ALEdge, ALAxis, or ALDimension of the peer view to constrain to. - @param peerView The peer view to constrain to. Must be in the same view hierarchy as this view. - @param multiplier The multiplier between the attribute of this view and the attribute of the peer view. - @return The constraint added. - */ -- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)ALAttribute toAttribute:(NSInteger)toALAttribute ofView:(UIView *)peerView withMultiplier:(CGFloat)multiplier -{ - return [self autoConstrainAttribute:ALAttribute toAttribute:toALAttribute ofView:peerView withMultiplier:multiplier relation:NSLayoutRelationEqual]; -} - -/** - Constrains an attribute (any ALEdge, ALAxis, or ALDimension) of the view to a given attribute of another view with a multiplier as a maximum or minimum. - This method can be used to constrain different types of attributes across two views. - - @param ALAttribute Any ALEdge, ALAxis, or ALDimension of this view to constrain. - @param toALAttribute Any ALEdge, ALAxis, or ALDimension of the peer view to constrain to. - @param peerView The peer view to constrain to. Must be in the same view hierarchy as this view. - @param multiplier The multiplier between the attribute of this view and the attribute of the peer view. - @param relation Whether the multiplier should be at least, at most, or exactly equal to the given value. - @return The constraint added. - */ -- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)ALAttribute toAttribute:(NSInteger)toALAttribute ofView:(UIView *)peerView withMultiplier:(CGFloat)multiplier relation:(NSLayoutRelation)relation -{ - self.translatesAutoresizingMaskIntoConstraints = NO; - NSLayoutAttribute attribute = [UIView al_attributeForALAttribute:ALAttribute]; - NSLayoutAttribute toAttribute = [UIView al_attributeForALAttribute:toALAttribute]; - NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:attribute relatedBy:relation toItem:peerView attribute:toAttribute multiplier:multiplier constant:0.0f]; - [constraint autoInstall]; - return constraint; -} - - -#pragma mark Pin to Layout Guides - -/** - Pins the top edge of the view to the top layout guide of the given view controller with an inset. - For compatibility with iOS 6 (where layout guides do not exist), this method will simply pin the top edge of - the view to the top edge of the given view controller's view with an inset. - - @param viewController The view controller whose topLayoutGuide should be used to pin to. - @param inset The amount to inset this view's top edge from the layout guide. - @return The constraint added. - */ -- (NSLayoutConstraint *)autoPinToTopLayoutGuideOfViewController:(UIViewController *)viewController withInset:(CGFloat)inset -{ - if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) { - return [self autoPinEdge:ALEdgeTop toEdge:ALEdgeTop ofView:viewController.view withOffset:inset]; - } else { - self.translatesAutoresizingMaskIntoConstraints = NO; - NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:viewController.topLayoutGuide attribute:NSLayoutAttributeBottom multiplier:1.0f constant:inset]; - [viewController.view al_addConstraintUsingGlobalPriority:constraint]; - return constraint; - } -} - -/** - Pins the bottom edge of the view to the bottom layout guide of the given view controller with an inset. - For compatibility with iOS 6 (where layout guides do not exist), this method will simply pin the bottom edge of - the view to the bottom edge of the given view controller's view with an inset. - - @param viewController The view controller whose bottomLayoutGuide should be used to pin to. - @param inset The amount to inset this view's bottom edge from the layout guide. - @return The constraint added. - */ -- (NSLayoutConstraint *)autoPinToBottomLayoutGuideOfViewController:(UIViewController *)viewController withInset:(CGFloat)inset -{ - if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) { - return [self autoPinEdge:ALEdgeBottom toEdge:ALEdgeBottom ofView:viewController.view withOffset:-inset]; - } else { - self.translatesAutoresizingMaskIntoConstraints = NO; - NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:viewController.bottomLayoutGuide attribute:NSLayoutAttributeTop multiplier:1.0f constant:-inset]; - [viewController.view al_addConstraintUsingGlobalPriority:constraint]; - return constraint; - } -} - - -#pragma mark Internal Helper Methods - -/** - Adds the given constraint to this view after setting the constraint's priority to the global constraint priority. - - This method is the only one that calls the SDK addConstraint: method directly; all other instances in this category - should use this method to add constraints so that the global priority is correctly set on constraints. - - @param constraint The constraint to set the global priority on and then add to this view. - */ -- (void)al_addConstraintUsingGlobalPriority:(NSLayoutConstraint *)constraint -{ - constraint.priority = _al_globalConstraintPriority; - [self addConstraint:constraint]; -} - -/** - Returns the corresponding NSLayoutAttribute for the given ALEdge. - - @return The layout attribute for the given edge. - */ -+ (NSLayoutAttribute)al_attributeForEdge:(ALEdge)edge -{ - NSLayoutAttribute attribute = NSLayoutAttributeNotAnAttribute; - switch (edge) { - case ALEdgeLeft: - attribute = NSLayoutAttributeLeft; - break; - case ALEdgeRight: - attribute = NSLayoutAttributeRight; - break; - case ALEdgeTop: - attribute = NSLayoutAttributeTop; - break; - case ALEdgeBottom: - attribute = NSLayoutAttributeBottom; - break; - case ALEdgeLeading: - attribute = NSLayoutAttributeLeading; - break; - case ALEdgeTrailing: - attribute = NSLayoutAttributeTrailing; - break; - default: - NSAssert(nil, @"Not a valid ALEdge."); - break; - } - return attribute; -} - -/** - Returns the corresponding NSLayoutAttribute for the given ALAxis. - - @return The layout attribute for the given axis. - */ -+ (NSLayoutAttribute)al_attributeForAxis:(ALAxis)axis -{ - NSLayoutAttribute attribute = NSLayoutAttributeNotAnAttribute; - switch (axis) { - case ALAxisVertical: - attribute = NSLayoutAttributeCenterX; - break; - case ALAxisHorizontal: - attribute = NSLayoutAttributeCenterY; - break; - case ALAxisBaseline: - attribute = NSLayoutAttributeBaseline; - break; - default: - NSAssert(nil, @"Not a valid ALAxis."); - break; - } - return attribute; -} - -/** - Returns the corresponding NSLayoutAttribute for the given ALDimension. - - @return The layout attribute for the given dimension. - */ -+ (NSLayoutAttribute)al_attributeForDimension:(ALDimension)dimension -{ - NSLayoutAttribute attribute = NSLayoutAttributeNotAnAttribute; - switch (dimension) { - case ALDimensionWidth: - attribute = NSLayoutAttributeWidth; - break; - case ALDimensionHeight: - attribute = NSLayoutAttributeHeight; - break; - default: - NSAssert(nil, @"Not a valid ALDimension."); - break; - } - return attribute; -} - -/** - Returns the corresponding NSLayoutAttribute for the given ALAttribute. - - @return The layout attribute for the given ALAttribute. - */ -+ (NSLayoutAttribute)al_attributeForALAttribute:(NSInteger)ALAttribute -{ - NSLayoutAttribute attribute = NSLayoutAttributeNotAnAttribute; - switch (ALAttribute) { - case ALEdgeLeft: - attribute = NSLayoutAttributeLeft; - break; - case ALEdgeRight: - attribute = NSLayoutAttributeRight; - break; - case ALEdgeTop: - attribute = NSLayoutAttributeTop; - break; - case ALEdgeBottom: - attribute = NSLayoutAttributeBottom; - break; - case ALEdgeLeading: - attribute = NSLayoutAttributeLeading; - break; - case ALEdgeTrailing: - attribute = NSLayoutAttributeTrailing; - break; - case ALDimensionWidth: - attribute = NSLayoutAttributeWidth; - break; - case ALDimensionHeight: - attribute = NSLayoutAttributeHeight; - break; - case ALAxisVertical: - attribute = NSLayoutAttributeCenterX; - break; - case ALAxisHorizontal: - attribute = NSLayoutAttributeCenterY; - break; - case ALAxisBaseline: - attribute = NSLayoutAttributeBaseline; - break; - default: - NSAssert(nil, @"Not a valid ALAttribute."); - break; - } - return attribute; -} - -/** - Returns the corresponding UILayoutConstraintAxis for the given ALAxis. - - @return The constraint axis for the given axis. - */ -+ (UILayoutConstraintAxis)al_constraintAxisForAxis:(ALAxis)axis -{ - UILayoutConstraintAxis constraintAxis; - switch (axis) { - case ALAxisVertical: - constraintAxis = UILayoutConstraintAxisVertical; - break; - case ALAxisHorizontal: - case ALAxisBaseline: - constraintAxis = UILayoutConstraintAxisHorizontal; - break; - default: - NSAssert(nil, @"Not a valid ALAxis."); - break; - } - return constraintAxis; -} - -/** - Returns the common superview for this view and the given peer view. - Raises an exception if this view and the peer view do not share a common superview. - - @return The common superview for the two views. - */ -- (UIView *)al_commonSuperviewWithView:(UIView *)peerView -{ - UIView *commonSuperview = nil; - UIView *startView = self; - do { - if ([peerView isDescendantOfView:startView]) { - commonSuperview = startView; - } - startView = startView.superview; - } while (startView && !commonSuperview); - NSAssert(commonSuperview, @"Can't constrain two views that do not share a common superview. Make sure that both views have been added into the same view hierarchy."); - return commonSuperview; -} - -/** - Aligns this view to a peer view with an alignment option. - - @param peerView The peer view to align to. - @param alignment The alignment option to apply to the two views. - @param axis The axis along which the views are distributed, used to validate the alignment option. - @return The constraint added. - */ -- (NSLayoutConstraint *)al_alignToView:(UIView *)peerView withOption:(NSLayoutFormatOptions)alignment forAxis:(ALAxis)axis -{ - NSLayoutConstraint *constraint = nil; - switch (alignment) { - case NSLayoutFormatAlignAllCenterX: - NSAssert(axis == ALAxisVertical, @"Cannot align views that are distributed horizontally with NSLayoutFormatAlignAllCenterX."); - constraint = [self autoAlignAxis:ALAxisVertical toSameAxisOfView:peerView]; - break; - case NSLayoutFormatAlignAllCenterY: - NSAssert(axis != ALAxisVertical, @"Cannot align views that are distributed vertically with NSLayoutFormatAlignAllCenterY."); - constraint = [self autoAlignAxis:ALAxisHorizontal toSameAxisOfView:peerView]; - break; - case NSLayoutFormatAlignAllBaseline: - NSAssert(axis != ALAxisVertical, @"Cannot align views that are distributed vertically with NSLayoutFormatAlignAllBaseline."); - constraint = [self autoAlignAxis:ALAxisBaseline toSameAxisOfView:peerView]; - break; - case NSLayoutFormatAlignAllTop: - NSAssert(axis != ALAxisVertical, @"Cannot align views that are distributed vertically with NSLayoutFormatAlignAllTop."); - constraint = [self autoPinEdge:ALEdgeTop toEdge:ALEdgeTop ofView:peerView]; - break; - case NSLayoutFormatAlignAllLeft: - NSAssert(axis == ALAxisVertical, @"Cannot align views that are distributed horizontally with NSLayoutFormatAlignAllLeft."); - constraint = [self autoPinEdge:ALEdgeLeft toEdge:ALEdgeLeft ofView:peerView]; - break; - case NSLayoutFormatAlignAllBottom: - NSAssert(axis != ALAxisVertical, @"Cannot align views that are distributed vertically with NSLayoutFormatAlignAllBottom."); - constraint = [self autoPinEdge:ALEdgeBottom toEdge:ALEdgeBottom ofView:peerView]; - break; - case NSLayoutFormatAlignAllRight: - NSAssert(axis == ALAxisVertical, @"Cannot align views that are distributed horizontally with NSLayoutFormatAlignAllRight."); - constraint = [self autoPinEdge:ALEdgeRight toEdge:ALEdgeRight ofView:peerView]; - break; - case NSLayoutFormatAlignAllLeading: - NSAssert(axis == ALAxisVertical, @"Cannot align views that are distributed horizontally with NSLayoutFormatAlignAllLeading."); - constraint = [self autoPinEdge:ALEdgeLeading toEdge:ALEdgeLeading ofView:peerView]; - break; - case NSLayoutFormatAlignAllTrailing: - NSAssert(axis == ALAxisVertical, @"Cannot align views that are distributed horizontally with NSLayoutFormatAlignAllTrailing."); - constraint = [self autoPinEdge:ALEdgeTrailing toEdge:ALEdgeTrailing ofView:peerView]; - break; - default: - NSAssert(nil, @"Unsupported alignment option."); - break; - } - return constraint; -} - -@end - - -#pragma mark - NSArray+AutoLayout - -@implementation NSArray (AutoLayout) - - -#pragma mark Constrain Multiple Views - -/** - Aligns views in this array to one another along a given edge. - Note: This array must contain at least 2 views, and all views must share a common superview. - - @param edge The edge to which the subviews will be aligned. - @return An array of constraints added. - */ -- (NSArray *)autoAlignViewsToEdge:(ALEdge)edge -{ - NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views."); - NSMutableArray *constraints = [NSMutableArray new]; - UIView *previousView = nil; - for (id object in self) { - if ([object isKindOfClass:[UIView class]]) { - UIView *view = (UIView *)object; - view.translatesAutoresizingMaskIntoConstraints = NO; - if (previousView) { - [constraints addObject:[view autoPinEdge:edge toEdge:edge ofView:previousView]]; - } - previousView = view; - } - } - return constraints; -} - -/** - Aligns views in this array to one another along a given axis. - Note: This array must contain at least 2 views, and all views must share a common superview. - - @param axis The axis to which to subviews will be aligned. - @return An array of constraints added. - */ -- (NSArray *)autoAlignViewsToAxis:(ALAxis)axis -{ - NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views."); - NSMutableArray *constraints = [NSMutableArray new]; - UIView *previousView = nil; - for (id object in self) { - if ([object isKindOfClass:[UIView class]]) { - UIView *view = (UIView *)object; - view.translatesAutoresizingMaskIntoConstraints = NO; - if (previousView) { - [constraints addObject:[view autoAlignAxis:axis toSameAxisOfView:previousView]]; - } - previousView = view; - } - } - return constraints; -} - -/** - Matches a given dimension of all the views in this array. - Note: This array must contain at least 2 views, and all views must share a common superview. - - @param dimension The dimension to match for all of the subviews. - @return An array of constraints added. - */ -- (NSArray *)autoMatchViewsDimension:(ALDimension)dimension -{ - NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views."); - NSMutableArray *constraints = [NSMutableArray new]; - UIView *previousView = nil; - for (id object in self) { - if ([object isKindOfClass:[UIView class]]) { - UIView *view = (UIView *)object; - view.translatesAutoresizingMaskIntoConstraints = NO; - if (previousView) { - [constraints addObject:[view autoMatchDimension:dimension toDimension:dimension ofView:previousView]]; - } - previousView = view; - } - } - return constraints; -} - -/** - Sets the given dimension of all the views in this array to a given size. - Note: This array must contain at least 1 view. - - @param dimension The dimension of each of the subviews to set. - @param size The size to set the given dimension of each subview to. - @return An array of constraints added. - */ -- (NSArray *)autoSetViewsDimension:(ALDimension)dimension toSize:(CGFloat)size -{ - NSAssert([self al_containsMinimumNumberOfViews:1], @"This array must contain at least 1 view."); - NSMutableArray *constraints = [NSMutableArray new]; - for (id object in self) { - if ([object isKindOfClass:[UIView class]]) { - UIView *view = (UIView *)object; - view.translatesAutoresizingMaskIntoConstraints = NO; - [constraints addObject:[view autoSetDimension:dimension toSize:size]]; - } - } - return constraints; -} - - -#pragma mark Distribute Multiple Views - -/** - Distributes the views in this array equally along the selected axis in their superview. - Views will be the same size (variable) in the dimension along the axis and will have spacing (fixed) between them, - including from the first and last views to their superview. - - @param axis The axis along which to distribute the subviews. - @param spacing The fixed amount of spacing between each subview, before the first subview and after the last subview. - @param alignment The way in which the subviews will be aligned. - @return An array of constraints added. - */ -- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSpacing:(CGFloat)spacing alignment:(NSLayoutFormatOptions)alignment -{ - return [self autoDistributeViewsAlongAxis:axis withFixedSpacing:spacing insetSpacing:YES alignment:alignment]; -} - -/** - Distributes the views in this array equally along the selected axis in their superview. - Views will be the same size (variable) in the dimension along the axis and will have spacing (fixed) between them. - The first and last views can optionally be inset from their superview by the same amount of spacing as between views. - - @param axis The axis along which to distribute the subviews. - @param spacing The fixed amount of spacing between each subview. - @param shouldSpaceInsets Whether the first and last views should be equally inset from their superview. - @param alignment The way in which the subviews will be aligned. - @return An array of constraints added. - */ -- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSpacing:(CGFloat)spacing insetSpacing:(BOOL)shouldSpaceInsets alignment:(NSLayoutFormatOptions)alignment -{ - NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views to distribute."); - ALDimension matchedDimension; - ALEdge firstEdge, lastEdge; - switch (axis) { - case ALAxisHorizontal: - case ALAxisBaseline: - matchedDimension = ALDimensionWidth; - firstEdge = ALEdgeLeading; - lastEdge = ALEdgeTrailing; - break; - case ALAxisVertical: - matchedDimension = ALDimensionHeight; - firstEdge = ALEdgeTop; - lastEdge = ALEdgeBottom; - break; - default: - NSAssert(nil, @"Not a valid ALAxis."); - return nil; - } - CGFloat leadingSpacing = shouldSpaceInsets ? spacing : 0.0; - CGFloat trailingSpacing = shouldSpaceInsets ? spacing : 0.0; - - NSMutableArray *constraints = [NSMutableArray new]; - UIView *previousView = nil; - for (id object in self) { - if ([object isKindOfClass:[UIView class]]) { - UIView *view = (UIView *)object; - view.translatesAutoresizingMaskIntoConstraints = NO; - if (previousView) { - // Second, Third, ... View - [constraints addObject:[view autoPinEdge:firstEdge toEdge:lastEdge ofView:previousView withOffset:spacing]]; - [constraints addObject:[view autoMatchDimension:matchedDimension toDimension:matchedDimension ofView:previousView]]; - [constraints addObject:[view al_alignToView:previousView withOption:alignment forAxis:axis]]; - } - else { - // First view - [constraints addObject:[view autoPinEdgeToSuperviewEdge:firstEdge withInset:leadingSpacing]]; - } - previousView = view; - } - } - if (previousView) { - // Last View - [constraints addObject:[previousView autoPinEdgeToSuperviewEdge:lastEdge withInset:trailingSpacing]]; - } - return constraints; -} - -/** - Distributes the views in this array equally along the selected axis in their superview. - Views will be the same size (fixed) in the dimension along the axis and will have spacing (variable) between them, - including from the first and last views to their superview. - - @param axis The axis along which to distribute the subviews. - @param size The fixed size of each subview in the dimension along the given axis. - @param alignment The way in which the subviews will be aligned. - @return An array of constraints added. - */ -- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSize:(CGFloat)size alignment:(NSLayoutFormatOptions)alignment -{ - return [self autoDistributeViewsAlongAxis:axis withFixedSize:size insetSpacing:YES alignment:alignment]; -} - -/** - Distributes the views in this array equally along the selected axis in their superview. - Views will be the same size (fixed) in the dimension along the axis and will have spacing (variable) between them. - The first and last views can optionally be inset from their superview by the same amount of spacing as between views. - - @param axis The axis along which to distribute the subviews. - @param size The fixed size of each subview in the dimension along the given axis. - @param shouldSpaceInsets Whether the first and last views should be equally inset from their superview. - @param alignment The way in which the subviews will be aligned. - @return An array of constraints added. - */ -- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSize:(CGFloat)size insetSpacing:(BOOL)shouldSpaceInsets alignment:(NSLayoutFormatOptions)alignment -{ - NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views to distribute."); - ALDimension fixedDimension; - NSLayoutAttribute attribute; - switch (axis) { - case ALAxisHorizontal: - case ALAxisBaseline: - fixedDimension = ALDimensionWidth; - attribute = NSLayoutAttributeCenterX; - break; - case ALAxisVertical: - fixedDimension = ALDimensionHeight; - attribute = NSLayoutAttributeCenterY; - break; - default: - NSAssert(nil, @"Not a valid ALAxis."); - return nil; - } - BOOL isRightToLeftLanguage = [NSLocale characterDirectionForLanguage:[[NSBundle mainBundle] preferredLocalizations][0]] == NSLocaleLanguageDirectionRightToLeft; - BOOL shouldFlipOrder = isRightToLeftLanguage && (axis != ALAxisVertical); // imitate the effect of leading/trailing when distributing horizontally - - NSMutableArray *constraints = [NSMutableArray new]; - NSArray *views = [self al_copyViewsOnly]; - NSUInteger numberOfViews = [views count]; - UIView *commonSuperview = [views al_commonSuperviewOfViews]; - UIView *previousView = nil; - for (NSUInteger i = 0; i < numberOfViews; i++) { - UIView *view = shouldFlipOrder ? views[numberOfViews - i - 1] : views[i]; - view.translatesAutoresizingMaskIntoConstraints = NO; - [constraints addObject:[view autoSetDimension:fixedDimension toSize:size]]; - CGFloat multiplier, constant; - if (shouldSpaceInsets) { - multiplier = (i * 2.0f + 2.0f) / (numberOfViews + 1.0f); - constant = (multiplier - 1.0f) * size / 2.0f; - } else { - multiplier = (i * 2.0f) / (numberOfViews - 1.0f); - constant = (-multiplier + 1.0f) * size / 2.0f; - } - NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:view attribute:attribute relatedBy:NSLayoutRelationEqual toItem:commonSuperview attribute:attribute multiplier:multiplier constant:constant]; - [commonSuperview al_addConstraintUsingGlobalPriority:constraint]; - [constraints addObject:constraint]; - if (previousView) { - [constraints addObject:[view al_alignToView:previousView withOption:alignment forAxis:axis]]; - } - previousView = view; - } - return constraints; -} - -#pragma mark Internal Helper Methods - -/** - Returns the common superview for the views in this array. - Raises an exception if the views in this array do not share a common superview. - - @return The common superview for the views in this array. - */ -- (UIView *)al_commonSuperviewOfViews -{ - UIView *commonSuperview = nil; - UIView *previousView = nil; - for (id object in self) { - if ([object isKindOfClass:[UIView class]]) { - UIView *view = (UIView *)object; - if (previousView) { - commonSuperview = [view al_commonSuperviewWithView:commonSuperview]; - } else { - commonSuperview = view; - } - previousView = view; - } - } - NSAssert(commonSuperview, @"Can't constrain views that do not share a common superview. Make sure that all the views in this array have been added into the same view hierarchy."); - return commonSuperview; -} - -/** - Determines whether this array contains a minimum number of views. - - @param minimumNumberOfViews The minimum number of views to check for. - @return YES if this array contains at least the minimum number of views, NO otherwise. - */ -- (BOOL)al_containsMinimumNumberOfViews:(NSUInteger)minimumNumberOfViews -{ - NSUInteger numberOfViews = 0; - for (id object in self) { - if ([object isKindOfClass:[UIView class]]) { - numberOfViews++; - if (numberOfViews >= minimumNumberOfViews) { - return YES; - } - } - } - return numberOfViews >= minimumNumberOfViews; -} - -/** - Creates a copy of this array containing only the view objects in it. - - @return A new array containing only the views that are in this array. - */ -- (NSArray *)al_copyViewsOnly -{ - NSMutableArray *viewsOnlyArray = [NSMutableArray arrayWithCapacity:[self count]]; - for (id object in self) { - if ([object isKindOfClass:[UIView class]]) { - [viewsOnlyArray addObject:object]; - } - } - return viewsOnlyArray; -} - -@end - - -#pragma mark - NSLayoutConstraint+AutoLayout - -@implementation NSLayoutConstraint (AutoLayout) - -/** - Adds the constraint to the appropriate view. - */ -- (void)autoInstall -{ - NSAssert(self.firstItem || self.secondItem, @"Can't install a constraint with nil firstItem and secondItem."); - if (self.firstItem) { - if (self.secondItem) { - NSAssert([self.firstItem isKindOfClass:[UIView class]] && [self.secondItem isKindOfClass:[UIView class]], @"Can only automatically install a constraint if both items are views."); - UIView *commonSuperview = [self.firstItem al_commonSuperviewWithView:self.secondItem]; - [commonSuperview al_addConstraintUsingGlobalPriority:self]; - } else { - NSAssert([self.firstItem isKindOfClass:[UIView class]], @"Can only automatically install a constraint if the item is a view."); - [self.firstItem al_addConstraintUsingGlobalPriority:self]; - } - } else { - NSAssert([self.secondItem isKindOfClass:[UIView class]], @"Can only automatically install a constraint if the item is a view."); - [self.secondItem al_addConstraintUsingGlobalPriority:self]; - } -} - -/** - Removes the constraint from the view it has been added to. - */ -- (void)autoRemove -{ - [UIView autoRemoveConstraint:self]; -} - -@end diff --git a/TableViewCellWithAutoLayout/main.m b/TableViewCellWithAutoLayout/main.m deleted file mode 100644 index 9989d84..0000000 --- a/TableViewCellWithAutoLayout/main.m +++ /dev/null @@ -1,18 +0,0 @@ -// -// main.m -// TableViewCellWithAutoLayout -// -// Created by Kevin Muldoon on 10/5/13. -// Copyright (c) 2013 RobotJackalope. All rights reserved. -// - -#import - -#import "RJAppDelegate.h" - -int main(int argc, char * argv[]) -{ - @autoreleasepool { - return UIApplicationMain(argc, argv, nil, NSStringFromClass([RJAppDelegate class])); - } -} diff --git a/TableViewCellWithAutoLayoutTests/TableViewCellWithAutoLayoutTests-Info.plist b/TableViewCellWithAutoLayoutTests/TableViewCellWithAutoLayoutTests-Info.plist index 2d0aa3f..169b6f7 100644 --- a/TableViewCellWithAutoLayoutTests/TableViewCellWithAutoLayoutTests-Info.plist +++ b/TableViewCellWithAutoLayoutTests/TableViewCellWithAutoLayoutTests-Info.plist @@ -7,7 +7,7 @@ CFBundleExecutable ${EXECUTABLE_NAME} CFBundleIdentifier - com.robotjackalope.${PRODUCT_NAME:rfc1034identifier} + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundlePackageType