导入 XuXuCheck 工程(iOS 干化学尿液试纸分析 App)
从桌面工程复制而来,作为本仓库的 Xuxucheck/ 子目录。 为控制仓库体积做了两处删减: - 移除 Frameworks/opencv2.xcframework 下的两个 visionOS 切片 (xros-arm64、xros-arm64-simulator,合计约 106 MB),并同步删掉该 xcframework 内 Info.plist 里对应的两条 AvailableLibraries 记录, 只保留 ios-arm64 与 ios-arm64_x86_64-simulator。 - 移除全部 .DS_Store 与 xcuserdata/。 已用 xcodebuild 从本目录完整编译验证:BUILD SUCCEEDED, ProcessXCFramework 以 --platform ios 成功选中框架,产物含 3699 个 cv:: 符号 (OpenCV 确实链入),嵌入 framework 3 个,与移除无用 pod 之后的状态一致。 仓库约 206 MB,其中 OpenCV 203 MB、其余源码与依赖约 3 MB。
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
//
|
||||
// exts.swift
|
||||
// XuXuCheck
|
||||
//
|
||||
// Created by henseycai on 2025/6/20.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
// MARK: - Simple
|
||||
|
||||
//let bgColor = Color(hex: "E8F2F0")
|
||||
//let alertColor = Color(hex: "ee6c4d")
|
||||
//let topToastColor = Color(hex: "4067CC")
|
||||
//let bottomToastColor = Color(hex: "bfdcae")
|
||||
//let topFloatColor = Color(hex: "61A117")
|
||||
//let bottomFloatColor = Color(hex: "3d5a80")
|
||||
//let leftRightToastColor = Color(hex: "85adad")
|
||||
extension Color {
|
||||
init(hex: String) {
|
||||
let scanner = Scanner(string: hex)
|
||||
var rgbValue: UInt64 = 0
|
||||
scanner.scanHexInt64(&rgbValue)
|
||||
|
||||
let r = (rgbValue & 0xff0000) >> 16
|
||||
let g = (rgbValue & 0xff00) >> 8
|
||||
let b = rgbValue & 0xff
|
||||
|
||||
self.init(
|
||||
red: Double(r) / 0xff,
|
||||
green: Double(g) / 0xff,
|
||||
blue: Double(b) / 0xff
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
struct MyLinearAnimation: CustomAnimation {
|
||||
let duration: TimeInterval
|
||||
|
||||
func animate<V>(
|
||||
value: V,
|
||||
time: TimeInterval,
|
||||
context: inout AnimationContext<V>
|
||||
) -> V? where V: VectorArithmetic {
|
||||
guard time < duration else { return nil }
|
||||
|
||||
return value.scaled(by: time / duration)
|
||||
}
|
||||
}
|
||||
|
||||
// For convenience and code readability, we extend Animation
|
||||
extension Animation {
|
||||
static func myLinear(duration: TimeInterval) -> Animation {
|
||||
Animation(MyLinearAnimation(duration: duration))
|
||||
}
|
||||
|
||||
static var myLinear: Animation {
|
||||
Animation(MyLinearAnimation(duration: 5.0))
|
||||
}
|
||||
}
|
||||
|
||||
//https://www.mysamplecode.com/2019/04/ios-swift-convert-image-base64.html
|
||||
func convertImageToBase64(image: UIImage) -> String {
|
||||
let imageData = image.pngData()!
|
||||
return imageData.base64EncodedString(
|
||||
options: Data.Base64EncodingOptions.lineLength64Characters
|
||||
)
|
||||
}
|
||||
|
||||
func convertBase64ToImage(imageString: String) -> UIImage {
|
||||
let imageData = Data(
|
||||
base64Encoded: imageString,
|
||||
options: Data.Base64DecodingOptions.ignoreUnknownCharacters
|
||||
)!
|
||||
return UIImage(data: imageData)!
|
||||
}
|
||||
|
||||
extension UIImage {
|
||||
|
||||
func getJpegBase64() -> String? {
|
||||
return self.jpegData(compressionQuality: 1)?.base64EncodedString()
|
||||
}
|
||||
|
||||
func compressedJpegData(quality: CGFloat) -> Data?{
|
||||
return self.jpegData(compressionQuality: quality)
|
||||
}
|
||||
|
||||
func aspectFit2Height(_ newHeight: CGFloat) -> UIImage{
|
||||
let scale = newHeight / self.size.height
|
||||
let newWidth = self.size.width * scale
|
||||
let newSize = CGSize(width: newWidth, height: newHeight)
|
||||
let renderer = UIGraphicsImageRenderer(size: newSize)
|
||||
return renderer.image{ _ in
|
||||
self.draw(in: CGRect(origin: .zero, size: newSize))
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user