From a9b85cce4815ded2f9b85be1f2fb69ca8ba130b5 Mon Sep 17 00:00:00 2001 From: ismailgulek Date: Thu, 9 Mar 2017 21:47:18 +0300 Subject: [PATCH] All files added --- .../project.pbxproj | 326 ++++++++++++++++++ SelectiveBordersDemo/AppDelegate.swift | 46 +++ .../AppIcon.appiconset/Contents.json | 93 +++++ .../Base.lproj/LaunchScreen.storyboard | 27 ++ .../Base.lproj/Main.storyboard | 130 +++++++ SelectiveBordersDemo/Info.plist | 43 +++ SelectiveBordersDemo/ViewController.swift | 55 +++ Source/SelectiveBordersLayer.swift | 195 +++++++++++ 8 files changed, 915 insertions(+) create mode 100644 SelectiveBordersDemo.xcodeproj/project.pbxproj create mode 100644 SelectiveBordersDemo/AppDelegate.swift create mode 100644 SelectiveBordersDemo/Assets.xcassets/AppIcon.appiconset/Contents.json create mode 100644 SelectiveBordersDemo/Base.lproj/LaunchScreen.storyboard create mode 100644 SelectiveBordersDemo/Base.lproj/Main.storyboard create mode 100644 SelectiveBordersDemo/Info.plist create mode 100644 SelectiveBordersDemo/ViewController.swift create mode 100644 Source/SelectiveBordersLayer.swift diff --git a/SelectiveBordersDemo.xcodeproj/project.pbxproj b/SelectiveBordersDemo.xcodeproj/project.pbxproj new file mode 100644 index 0000000..6fed622 --- /dev/null +++ b/SelectiveBordersDemo.xcodeproj/project.pbxproj @@ -0,0 +1,326 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + EC33001C1E71D8E300765372 /* SelectiveBordersLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC33001B1E71D8E300765372 /* SelectiveBordersLayer.swift */; }; + EC3300261E71D93A00765372 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC33001E1E71D93A00765372 /* AppDelegate.swift */; }; + EC3300271E71D93A00765372 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = EC33001F1E71D93A00765372 /* Assets.xcassets */; }; + EC3300281E71D93A00765372 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = EC3300201E71D93A00765372 /* LaunchScreen.storyboard */; }; + EC3300291E71D93A00765372 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = EC3300221E71D93A00765372 /* Main.storyboard */; }; + EC33002A1E71D93A00765372 /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = EC3300241E71D93A00765372 /* Info.plist */; }; + EC33002B1E71D93A00765372 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC3300251E71D93A00765372 /* ViewController.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + EC33001B1E71D8E300765372 /* SelectiveBordersLayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SelectiveBordersLayer.swift; sourceTree = ""; }; + EC33001E1E71D93A00765372 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + EC33001F1E71D93A00765372 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + EC3300211E71D93A00765372 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + EC3300231E71D93A00765372 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + EC3300241E71D93A00765372 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + EC3300251E71D93A00765372 /* ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; + EC33FFDF1E64881A00765372 /* SelectiveBordersDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SelectiveBordersDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + EC33FFDC1E64881A00765372 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + EC33001A1E71D8E300765372 /* Source */ = { + isa = PBXGroup; + children = ( + EC33001B1E71D8E300765372 /* SelectiveBordersLayer.swift */, + ); + path = Source; + sourceTree = ""; + }; + EC33001D1E71D93A00765372 /* SelectiveBordersDemo */ = { + isa = PBXGroup; + children = ( + EC33001E1E71D93A00765372 /* AppDelegate.swift */, + EC33001F1E71D93A00765372 /* Assets.xcassets */, + EC3300201E71D93A00765372 /* LaunchScreen.storyboard */, + EC3300221E71D93A00765372 /* Main.storyboard */, + EC3300241E71D93A00765372 /* Info.plist */, + EC3300251E71D93A00765372 /* ViewController.swift */, + ); + path = SelectiveBordersDemo; + sourceTree = ""; + }; + EC33FFD61E64881A00765372 = { + isa = PBXGroup; + children = ( + EC33001A1E71D8E300765372 /* Source */, + EC33001D1E71D93A00765372 /* SelectiveBordersDemo */, + EC33FFE01E64881A00765372 /* Products */, + ); + sourceTree = ""; + }; + EC33FFE01E64881A00765372 /* Products */ = { + isa = PBXGroup; + children = ( + EC33FFDF1E64881A00765372 /* SelectiveBordersDemo.app */, + ); + name = Products; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + EC33FFDE1E64881A00765372 /* SelectiveBordersDemo */ = { + isa = PBXNativeTarget; + buildConfigurationList = EC33FFF11E64881A00765372 /* Build configuration list for PBXNativeTarget "SelectiveBordersDemo" */; + buildPhases = ( + EC33FFDB1E64881A00765372 /* Sources */, + EC33FFDC1E64881A00765372 /* Frameworks */, + EC33FFDD1E64881A00765372 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = SelectiveBordersDemo; + productName = Trials; + productReference = EC33FFDF1E64881A00765372 /* SelectiveBordersDemo.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + EC33FFD71E64881A00765372 /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 0820; + LastUpgradeCheck = 0820; + ORGANIZATIONNAME = "Ismail Gulek"; + TargetAttributes = { + EC33FFDE1E64881A00765372 = { + CreatedOnToolsVersion = 8.2.1; + DevelopmentTeam = S74N7PNF8A; + ProvisioningStyle = Automatic; + }; + }; + }; + buildConfigurationList = EC33FFDA1E64881A00765372 /* Build configuration list for PBXProject "SelectiveBordersDemo" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = EC33FFD61E64881A00765372; + productRefGroup = EC33FFE01E64881A00765372 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + EC33FFDE1E64881A00765372 /* SelectiveBordersDemo */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + EC33FFDD1E64881A00765372 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + EC33002A1E71D93A00765372 /* Info.plist in Resources */, + EC3300291E71D93A00765372 /* Main.storyboard in Resources */, + EC3300271E71D93A00765372 /* Assets.xcassets in Resources */, + EC3300281E71D93A00765372 /* LaunchScreen.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + EC33FFDB1E64881A00765372 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + EC33002B1E71D93A00765372 /* ViewController.swift in Sources */, + EC3300261E71D93A00765372 /* AppDelegate.swift in Sources */, + EC33001C1E71D8E300765372 /* SelectiveBordersLayer.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + EC3300201E71D93A00765372 /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + EC3300211E71D93A00765372 /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; + EC3300221E71D93A00765372 /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + EC3300231E71D93A00765372 /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + EC33FFEF1E64881A00765372 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + 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.2; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + EC33FFF01E64881A00765372 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + 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.2; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + EC33FFF21E64881A00765372 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = S74N7PNF8A; + INFOPLIST_FILE = "$(SRCROOT)/SelectiveBordersDemo/Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = com.gulek.SelectiveBordersDemo; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; + }; + name = Debug; + }; + EC33FFF31E64881A00765372 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = S74N7PNF8A; + INFOPLIST_FILE = "$(SRCROOT)/SelectiveBordersDemo/Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = com.gulek.SelectiveBordersDemo; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + EC33FFDA1E64881A00765372 /* Build configuration list for PBXProject "SelectiveBordersDemo" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + EC33FFEF1E64881A00765372 /* Debug */, + EC33FFF01E64881A00765372 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + EC33FFF11E64881A00765372 /* Build configuration list for PBXNativeTarget "SelectiveBordersDemo" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + EC33FFF21E64881A00765372 /* Debug */, + EC33FFF31E64881A00765372 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = EC33FFD71E64881A00765372 /* Project object */; +} diff --git a/SelectiveBordersDemo/AppDelegate.swift b/SelectiveBordersDemo/AppDelegate.swift new file mode 100644 index 0000000..428cafd --- /dev/null +++ b/SelectiveBordersDemo/AppDelegate.swift @@ -0,0 +1,46 @@ +// +// AppDelegate.swift +// SelectiveBordersDemo +// +// Created by Ismail GULEK on 27/02/2017. +// Copyright © 2017 Ismail Gulek. All rights reserved. +// + +import UIKit + +@UIApplicationMain +class AppDelegate: UIResponder, UIApplicationDelegate { + + var window: UIWindow? + + + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { + // Override point for customization after application launch. + 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 invalidate graphics rendering callbacks. 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 active 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/SelectiveBordersDemo/Assets.xcassets/AppIcon.appiconset/Contents.json b/SelectiveBordersDemo/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..1d060ed --- /dev/null +++ b/SelectiveBordersDemo/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,93 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, + { + "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" : "20x20", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "2x" + }, + { + "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" + }, + { + "idiom" : "ipad", + "size" : "83.5x83.5", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/SelectiveBordersDemo/Base.lproj/LaunchScreen.storyboard b/SelectiveBordersDemo/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 0000000..fdf3f97 --- /dev/null +++ b/SelectiveBordersDemo/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SelectiveBordersDemo/Base.lproj/Main.storyboard b/SelectiveBordersDemo/Base.lproj/Main.storyboard new file mode 100644 index 0000000..5d3d045 --- /dev/null +++ b/SelectiveBordersDemo/Base.lproj/Main.storyboard @@ -0,0 +1,130 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SelectiveBordersDemo/Info.plist b/SelectiveBordersDemo/Info.plist new file mode 100644 index 0000000..2b02ec4 --- /dev/null +++ b/SelectiveBordersDemo/Info.plist @@ -0,0 +1,43 @@ + + + + + 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 + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/SelectiveBordersDemo/ViewController.swift b/SelectiveBordersDemo/ViewController.swift new file mode 100644 index 0000000..ada4a7c --- /dev/null +++ b/SelectiveBordersDemo/ViewController.swift @@ -0,0 +1,55 @@ +// +// ViewController.swift +// SelectiveBordersDemo +// +// Created by Ismail GULEK on 27/02/2017. +// Copyright © 2017 Ismail Gulek. All rights reserved. +// + +import UIKit + +class ViewController: UIViewController { + + @IBOutlet weak var customView: SelectiveBordersView! + + override func viewDidLoad() { + super.viewDidLoad() + + customView.selectiveBorderWidth = 3.0 + customView.selectiveBorderColor = UIColor.red + customView.borders = .all + + /* sample usage: + customView.borders = .all + customView.borders = [.left, .top] + */ + } + + @IBAction func switchValueChanged(_ sender: UISwitch) { + let tag = sender.tag + let isOn = sender.isOn + + var member: SelectiveBorderType + + if tag == 1 { + member = .top + } else if tag == 2 { + member = .left + } else if tag == 3 { + member = .bottom + } else { + member = .right + } + + if isOn { + customView.borders.insert(member) + } else { + customView.borders.remove(member) + } + } + + @IBAction func sliderValueChanged(_ slider: UISlider) { + customView.selectiveBorderWidth = CGFloat(slider.value) + } + +} diff --git a/Source/SelectiveBordersLayer.swift b/Source/SelectiveBordersLayer.swift new file mode 100644 index 0000000..a18c572 --- /dev/null +++ b/Source/SelectiveBordersLayer.swift @@ -0,0 +1,195 @@ +// +// SelectiveBordersLayer.swift +// +// Created by Ismail GULEK on 27/02/2017. +// Copyright © 2017 Ismail Gulek. All rights reserved. +// + +import Foundation +import UIKit +import QuartzCore + +// Border types +struct SelectiveBorderType: OptionSet { + + let rawValue: Int + + static var top = SelectiveBorderType(rawValue: 1 << 0) + static var left = SelectiveBorderType(rawValue: 1 << 1) + static var bottom = SelectiveBorderType(rawValue: 1 << 2) + static var right = SelectiveBorderType(rawValue: 1 << 3) + + static var all = SelectiveBorderType(rawValue: 16 - 1) +} + +// UIView subclass +class SelectiveBordersView: UIView, SelectiveBordersProtocol { + + // You must add below override code to your subclass in order to use selective borders + override class var layerClass: AnyClass { + get { + return SelectiveBordersLayer.self + } + } + +} + +// CALayer subclass +class SelectiveBordersLayer: CALayer { + + var _topBorder: CALayer? + var _leftBorder: CALayer? + var _bottomBorder: CALayer? + var _rightBorder: CALayer? + + var selectiveBorderColor: UIColor = UIColor.lightGray { + didSet { + _topBorder?.backgroundColor = selectiveBorderColor.cgColor + _leftBorder?.backgroundColor = selectiveBorderColor.cgColor + _bottomBorder?.backgroundColor = selectiveBorderColor.cgColor + _rightBorder?.backgroundColor = selectiveBorderColor.cgColor + } + } + var selectiveBorderWidth: CGFloat = 1.0 { + didSet { + self.removeAllBorderLayers() + self.arrangeBorderLayers() + } + } + + var borders: SelectiveBorderType = [] { + didSet { + self.arrangeBorderLayers() + } + } + + fileprivate func removeAllBorderLayers() { + _topBorder?.removeFromSuperlayer() + _topBorder = nil + _leftBorder?.removeFromSuperlayer() + _leftBorder = nil + _bottomBorder?.removeFromSuperlayer() + _bottomBorder = nil + _rightBorder?.removeFromSuperlayer() + _rightBorder = nil + } + + fileprivate func arrangeBorderLayers() { + // implemented like this to avoid blinking + // please do NOT change + var newLayerAdded = false + + // top + if borders.contains(.top) { + if _topBorder == nil { + _topBorder = self.createNewBorderLayer() + newLayerAdded = true + } + } else { + _topBorder?.removeFromSuperlayer() + _topBorder = nil + } + + // left + if borders.contains(.left) { + if _leftBorder == nil { + _leftBorder = self.createNewBorderLayer() + newLayerAdded = true + } + } else { + _leftBorder?.removeFromSuperlayer() + _leftBorder = nil + } + + // bottom + if borders.contains(.bottom) { + if _bottomBorder == nil { + _bottomBorder = self.createNewBorderLayer() + newLayerAdded = true + } + } else { + _bottomBorder?.removeFromSuperlayer() + _bottomBorder = nil + } + + // right + if borders.contains(.right) { + if _rightBorder == nil { + _rightBorder = self.createNewBorderLayer() + newLayerAdded = true + } + } else { + _rightBorder?.removeFromSuperlayer() + _rightBorder = nil + } + + // update layout if new layer added + if newLayerAdded { + self.setNeedsLayout() + } + } + + fileprivate func createNewBorderLayer() -> CALayer { + let layer = CALayer() + layer.backgroundColor = self.selectiveBorderColor.cgColor + self.addSublayer(layer) + return layer + } + + override func layoutSublayers() { + super.layoutSublayers() + + _topBorder?.frame = CGRect(x: 0, y: 0, width: self.frame.width, height: self.selectiveBorderWidth) + _leftBorder?.frame = CGRect(x: 0, y: 0, width: self.selectiveBorderWidth, height: self.frame.height) + _bottomBorder?.frame = CGRect(x: 0, y: self.frame.height - self.selectiveBorderWidth, width: self.frame.width, height: self.selectiveBorderWidth) + _rightBorder?.frame = CGRect(x: self.frame.width - self.selectiveBorderWidth, y: 0, width: self.selectiveBorderWidth, height: self.frame.height) + + } + +} + +extension SelectiveBordersProtocol where Self: UIView { + + var layer: SelectiveBordersLayer { + get { + return layer as! SelectiveBordersLayer + } + } + + var selectiveBorderWidth: CGFloat { + get { + return self.layer.selectiveBorderWidth + } + set { + self.layer.selectiveBorderWidth = newValue + } + } + + var selectiveBorderColor: UIColor { + get { + return self.layer.selectiveBorderColor + } + set { + self.layer.selectiveBorderColor = newValue + } + } + + var borders: SelectiveBorderType { + get { + return self.layer.borders + } + set { + self.layer.borders = newValue + } + } + +} + +protocol SelectiveBordersProtocol { + + var layer: SelectiveBordersLayer { get } + var selectiveBorderWidth: CGFloat { get set } + var selectiveBorderColor: UIColor { get set } + var borders: SelectiveBorderType { get set } + +}