From ff920621b0e94cf71ddca4c80af11674ec3e48b9 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Thu, 25 Jul 2019 19:56:49 +0800 Subject: [PATCH] add UIView extension --- iOS/Doric/Classes/UIView+Doric.h | 26 +++++ iOS/Doric/Classes/UIView+Doric.m | 113 ++++++++++++++++++++ iOS/Example/Doric.xcodeproj/project.pbxproj | 13 ++- 3 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 iOS/Doric/Classes/UIView+Doric.h create mode 100644 iOS/Doric/Classes/UIView+Doric.m diff --git a/iOS/Doric/Classes/UIView+Doric.h b/iOS/Doric/Classes/UIView+Doric.h new file mode 100644 index 00000000..94f3464c --- /dev/null +++ b/iOS/Doric/Classes/UIView+Doric.h @@ -0,0 +1,26 @@ +// +// UIView+Doric.h +// Doric_Example +// +// Created by pengfei.zhou on 2019/7/25. +// Copyright © 2019 CocoaPods. All rights reserved. +// + +#import +#import +NS_ASSUME_NONNULL_BEGIN + +@interface UIView (Doric) + @property (nonatomic) CGFloat x; + @property (nonatomic) CGFloat y; + @property (nonatomic) CGFloat width; + @property (nonatomic) CGFloat height; + @property (nonatomic) CGFloat centerX; + @property (nonatomic) CGFloat centerY; + @property (nonatomic) CGFloat top + @property (nonatomic) CGFloat left; + @property (nonatomic) CGFloat right; + @property (nonatomic) CGFloat bottom; +@end + +NS_ASSUME_NONNULL_END diff --git a/iOS/Doric/Classes/UIView+Doric.m b/iOS/Doric/Classes/UIView+Doric.m new file mode 100644 index 00000000..30f8c83a --- /dev/null +++ b/iOS/Doric/Classes/UIView+Doric.m @@ -0,0 +1,113 @@ +// +// UIView+Doric.m +// Doric_Example +// +// Created by pengfei.zhou on 2019/7/25. +// Copyright © 2019 CocoaPods. All rights reserved. +// + +#import "UIView+Doric.h" + +@implementation UIView(Doric) + +-(CGFloat)x { + return self.frame.origin.x; +} + +-(void)setX:(CGFloat)x { + CGRect frame = self.frame; + frame.origin.x = x; + [self setFrame:frame]; +} + +-(CGFloat)y { + return self.frame.origin.y; +} + +-(void)setY:(CGFloat)y { + CGRect frame = self.frame; + frame.origin.y = y; + [self setFrame:frame]; +} + +-(CGFloat)left { + return self.frame.origin.x; +} + +-(void)setLeft:(CGFloat)left { + CGRect frame = self.frame; + frame.origin.x = left; + [self setFrame:frame]; +} + +-(CGFloat)right { + return self.frame.origin.x + self.frame.size.width; +} + +-(void)setRight:(CGFloat)right { + CGRect frame = self.frame; + frame.origin.x = right - self.frame.size.width; + [self setFrame:frame]; +} + +-(CGFloat)top { + return self.frame.origin.y; +} + +- (void)setTop:(CGFloat)top { + CGRect frame = self.frame; + frame.origin.y = top; + [self setFrame:frame]; +} + +-(CGFloat)bottom { + return self.frame.origin.y + self.frame.size.height; +} + +-(void)setBottom:(CGFloat)bottom { + CGRect frame = self.frame; + frame.origin.y = bottom - self.frame.size.height; + [self setFrame:frame]; +} + +- (CGFloat)width { + return self.frame.size.width; +} + +-(void)setWidth:(CGFloat)width { + CGRect frame = self.frame; + frame.size.width = width; + self.frame = frame; +} + +-(CGFloat)height { + return self.frame.size.height; +} + +-(void)setHeight:(CGFloat)height { + CGRect frame = self.frame; + frame.size.height = height; + self.frame = frame; +} + +- (CGFloat)centerX { + return self.frame.origin.x + self.frame.size.width/2; +} + +- (void)setCenterX:(CGFloat)centerX { + CGRect frame = self.frame; + frame.origin.x = centerX - self.frame.size.width/2; + [self setFrame:frame]; +} + +- (CGFloat)centerY { + return self.frame.origin.y + self.frame.size.height/2; +} + +- (void)setCenterY:(CGFloat)centerY { + CGRect frame = self.frame; + frame.origin.y = centerY - self.frame.size.height/2; + [self setFrame:frame]; +} + +@end diff --git a/iOS/Example/Doric.xcodeproj/project.pbxproj b/iOS/Example/Doric.xcodeproj/project.pbxproj index c702942f..517ab09a 100644 --- a/iOS/Example/Doric.xcodeproj/project.pbxproj +++ b/iOS/Example/Doric.xcodeproj/project.pbxproj @@ -15,6 +15,7 @@ 607FACEC1AFB9204008FA782 /* Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACEB1AFB9204008FA782 /* Tests.swift */; }; AA31225E33516EB3CE20EC93 /* Pods_Doric_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 972B1C7B71414DF9AC151EE0 /* Pods_Doric_Example.framework */; }; C4DF03C9CBA66A27ED587DD4 /* Pods_Doric_Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 78ED34DAE38B7E34C7C5ED62 /* Pods_Doric_Tests.framework */; }; + E2334AA322E9CA9E0098A085 /* UIView+Doric.m in Sources */ = {isa = PBXBuildFile; fileRef = E2334AA222E9CA9E0098A085 /* UIView+Doric.m */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -46,6 +47,8 @@ 78ED34DAE38B7E34C7C5ED62 /* Pods_Doric_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Doric_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 972B1C7B71414DF9AC151EE0 /* Pods_Doric_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Doric_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; }; CC67379F30C9E12F7919374D /* Doric.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = Doric.podspec; path = ../Doric.podspec; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; + E2334AA122E9CA9E0098A085 /* UIView+Doric.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "UIView+Doric.h"; path = "../Doric/Classes/UIView+Doric.h"; sourceTree = ""; }; + E2334AA222E9CA9E0098A085 /* UIView+Doric.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = "UIView+Doric.m"; path = "../Doric/Classes/UIView+Doric.m"; sourceTree = ""; }; ECED1D64B2512FAA4DBC32D8 /* Pods-Doric_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Doric_Example.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Doric_Example/Pods-Doric_Example.debug.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ @@ -92,6 +95,8 @@ 607FACC71AFB9204008FA782 = { isa = PBXGroup; children = ( + E2334AA122E9CA9E0098A085 /* UIView+Doric.h */, + E2334AA222E9CA9E0098A085 /* UIView+Doric.m */, 607FACF51AFB993E008FA782 /* Podspec Metadata */, 607FACD21AFB9204008FA782 /* Example for Doric */, 607FACE81AFB9204008FA782 /* Tests */, @@ -216,7 +221,7 @@ 607FACCF1AFB9204008FA782 = { CreatedOnToolsVersion = 6.3.1; DevelopmentTeam = 7EE2RX3L3P; - LastSwiftMigration = 0900; + LastSwiftMigration = 1030; }; 607FACE41AFB9204008FA782 = { CreatedOnToolsVersion = 6.3.1; @@ -407,6 +412,7 @@ files = ( 607FACD81AFB9204008FA782 /* ViewController.swift in Sources */, 607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */, + E2334AA322E9CA9E0098A085 /* UIView+Doric.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -552,12 +558,15 @@ baseConfigurationReference = ECED1D64B2512FAA4DBC32D8 /* Pods-Doric_Example.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; DEVELOPMENT_TEAM = 7EE2RX3L3P; INFOPLIST_FILE = Doric/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; MODULE_NAME = ExampleApp; PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "Doric_Example-Bridging-Header.h"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 4.0; }; @@ -568,12 +577,14 @@ baseConfigurationReference = 3657907C57FF8512CF3B0A5D /* Pods-Doric_Example.release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; DEVELOPMENT_TEAM = 7EE2RX3L3P; INFOPLIST_FILE = Doric/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; MODULE_NAME = ExampleApp; PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "Doric_Example-Bridging-Header.h"; SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 4.0; };