Files
iOS/Sources/Shared/Common/Extensions/UIImage+Icons.swift
mat1th 97834bfd5e Update swift lint and format + appy fixes (#2585)
## Summary
Swift lint and swiftformat are outdated. This PR does update those +
applies the new formatting form swiftformat.
There is 1 swift file with a manual change:
`Sources/Vehicle/Templates/Areas/CarPlayAreasViewModel.swift`. This is
done because `swiftlint` did create the following swiftlint error:
`error: Cyclomatic Complexity Violation: Function should have complexity
10 or less; currently complexity is 11 (cyclomatic_complexity)`.

Because it does change a lot of files the question is if we want to
finetune the `swiftformat` rules.

## Screenshots
No user facing changes.

## Link to pull request in Documentation repository
NA

## Any other notes
NA
2024-02-22 13:06:39 +01:00

38 lines
1.2 KiB
Swift

import UIKit
public extension UIImage {
convenience init(size: CGSize, color: UIColor) {
// why is UIGraphicsImageRenderer not available on watchOS?
var alpha: CGFloat = 1
color.getRed(nil, green: nil, blue: nil, alpha: &alpha)
UIGraphicsBeginImageContextWithOptions(size, alpha == 1.0, 0)
color.setFill()
UIRectFill(CGRect(origin: .zero, size: size))
let image = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
self.init(cgImage: image.cgImage!, scale: image.scale, orientation: image.imageOrientation)
}
}
public extension MaterialDesignIcons {
convenience init(serversideValueNamed value: String, fallback: MaterialDesignIcons? = nil) {
if let fallback {
self.init(named: value.normalizingIconString, fallback: fallback)
} else {
self.init(named: value.normalizingIconString)
}
}
}
public extension String {
var normalizingIconString: String {
let base = replacingOccurrences(of: "mdi:|hass:", with: "", options: .regularExpression)
.replacingOccurrences(of: ":", with: "_")
.replacingOccurrences(of: "-", with: "_")
return MDIMigration.migrate(icon: base)
}
}