From 55094ab1ba8ca6199f9889a4a0467c50beb78ccc Mon Sep 17 00:00:00 2001 From: Dan Date: Wed, 26 Apr 2017 20:32:38 +0800 Subject: [PATCH] first commit --- .gitignore | 15 + .../project.pbxproj | 334 ++++++++++++++++++ DLSimpleAutolayoutDemo/AppDelegate.h | 17 + DLSimpleAutolayoutDemo/AppDelegate.m | 51 +++ .../AppIcon.appiconset/Contents.json | 68 ++++ .../Base.lproj/LaunchScreen.storyboard | 27 ++ .../Base.lproj/Main.storyboard | 50 +++ .../DLSimpleAutolayout/DLSimpleAutolayout.h | 56 +++ .../DLSimpleAutolayout/DLSimpleAutolayout.m | 245 +++++++++++++ DLSimpleAutolayoutDemo/Info.plist | 45 +++ DLSimpleAutolayoutDemo/ViewController.h | 15 + DLSimpleAutolayoutDemo/ViewController.m | 66 ++++ DLSimpleAutolayoutDemo/main.m | 16 + README.md | 0 14 files changed, 1005 insertions(+) create mode 100644 .gitignore create mode 100644 DLSimpleAutolayoutDemo.xcodeproj/project.pbxproj create mode 100644 DLSimpleAutolayoutDemo/AppDelegate.h create mode 100644 DLSimpleAutolayoutDemo/AppDelegate.m create mode 100644 DLSimpleAutolayoutDemo/Assets.xcassets/AppIcon.appiconset/Contents.json create mode 100644 DLSimpleAutolayoutDemo/Base.lproj/LaunchScreen.storyboard create mode 100644 DLSimpleAutolayoutDemo/Base.lproj/Main.storyboard create mode 100644 DLSimpleAutolayoutDemo/DLSimpleAutolayout/DLSimpleAutolayout.h create mode 100644 DLSimpleAutolayoutDemo/DLSimpleAutolayout/DLSimpleAutolayout.m create mode 100644 DLSimpleAutolayoutDemo/Info.plist create mode 100644 DLSimpleAutolayoutDemo/ViewController.h create mode 100644 DLSimpleAutolayoutDemo/ViewController.m create mode 100644 DLSimpleAutolayoutDemo/main.m create mode 100644 README.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..42fceca --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +#cocoapods +Pods + +#project +**/*.xccheckout +**/*.xcscmblueprint +**/contents.xcworkspacedata +**/xcuserdata/* + +#merge +**/*.orig + +#build +Release +Products \ No newline at end of file diff --git a/DLSimpleAutolayoutDemo.xcodeproj/project.pbxproj b/DLSimpleAutolayoutDemo.xcodeproj/project.pbxproj new file mode 100644 index 0000000..9eac1e7 --- /dev/null +++ b/DLSimpleAutolayoutDemo.xcodeproj/project.pbxproj @@ -0,0 +1,334 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 37C8A5101EB0C64400DDFCC0 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 37C8A50F1EB0C64400DDFCC0 /* main.m */; }; + 37C8A5131EB0C64400DDFCC0 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 37C8A5121EB0C64400DDFCC0 /* AppDelegate.m */; }; + 37C8A5161EB0C64400DDFCC0 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 37C8A5151EB0C64400DDFCC0 /* ViewController.m */; }; + 37C8A5191EB0C64400DDFCC0 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 37C8A5171EB0C64400DDFCC0 /* Main.storyboard */; }; + 37C8A51B1EB0C64400DDFCC0 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 37C8A51A1EB0C64400DDFCC0 /* Assets.xcassets */; }; + 37C8A51E1EB0C64400DDFCC0 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 37C8A51C1EB0C64400DDFCC0 /* LaunchScreen.storyboard */; }; + 37C8A5271EB0C69100DDFCC0 /* DLSimpleAutolayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 37C8A5261EB0C69100DDFCC0 /* DLSimpleAutolayout.m */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 37C8A50B1EB0C64400DDFCC0 /* DLSimpleAutolayoutDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DLSimpleAutolayoutDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 37C8A50F1EB0C64400DDFCC0 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + 37C8A5111EB0C64400DDFCC0 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; + 37C8A5121EB0C64400DDFCC0 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; + 37C8A5141EB0C64400DDFCC0 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; + 37C8A5151EB0C64400DDFCC0 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; + 37C8A5181EB0C64400DDFCC0 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 37C8A51A1EB0C64400DDFCC0 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 37C8A51D1EB0C64400DDFCC0 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + 37C8A51F1EB0C64400DDFCC0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 37C8A5251EB0C69100DDFCC0 /* DLSimpleAutolayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DLSimpleAutolayout.h; path = DLSimpleAutolayout/DLSimpleAutolayout.h; sourceTree = ""; }; + 37C8A5261EB0C69100DDFCC0 /* DLSimpleAutolayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = DLSimpleAutolayout.m; path = DLSimpleAutolayout/DLSimpleAutolayout.m; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 37C8A5081EB0C64400DDFCC0 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 37C8A5021EB0C64400DDFCC0 = { + isa = PBXGroup; + children = ( + 37C8A50D1EB0C64400DDFCC0 /* DLSimpleAutolayoutDemo */, + 37C8A50C1EB0C64400DDFCC0 /* Products */, + ); + sourceTree = ""; + }; + 37C8A50C1EB0C64400DDFCC0 /* Products */ = { + isa = PBXGroup; + children = ( + 37C8A50B1EB0C64400DDFCC0 /* DLSimpleAutolayoutDemo.app */, + ); + name = Products; + sourceTree = ""; + }; + 37C8A50D1EB0C64400DDFCC0 /* DLSimpleAutolayoutDemo */ = { + isa = PBXGroup; + children = ( + 37C8A5111EB0C64400DDFCC0 /* AppDelegate.h */, + 37C8A5121EB0C64400DDFCC0 /* AppDelegate.m */, + 37C8A5141EB0C64400DDFCC0 /* ViewController.h */, + 37C8A5151EB0C64400DDFCC0 /* ViewController.m */, + 37C8A5171EB0C64400DDFCC0 /* Main.storyboard */, + 37C8A51A1EB0C64400DDFCC0 /* Assets.xcassets */, + 37C8A51C1EB0C64400DDFCC0 /* LaunchScreen.storyboard */, + 37C8A51F1EB0C64400DDFCC0 /* Info.plist */, + 37C8A50E1EB0C64400DDFCC0 /* Supporting Files */, + 37C8A5281EB0C69A00DDFCC0 /* DLSimpleAutolayout */, + ); + path = DLSimpleAutolayoutDemo; + sourceTree = ""; + }; + 37C8A50E1EB0C64400DDFCC0 /* Supporting Files */ = { + isa = PBXGroup; + children = ( + 37C8A50F1EB0C64400DDFCC0 /* main.m */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; + 37C8A5281EB0C69A00DDFCC0 /* DLSimpleAutolayout */ = { + isa = PBXGroup; + children = ( + 37C8A5251EB0C69100DDFCC0 /* DLSimpleAutolayout.h */, + 37C8A5261EB0C69100DDFCC0 /* DLSimpleAutolayout.m */, + ); + name = DLSimpleAutolayout; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 37C8A50A1EB0C64400DDFCC0 /* DLSimpleAutolayoutDemo */ = { + isa = PBXNativeTarget; + buildConfigurationList = 37C8A5221EB0C64400DDFCC0 /* Build configuration list for PBXNativeTarget "DLSimpleAutolayoutDemo" */; + buildPhases = ( + 37C8A5071EB0C64400DDFCC0 /* Sources */, + 37C8A5081EB0C64400DDFCC0 /* Frameworks */, + 37C8A5091EB0C64400DDFCC0 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = DLSimpleAutolayoutDemo; + productName = DLSimpleAutolayoutDemo; + productReference = 37C8A50B1EB0C64400DDFCC0 /* DLSimpleAutolayoutDemo.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 37C8A5031EB0C64400DDFCC0 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0830; + ORGANIZATIONNAME = "Dan Lee"; + TargetAttributes = { + 37C8A50A1EB0C64400DDFCC0 = { + CreatedOnToolsVersion = 8.3.2; + ProvisioningStyle = Automatic; + }; + }; + }; + buildConfigurationList = 37C8A5061EB0C64400DDFCC0 /* Build configuration list for PBXProject "DLSimpleAutolayoutDemo" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 37C8A5021EB0C64400DDFCC0; + productRefGroup = 37C8A50C1EB0C64400DDFCC0 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 37C8A50A1EB0C64400DDFCC0 /* DLSimpleAutolayoutDemo */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 37C8A5091EB0C64400DDFCC0 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 37C8A51E1EB0C64400DDFCC0 /* LaunchScreen.storyboard in Resources */, + 37C8A51B1EB0C64400DDFCC0 /* Assets.xcassets in Resources */, + 37C8A5191EB0C64400DDFCC0 /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 37C8A5071EB0C64400DDFCC0 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 37C8A5271EB0C69100DDFCC0 /* DLSimpleAutolayout.m in Sources */, + 37C8A5161EB0C64400DDFCC0 /* ViewController.m in Sources */, + 37C8A5131EB0C64400DDFCC0 /* AppDelegate.m in Sources */, + 37C8A5101EB0C64400DDFCC0 /* main.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + 37C8A5171EB0C64400DDFCC0 /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 37C8A5181EB0C64400DDFCC0 /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 37C8A51C1EB0C64400DDFCC0 /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 37C8A51D1EB0C64400DDFCC0 /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 37C8A5201EB0C64400DDFCC0 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + 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_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 10.3; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 37C8A5211EB0C64400DDFCC0 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + 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_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 10.3; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 37C8A5231EB0C64400DDFCC0 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = ""; + INFOPLIST_FILE = DLSimpleAutolayoutDemo/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = com.danlee.DLSimpleAutolayoutDemo; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 37C8A5241EB0C64400DDFCC0 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = ""; + INFOPLIST_FILE = DLSimpleAutolayoutDemo/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = com.danlee.DLSimpleAutolayoutDemo; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 37C8A5061EB0C64400DDFCC0 /* Build configuration list for PBXProject "DLSimpleAutolayoutDemo" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 37C8A5201EB0C64400DDFCC0 /* Debug */, + 37C8A5211EB0C64400DDFCC0 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 37C8A5221EB0C64400DDFCC0 /* Build configuration list for PBXNativeTarget "DLSimpleAutolayoutDemo" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 37C8A5231EB0C64400DDFCC0 /* Debug */, + 37C8A5241EB0C64400DDFCC0 /* Release */, + ); + defaultConfigurationIsVisible = 0; + }; +/* End XCConfigurationList section */ + }; + rootObject = 37C8A5031EB0C64400DDFCC0 /* Project object */; +} diff --git a/DLSimpleAutolayoutDemo/AppDelegate.h b/DLSimpleAutolayoutDemo/AppDelegate.h new file mode 100644 index 0000000..9fc4563 --- /dev/null +++ b/DLSimpleAutolayoutDemo/AppDelegate.h @@ -0,0 +1,17 @@ +// +// AppDelegate.h +// DLSimpleAutolayoutDemo +// +// Created by Dan.Lee on 2017/4/26. +// Copyright © 2017年 Dan Lee. All rights reserved. +// + +#import + +@interface AppDelegate : UIResponder + +@property (strong, nonatomic) UIWindow *window; + + +@end + diff --git a/DLSimpleAutolayoutDemo/AppDelegate.m b/DLSimpleAutolayoutDemo/AppDelegate.m new file mode 100644 index 0000000..bc5bb67 --- /dev/null +++ b/DLSimpleAutolayoutDemo/AppDelegate.m @@ -0,0 +1,51 @@ +// +// AppDelegate.m +// DLSimpleAutolayoutDemo +// +// Created by Dan.Lee on 2017/4/26. +// Copyright © 2017年 Dan Lee. All rights reserved. +// + +#import "AppDelegate.h" + +@interface AppDelegate () + +@end + +@implementation AppDelegate + + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + // Override point for customization after application launch. + 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 invalidate graphics rendering callbacks. 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 active 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/DLSimpleAutolayoutDemo/Assets.xcassets/AppIcon.appiconset/Contents.json b/DLSimpleAutolayoutDemo/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..36d2c80 --- /dev/null +++ b/DLSimpleAutolayoutDemo/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,68 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "3x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/DLSimpleAutolayoutDemo/Base.lproj/LaunchScreen.storyboard b/DLSimpleAutolayoutDemo/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 0000000..fdf3f97 --- /dev/null +++ b/DLSimpleAutolayoutDemo/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DLSimpleAutolayoutDemo/Base.lproj/Main.storyboard b/DLSimpleAutolayoutDemo/Base.lproj/Main.storyboard new file mode 100644 index 0000000..50f9d20 --- /dev/null +++ b/DLSimpleAutolayoutDemo/Base.lproj/Main.storyboard @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DLSimpleAutolayoutDemo/DLSimpleAutolayout/DLSimpleAutolayout.h b/DLSimpleAutolayoutDemo/DLSimpleAutolayout/DLSimpleAutolayout.h new file mode 100644 index 0000000..2f40c09 --- /dev/null +++ b/DLSimpleAutolayoutDemo/DLSimpleAutolayout/DLSimpleAutolayout.h @@ -0,0 +1,56 @@ +// +// DLSimpleAutolayout.h +// DLSimpleAutolayoutDemo +// +// Created by Dan.Lee on 2017/4/26. +// Copyright © 2017年 Dan Lee. All rights reserved. +// + +@import UIKit; + +@interface DLSimpleViewAttribute : NSObject + +@property (nonatomic, strong, readonly) DLSimpleViewAttribute *(^equalTo)(id view); +@property (nonatomic, strong, readonly) DLSimpleViewAttribute *(^lessThanOrEqualTo)(id view); +@property (nonatomic, strong, readonly) DLSimpleViewAttribute *(^greaterThanOrEqualTo)(id view); +@property (nonatomic, strong, readonly) DLSimpleViewAttribute *(^multipliedBy)(CGFloat multipier); +@property (nonatomic, strong, readonly) DLSimpleViewAttribute *(^offset)(CGFloat offset); +@property (nonatomic, strong, readonly) NSLayoutConstraint *(^install)(); + +@end + + +@interface UIView (DLSimpleAutoLayout) + +@property (nonatomic, strong, readonly) DLSimpleViewAttribute *dl_left; +@property (nonatomic, strong, readonly) DLSimpleViewAttribute *dl_top; +@property (nonatomic, strong, readonly) DLSimpleViewAttribute *dl_right; +@property (nonatomic, strong, readonly) DLSimpleViewAttribute *dl_bottom; +@property (nonatomic, strong, readonly) DLSimpleViewAttribute *dl_leading; +@property (nonatomic, strong, readonly) DLSimpleViewAttribute *dl_trailing; +@property (nonatomic, strong, readonly) DLSimpleViewAttribute *dl_width; +@property (nonatomic, strong, readonly) DLSimpleViewAttribute *dl_height; +@property (nonatomic, strong, readonly) DLSimpleViewAttribute *dl_centerX; +@property (nonatomic, strong, readonly) DLSimpleViewAttribute *dl_centerY; +@property (nonatomic, strong, readonly) DLSimpleViewAttribute *dl_baseline; + +#if TARGET_OS_IPHONE || TARGET_OS_TV + +@property (nonatomic, strong, readonly) DLSimpleViewAttribute *dl_leftMargin; +@property (nonatomic, strong, readonly) DLSimpleViewAttribute *dl_rightMargin; +@property (nonatomic, strong, readonly) DLSimpleViewAttribute *dl_topMargin; +@property (nonatomic, strong, readonly) DLSimpleViewAttribute *dl_bottomMargin; +@property (nonatomic, strong, readonly) DLSimpleViewAttribute *dl_leadingMargin; +@property (nonatomic, strong, readonly) DLSimpleViewAttribute *dl_trailingMargin; +@property (nonatomic, strong, readonly) DLSimpleViewAttribute *dl_centerXWithinMargins; +@property (nonatomic, strong, readonly) DLSimpleViewAttribute *dl_centerYWithinMargins; + +#endif +@end + +@interface NSArray (DLSimpleAutoLayout) + +@property (nonatomic, strong, readonly) NSArray * (^dl_constraint_install)(); + +@end + diff --git a/DLSimpleAutolayoutDemo/DLSimpleAutolayout/DLSimpleAutolayout.m b/DLSimpleAutolayoutDemo/DLSimpleAutolayout/DLSimpleAutolayout.m new file mode 100644 index 0000000..7deded2 --- /dev/null +++ b/DLSimpleAutolayoutDemo/DLSimpleAutolayout/DLSimpleAutolayout.m @@ -0,0 +1,245 @@ +// +// DLSimpleAutolayout.m +// DLSimpleAutolayoutDemo +// +// Created by Dan.Lee on 2017/4/26. +// Copyright © 2017年 Dan Lee. All rights reserved. +// + +#import "DLSimpleAutolayout.h" + + +static NSInteger DLSimpleLayoutNotSetAttribute = -10; +static NSInteger DLSimpleLayoutNotSetRelation = -10; + +@interface DLSimpleViewAttribute() + +@property (nonatomic, weak) id item; +@property (nonatomic, assign) NSLayoutAttribute attribute; + +@property (nonatomic, weak) id firstItem; +@property (nonatomic, assign) NSLayoutAttribute firstAttribute; +@property (nullable, nonatomic, weak) id secondItem; +@property (nonatomic, assign) NSLayoutAttribute secondAttribute; +@property (nonatomic, assign) NSLayoutRelation relation; +@property (nonatomic, assign) CGFloat multiplier; +@property (nonatomic, assign) CGFloat constant; +- (instancetype)initWithView:(UIView *)view attribute:(NSLayoutAttribute)attr; + + +@end + +@implementation DLSimpleViewAttribute + +- (instancetype)initWithView:(UIView *)view attribute:(NSLayoutAttribute)attr { + self = [super init]; + if (self) { + _item = view; + _attribute = attr; + + _firstItem = view; + _firstAttribute = attr; + + _secondItem = nil; + _secondAttribute = DLSimpleLayoutNotSetAttribute; + _relation = DLSimpleLayoutNotSetRelation; + _multiplier = 1; + _constant = 0; + } + return self; +} + +- (DLSimpleViewAttribute *(^)(id))equalTo { + return ^id(id view){ + [self customSelfWith:view]; + self.relation = NSLayoutRelationEqual; + return self; + }; +} + +- (DLSimpleViewAttribute *(^)(id))lessThanOrEqualTo { + return ^id(id view){ + [self customSelfWith:view]; + self.relation = NSLayoutRelationLessThanOrEqual; + return self; + }; +} + +- (DLSimpleViewAttribute *(^)(id))greaterThanOrEqualTo { + return ^id(id view){ + [self customSelfWith:view]; + self.relation = NSLayoutRelationGreaterThanOrEqual; + return self; + }; +} + +- (DLSimpleViewAttribute *(^)(CGFloat))multipliedBy { + return ^id(CGFloat mult){ + self.multiplier *= mult; + return self; + }; +} + +- (DLSimpleViewAttribute *(^)(CGFloat))offset { + return ^id(CGFloat constant){ + self.constant += constant; + return self; + }; +} + +// TODO: maybe some bugs +- (NSLayoutConstraint * (^)())install { + return ^id(){ + ((UIView *)self.firstItem).translatesAutoresizingMaskIntoConstraints = NO; + NSLayoutConstraint *constaraint = [NSLayoutConstraint constraintWithItem:self.firstItem + attribute:self.firstAttribute + relatedBy:self.relation + toItem:self.secondItem + attribute:self.secondAttribute + multiplier:self.multiplier + constant:self.constant]; + if (self.secondItem == nil) { + [self.firstItem addConstraint:constaraint]; + } else { + UIView *closestCommonSuperview = [self dl_ClosestCommonSuperview:self.firstItem view2:self.secondItem]; + [closestCommonSuperview addConstraint:constaraint]; + } + return constaraint; + }; +} + +- (UIView *)dl_ClosestCommonSuperview:(UIView *)view1 view2:(UIView *)view2 { + UIView *closestCommonSuperview = nil; + + UIView *secondViewSuperview = view1; + while (!closestCommonSuperview && secondViewSuperview) { + UIView *firstViewSuperview = view2; + while (!closestCommonSuperview && firstViewSuperview) { + if (secondViewSuperview == firstViewSuperview) { + closestCommonSuperview = secondViewSuperview; + } + firstViewSuperview = firstViewSuperview.superview; + } + secondViewSuperview = secondViewSuperview.superview; + } + return closestCommonSuperview; +} + +- (void)customSelfWith:(id)view { + if ([view isKindOfClass:[DLSimpleViewAttribute class]]) { + DLSimpleViewAttribute *secondAttribute = (DLSimpleViewAttribute *)view; + self.secondItem = secondAttribute.item; + self.secondAttribute = secondAttribute.attribute; + } else if ([view isKindOfClass:[NSNumber class]]) { + self.constant = [((NSNumber *)view) floatValue]; + self.secondAttribute = NSLayoutAttributeNotAnAttribute; + } else { + self.secondItem = view; + self.secondAttribute = self.firstAttribute; + } +} + +@end + + +@implementation UIView (DLSimpleAutoLayout) + +- (DLSimpleViewAttribute *)dl_left { + return [[DLSimpleViewAttribute alloc] initWithView:self attribute:NSLayoutAttributeLeft]; +} + +- (DLSimpleViewAttribute *)dl_top { + return [[DLSimpleViewAttribute alloc] initWithView:self attribute:NSLayoutAttributeTop]; +} + +- (DLSimpleViewAttribute *)dl_right { + return [[DLSimpleViewAttribute alloc] initWithView:self attribute:NSLayoutAttributeRight]; +} + +- (DLSimpleViewAttribute *)dl_bottom { + return [[DLSimpleViewAttribute alloc] initWithView:self attribute:NSLayoutAttributeBottom]; +} + +- (DLSimpleViewAttribute *)dl_leading { + return [[DLSimpleViewAttribute alloc] initWithView:self attribute:NSLayoutAttributeLeading]; +} + +- (DLSimpleViewAttribute *)dl_trailing { + return [[DLSimpleViewAttribute alloc] initWithView:self attribute:NSLayoutAttributeTrailing]; +} + +- (DLSimpleViewAttribute *)dl_width { + return [[DLSimpleViewAttribute alloc] initWithView:self attribute:NSLayoutAttributeWidth]; +} + +- (DLSimpleViewAttribute *)dl_height { + return [[DLSimpleViewAttribute alloc] initWithView:self attribute:NSLayoutAttributeHeight]; +} + +- (DLSimpleViewAttribute *)dl_centerX { + return [[DLSimpleViewAttribute alloc] initWithView:self attribute:NSLayoutAttributeCenterX]; +} + +- (DLSimpleViewAttribute *)dl_centerY { + return [[DLSimpleViewAttribute alloc] initWithView:self attribute:NSLayoutAttributeCenterY]; +} + +- (DLSimpleViewAttribute *)dl_baseline { + return [[DLSimpleViewAttribute alloc] initWithView:self attribute:NSLayoutAttributeBaseline]; +} + +#if TARGET_OS_IPHONE || TARGET_OS_TV + +- (DLSimpleViewAttribute *)dl_leftMargin { + return [[DLSimpleViewAttribute alloc] initWithView:self attribute:NSLayoutAttributeLeftMargin]; +} + +- (DLSimpleViewAttribute *)dl_rightMargin { + return [[DLSimpleViewAttribute alloc] initWithView:self attribute:NSLayoutAttributeRightMargin]; +} + +- (DLSimpleViewAttribute *)dl_topMargin { + return [[DLSimpleViewAttribute alloc] initWithView:self attribute:NSLayoutAttributeTopMargin]; +} + +- (DLSimpleViewAttribute *)dl_bottomMargin { + return [[DLSimpleViewAttribute alloc] initWithView:self attribute:NSLayoutAttributeBottomMargin]; +} + +- (DLSimpleViewAttribute *)dl_leadingMargin { + return [[DLSimpleViewAttribute alloc] initWithView:self attribute:NSLayoutAttributeLeadingMargin]; +} + +- (DLSimpleViewAttribute *)dl_trailingMargin { + return [[DLSimpleViewAttribute alloc] initWithView:self attribute:NSLayoutAttributeTrailingMargin]; +} + +- (DLSimpleViewAttribute *)dl_centerXWithinMargins { + return [[DLSimpleViewAttribute alloc] initWithView:self attribute:NSLayoutAttributeCenterXWithinMargins]; +} + +- (DLSimpleViewAttribute *)dl_centerYWithinMargins { + return [[DLSimpleViewAttribute alloc] initWithView:self attribute:NSLayoutAttributeCenterYWithinMargins]; +} + +#endif +@end + +@implementation NSArray (DLSimpleAutoLayout) + +- (NSArray * (^)())dl_constraint_install { + return ^NSArray *() { + NSMutableArray *resultArray = [NSMutableArray arrayWithCapacity:self.count]; + for (DLSimpleViewAttribute *item in self) { + if ([item isKindOfClass:[DLSimpleViewAttribute class]]) { + [resultArray addObject:item.install()]; + } + } + return resultArray.copy; + }; +} + +@end + + + diff --git a/DLSimpleAutolayoutDemo/Info.plist b/DLSimpleAutolayoutDemo/Info.plist new file mode 100644 index 0000000..d052473 --- /dev/null +++ b/DLSimpleAutolayoutDemo/Info.plist @@ -0,0 +1,45 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/DLSimpleAutolayoutDemo/ViewController.h b/DLSimpleAutolayoutDemo/ViewController.h new file mode 100644 index 0000000..00f3546 --- /dev/null +++ b/DLSimpleAutolayoutDemo/ViewController.h @@ -0,0 +1,15 @@ +// +// ViewController.h +// DLSimpleAutolayoutDemo +// +// Created by Dan.Lee on 2017/4/26. +// Copyright © 2017年 Dan Lee. All rights reserved. +// + +#import + +@interface ViewController : UIViewController + + +@end + diff --git a/DLSimpleAutolayoutDemo/ViewController.m b/DLSimpleAutolayoutDemo/ViewController.m new file mode 100644 index 0000000..64d837c --- /dev/null +++ b/DLSimpleAutolayoutDemo/ViewController.m @@ -0,0 +1,66 @@ +// +// ViewController.m +// DLSimpleAutolayoutDemo +// +// Created by Dan.Lee on 2017/4/26. +// Copyright © 2017年 Dan Lee. All rights reserved. +// + +#import "ViewController.h" +#import "DLSimpleAutolayout.h" + +@interface ViewController () + +@property (nonatomic, strong) UIButton *button1; +@property (nonatomic, strong) UIButton *button2; + +@end + +@implementation ViewController + +- (UIButton *)button1 { + if (_button1 == nil) { + _button1 = [UIButton new]; + [_button1 setTitle:@"Button One" forState:UIControlStateNormal]; + [_button1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; + _button1.backgroundColor = [UIColor brownColor]; + } + return _button1; +} + +- (UIButton *)button2 { + if (_button2 == nil) { + _button2 = [UIButton new]; + [_button2 setTitle:@"Button Two" forState:UIControlStateNormal]; + [_button2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; + _button2.backgroundColor = [UIColor purpleColor]; + } + return _button2; +} + +- (void)viewDidLoad { + [super viewDidLoad]; + // Do any additional setup after loading the view, typically from a nib. + + self.view.backgroundColor = [UIColor whiteColor]; + [self.view addSubview:self.button1]; + [self.view addSubview:self.button2]; + + @[ + self.button1.dl_top.equalTo(self.view).offset(100), + self.button1.dl_left.equalTo(self.view).offset(10), + self.button1.dl_right.equalTo(self.view).offset(-10), + self.button1.dl_height.equalTo(@40), + ].dl_constraint_install(); + + @[ + self.button2.dl_top.equalTo(self.button1.dl_bottom).offset(10), + self.button2.dl_left.equalTo(self.button1), + self.button2.dl_right.equalTo(self.button1), + self.button2.dl_height.equalTo(@60), + ].dl_constraint_install(); +} + + + +@end diff --git a/DLSimpleAutolayoutDemo/main.m b/DLSimpleAutolayoutDemo/main.m new file mode 100644 index 0000000..c8f77d9 --- /dev/null +++ b/DLSimpleAutolayoutDemo/main.m @@ -0,0 +1,16 @@ +// +// main.m +// DLSimpleAutolayoutDemo +// +// Created by Dan.Lee on 2017/4/26. +// Copyright © 2017年 Dan Lee. All rights reserved. +// + +#import +#import "AppDelegate.h" + +int main(int argc, char * argv[]) { + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + } +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29