Skip to content

Commit 27a33c2

Browse files
committed
Added more extensions.
1 parent 9a8b04e commit 27a33c2

File tree

4 files changed

+33
-7
lines changed

4 files changed

+33
-7
lines changed

Sources/SwiftBoost/CoreGraphics/Extensions/CGSizeExtension.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,17 @@ public extension CGSize {
1414

1515
var maxDimension: CGFloat { max(width, height) }
1616
var minDimension: CGFloat { min(width, height) }
17+
18+
func resize(newWidth: CGFloat) -> CGSize {
19+
let scaleFactor = newWidth / self.width
20+
let newHeight = self.height * scaleFactor
21+
return CGSize(width: newWidth, height: newHeight)
22+
}
23+
24+
func resize(newHeight: CGFloat) -> CGSize {
25+
let scaleFactor = newHeight / self.height
26+
let newWidth = self.width * scaleFactor
27+
return CGSize(width: newWidth, height: newHeight)
28+
}
1729
}
1830
#endif

Sources/SwiftBoost/UIKit/Extensions/UIColorExtension.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public extension UIColor {
179179
#endif
180180

181181
var secondary: UIColor {
182-
return self.alpha(0.06)
182+
return .init(light: self.alpha(0.06), dark: self.alpha(0.18))
183183
}
184184

185185
#if !os(watchOS) && !os(tvOS)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#if canImport(UIKit) && (os(iOS) || os(tvOS))
2+
import UIKit
3+
4+
public extension UITextField {
5+
6+
func removeTargetsAndActions() {
7+
self.removeTarget(nil, action: nil, for: .allEvents)
8+
}
9+
}
10+
#endif

Sources/SwiftBoost/UIKit/Extensions/UIViewExtension.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,17 @@ public extension UIView {
3939
}
4040

4141
var screenshot: UIImage? {
42-
UIGraphicsBeginImageContextWithOptions(layer.frame.size, false, 0)
43-
defer {
44-
UIGraphicsEndImageContext()
42+
/*UIGraphicsBeginImageContextWithOptions(layer.frame.size, false, 0)
43+
defer {
44+
UIGraphicsEndImageContext()
45+
}
46+
guard let context = UIGraphicsGetCurrentContext() else { return nil }
47+
layer.render(in: context)
48+
return UIGraphicsGetImageFromCurrentImageContext()*/
49+
let renderer = UIGraphicsImageRenderer(bounds: bounds)
50+
return renderer.image { rendererContext in
51+
layer.render(in: rendererContext.cgContext)
4552
}
46-
guard let context = UIGraphicsGetCurrentContext() else { return nil }
47-
layer.render(in: context)
48-
return UIGraphicsGetImageFromCurrentImageContext()
4953
}
5054

5155
// MARK: - Layout

0 commit comments

Comments
 (0)