-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:boinx/BXSwiftUtils
- Loading branch information
Showing
14 changed files
with
285 additions
and
1,082 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,3 +67,5 @@ fastlane/screenshots | |
fastlane/test_output | ||
|
||
.DS_Store | ||
.bx_build_env | ||
Artifacts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
51 changes: 51 additions & 0 deletions
51
BXSwiftUtils/Math & Geometry/CACornerMask+Convenience.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// | ||
// CACornerMask+Accessors.swift | ||
// BXSwiftUtils | ||
// | ||
// Created by Stefan Fochler on 16.10.18. | ||
// Copyright © 2018 Boinx Software Ltd. & Imagine GbR. All rights reserved. | ||
// | ||
|
||
import QuartzCore.CoreAnimation | ||
|
||
public extension CACornerMask | ||
{ | ||
public static let allCorners: CACornerMask = [ | ||
.layerMaxXMaxYCorner, | ||
.layerMaxXMinYCorner, | ||
.layerMinXMaxYCorner, | ||
.layerMinXMinYCorner | ||
] | ||
|
||
#if os(macOS) | ||
public static let bottomCorners: CACornerMask = [ | ||
.layerMaxXMinYCorner, | ||
.layerMinXMinYCorner | ||
] | ||
|
||
public static let topCorners: CACornerMask = [ | ||
.layerMinXMaxYCorner, | ||
.layerMaxXMaxYCorner | ||
] | ||
#elseif os(iOS) | ||
public static let bottomCorners: CACornerMask = [ | ||
.layerMaxXMaxYCorner, | ||
.layerMinXMaxYCorner | ||
] | ||
|
||
public static let topCorners: CACornerMask = [ | ||
.layerMinXMinYCorner, | ||
.layerMaxXMinYCorner | ||
] | ||
#endif | ||
|
||
public static let leftCorners: CACornerMask = [ | ||
.layerMinXMinYCorner, | ||
.layerMinXMaxYCorner | ||
] | ||
|
||
public static let rightCorners: CACornerMask = [ | ||
.layerMaxXMinYCorner, | ||
.layerMaxXMaxYCorner | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// | ||
// CGPath+RoundedRect.swift | ||
// BXSwiftUtils | ||
// | ||
// Created by Stefan Fochler on 16.10.18. | ||
// Copyright © 2018 Boinx Software Ltd. & Imagine GbR. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import QuartzCore.CoreAnimation | ||
|
||
public extension CGPath | ||
{ | ||
/** | ||
Creates the path of a rounded rect of size `bounds` where only the cordners of `corners` are rounded using `radius`. | ||
|
||
- parameter bounds: The outer bounds of the rect. | ||
- parameter corners: The corner mask containing the corners to be rounded. If empty, no corners will be rounded. | ||
- parameter radius: The radius to be applied to the rounded corners. | ||
*/ | ||
public static func roundedRect(inBounds bounds: CGRect, corners: CACornerMask, radius: CGFloat) -> CGPath | ||
{ | ||
let path = CGMutablePath() | ||
|
||
if corners.contains(.layerMinXMaxYCorner) | ||
{ | ||
let start = CGPoint(x: bounds.minX, y: bounds.maxY - radius) | ||
path.move(to: start) | ||
path.addArc(tangent1End: start, tangent2End: CGPoint(x: bounds.minX + radius, y: bounds.maxY), radius: radius) | ||
} | ||
else | ||
{ | ||
path.move(to: CGPoint(x: bounds.minX, y: bounds.maxY)) | ||
} | ||
|
||
if corners.contains(.layerMaxXMaxYCorner) | ||
{ | ||
let start = CGPoint(x: bounds.maxX - radius, y: bounds.maxY) | ||
path.addLine(to: start) | ||
path.addArc(tangent1End: start, tangent2End: CGPoint(x: bounds.maxX, y: bounds.maxY - radius), radius: radius) | ||
} | ||
else | ||
{ | ||
path.addLine(to: CGPoint(x: bounds.maxX, y: bounds.maxY)) | ||
} | ||
|
||
if corners.contains(.layerMaxXMinYCorner) | ||
{ | ||
let start = CGPoint(x: bounds.maxX, y: bounds.minY + radius) | ||
path.addLine(to: start) | ||
path.addArc(tangent1End: start, tangent2End: CGPoint(x: bounds.maxX - radius, y: bounds.minY), radius: radius) | ||
} | ||
else | ||
{ | ||
path.addLine(to: CGPoint(x: bounds.maxX, y: bounds.minY)) | ||
} | ||
|
||
if corners.contains(.layerMinXMinYCorner) | ||
{ | ||
let start = CGPoint(x: bounds.minX + radius, y: bounds.minY) | ||
path.addLine(to: start) | ||
path.addArc(tangent1End: start, tangent2End: CGPoint(x: bounds.minX, y: bounds.minY + radius), radius: radius) | ||
} | ||
else | ||
{ | ||
path.addLine(to: CGPoint(x: bounds.minX, y: bounds.minY)) | ||
} | ||
|
||
path.closeSubpath() | ||
|
||
return path | ||
} | ||
} |
Oops, something went wrong.