Post

Replies

Boosts

Views

Activity

Reply to Snapshot of a SwiftUI View
//	Convert any SwiftUI View to UIImage import SwiftUI struct ContentView: View { 		let imageSize: CGSize = CGSize(width: 1000, height: 1000) 		var body: some View { 				testView 						.frame(width: 300, height: 300) 						.onTapGesture { 								// Capture high res image of swiftUI view 								let highresImage = testView.asImage(size: imageSize) 								// Now you can do what ever with the highresImage 						} 		} 		var testView: some View { 				ZStack { 						Color.blue 						Circle() 								.fill(Color.red) 				} 		} } extension UIView { 		func asImage() -> UIImage { 				let format = UIGraphicsImageRendererFormat() 				format.scale = 1 				return UIGraphicsImageRenderer(size: self.layer.frame.size, format: format).image { context in 						self.drawHierarchy(in: self.layer.bounds, afterScreenUpdates: true) 				} 		} } extension View { 		func asImage(size: CGSize) -> UIImage { 				let controller = UIHostingController(rootView: self) 				controller.view.bounds = CGRect(origin: .zero, size: size) 				let image = controller.view.asImage() 				return image 		} }
Dec ’20
Reply to Xcode 12 (17219) : Unable to install apps on devices
Found the solution. Apparently this is a known (SR-13343) in Xcode 12. It has to do with "SwiftPM binaryTarget dependency and code signing", where Xcode fails to sign the frameworks that are provided by SwiftPM. See this link: https://forums.swift.org/t/swiftpm-binarytarget-dependency-and-code-signing/38953 If you read thru you will find a link to the work around, by adding a script to the build phase of the target: Work Around Link: pspdfkit.com/guides/ios/current/knowledge-base/library-not-found-swiftpm/ I just added the script to my app, everything is now good!
Oct ’20
Reply to Get RGB from SwiftUI Color Picker
Xcode 12 beta 3: ColorPicker won't run on Simulator, so run it on your device. struct ContentView: View {     @State private var drawSwiftUIColor: Color = Color.red     @State private var drawOpacity: Double = 1.0     @State private var drawUIColor: UIColor = UIColor(red: 1.0, green: 0.0, blue: 0.0, alpha: 1.0)     @State private var drawHexNumber: String = "#FF0000"     var body: some View {         VStack {             Spacer()             ColorPicker("", selection: $drawSwiftUIColor, supportsOpacity: true)                 .scaleEffect(2)                 .offset(x: 28 - UIScreen.main.bounds.width, y: -15)                 .onChange(of: drawSwiftUIColor) { newValue in                     getColorsFromPicker(pickerColor: newValue)                 }                 // Use this only if you are initializing the picker with UIColor, otherwise delete the onAppear()                 .onAppear() {                     //resetColorPickerWithUIColor()                 }             Spacer()             Text("SwiftUI Color").bold().foregroundColor(drawSwiftUIColor).opacity(drawOpacity)             Text("UI Color").bold().foregroundColor(Color(drawUIColor))             Text("Hex Number: \(drawHexNumber)").bold()         }     }     func getColorsFromPicker(pickerColor: Color) {         let colorString = "\(pickerColor)"         let colorArray: [String] = colorString.components(separatedBy: " ")         if colorArray.count > 1 {             var r: CGFloat = CGFloat((Float(colorArray[1]) ?? 1))             var g: CGFloat = CGFloat((Float(colorArray[2]) ?? 1))             var b: CGFloat = CGFloat((Float(colorArray[3]) ?? 1))             let alpha: CGFloat = CGFloat((Float(colorArray[4]) ?? 1))             if (r < 0.0) {r = 0.0}             if (g < 0.0) {g = 0.0}             if (b < 0.0) {b = 0.0}             if (r > 1.0) {r = 1.0}             if (g > 1.0) {g = 1.0}             if (b > 1.0) {b = 1.0}             // Update UIColor             drawUIColor = UIColor(red: r, green: g, blue: b, alpha: alpha)             // Update Opacity             drawOpacity = Double(alpha)             // Update hex             let rgb:Int = (Int)(r*255)<<16 | (Int)(g*255)<<8 | (Int)(b*255)<<0             drawHexNumber = String(format: "#%06X", rgb)         }     }     func resetColorPickerWithUIColor() {         let color: UIColor = drawUIColor         let r: Double = Double(color.rgba.red)         let g: Double = Double(color.rgba.green)         let b: Double = Double(color.rgba.blue)         drawSwiftUIColor = Color(red: r, green: g, blue: b, opacity: drawOpacity)     } } extension UIColor {     var rgba: (red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) {         var red: CGFloat = 0         var green: CGFloat = 0         var blue: CGFloat = 0         var alpha: CGFloat = 0         getRed(&amp;red, green: &amp;green, blue: &amp;blue, alpha: &amp;alpha)         return (red, green, blue, alpha)     } }
Jul ’20
Reply to Sign In With Apple not working with Xcode 12 beta on simulator ?
Can confirm! Actually "Sign In With Apple" in general does not run on iOS 14 Simulators. I have a full blown "Sign In With Apple" with backend server that runs smoothly on all iOS 14 DEVICES, but not the Simulator. iOS 14 Simulators, once you sign in to Apple account in the Settings, you can not Sign Out!!!! no access to submenu: Name, Phone Number, Email no access to submenu: Password &amp; Security
Jul ’20