From 47c611073bf31bbd3766fe6af85a74db377e6a06 Mon Sep 17 00:00:00 2001 From: Francesco Date: Wed, 4 Oct 2017 13:15:34 +0200 Subject: [PATCH 1/2] - added masked corners for iOS11 --- Codemine/Extensions/UIView+Utilities.swift | 38 +++++++++++++++++++--- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/Codemine/Extensions/UIView+Utilities.swift b/Codemine/Extensions/UIView+Utilities.swift index 3aeda2e..5f1b6c3 100644 --- a/Codemine/Extensions/UIView+Utilities.swift +++ b/Codemine/Extensions/UIView+Utilities.swift @@ -29,11 +29,39 @@ public extension UIView { - corners: Defines which corners should be rounded. - radius: Defines the radius of the round corners as a `CGFloat`. */ - public func roundViewCorners(_ corners:UIRectCorner, radius: CGFloat) { - let path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius)) - let mask = CAShapeLayer() - mask.path = path.cgPath - self.layer.mask = mask + public func roundViewCorners(_ corners: UIRectCorner, radius: CGFloat) { + if #available(iOS 11.0, *) { + self.layer.cornerRadius = radius + self.layer.maskedCorners = getMaskedCorners(from: corners) + } else { + // Fallback on earlier versions + let path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius)) + let mask = CAShapeLayer() + mask.path = path.cgPath + self.layer.mask = mask + } + self.layoutIfNeeded() + } + + //Helper to get CACornerMask from UIRectCorner + private func getMaskedCorners(from corners: UIRectCorner) -> CACornerMask { + var maskedCorners: CACornerMask = [] + if corners.contains(.bottomLeft) { + maskedCorners = maskedCorners.union(.layerMinXMaxYCorner) + } + if corners.contains(.bottomRight) { + maskedCorners = maskedCorners.union(.layerMaxXMaxYCorner) + } + if corners.contains(.topLeft) { + maskedCorners = maskedCorners.union(.layerMinXMinYCorner) + } + if corners.contains(.topRight) { + maskedCorners = maskedCorners.union(.layerMaxXMinYCorner) + } + if corners.contains(.allCorners) { + maskedCorners = [.layerMaxXMaxYCorner, .layerMaxXMinYCorner, .layerMinXMaxYCorner, .layerMinXMinYCorner] + } + return maskedCorners } } From f896350494be23f91ea262f8aa84f395f12a33fe Mon Sep 17 00:00:00 2001 From: Marius Constantinescu Date: Thu, 16 Apr 2020 15:02:05 +0200 Subject: [PATCH 2/2] Xcode 11, swift 5 --- Codemine.xcodeproj/project.pbxproj | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Codemine.xcodeproj/project.pbxproj b/Codemine.xcodeproj/project.pbxproj index 626b3d5..b45e177 100644 --- a/Codemine.xcodeproj/project.pbxproj +++ b/Codemine.xcodeproj/project.pbxproj @@ -500,11 +500,11 @@ }; 275BCA9E1C57D1B500FF3647 = { CreatedOnToolsVersion = 7.2; - LastSwiftMigration = 1010; + LastSwiftMigration = 1130; }; 275BCAA81C57D1B500FF3647 = { CreatedOnToolsVersion = 7.2; - LastSwiftMigration = 1010; + LastSwiftMigration = 1130; }; }; }; @@ -1062,7 +1062,7 @@ SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -1084,7 +1084,7 @@ SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Release; }; @@ -1096,7 +1096,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.nodes.CodemineTests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -1109,7 +1109,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Release; };