Post

Replies

Boosts

Views

Activity

How to export a SwiftUI View to PDF (Vector)
Hi, I have a SwiftUI View which contains Images and Borders. I'd like to export this to a Vector-PDF. I tried let pdfExportView = NSHostingView(rootView: MySwiftUIView()) let pdfData = pdfExportView.dataWithPDF(inside: pdfExportView.bounds) But the PDF does not contain the Images and the borders. Is there any other solution? PDF as Bitmap is not an option.
4
0
2k
Jul ’20
How to render SwiftUI view off screen?
I have a pretty complex and dynamic SwiftUI View which wrapps around multiple other Views which have different dynamic contents (images, texts …) But I also need those views as a thumbnail with a fixed height. I.e. something like a magazine where a page is displayed and the other pages are displayed in a thumbnail bar at the bottom of the screen. The thumbnails should be presented in a UICollectionView (the rest of the App is still UIKit!) I tried to scale down the UIView (coming from UIHostingController) using Autolayout but had no success with that. My next approach would be creating preview images but to render and SwiftUI-View as image I need it to be displayed on the screen … but how to do that? Thank you very much in advance
0
0
901
Nov ’20
Why do AttributedStrings render slightly different on SwiftUI?
Hi, I have a strange problem when drawing NSAttributedStrings in SwiftUI. Compared to render it in AppKit the SwiftUI characters are 1pt smaller. To display the string in SwiftUI I have to use NSViewRepresentable but it does not matter if I render the view in draw() of NSView or use a NSTextField to display it. I have to use NSViewRepresentable as I also have to use CMYK-Colors. The font used is "The Sans Mono-W8 ExtraBold". Can anyone point my for a hint? Or is this a bug?
0
0
263
Feb ’21
Using different swift packages for different configurations
Hi, is there a way to different swift packages for different build configuration? I.e. when I do Release-Builds I'd like to use MyPackage and for debug builds I'd like to use MyPackage-Debug. My first thought was that I could handle this in the Package.swift but .target does not support configurations in .when but only plattforms. So is there any way to use different packages depending on configuration?
0
0
348
Feb ’22
Swift Data Array with Elements to conform protocol
Hi, I'm try to convert from CoreData to SwiftData. Problem is that I'm using inheritance in CoreData. So, I have a base class "animal" and "cat" and "bird" inherit from it. I can have a array of type "animal" which contains both cats and dogs. Now as I try to move to SwiftData I tried the following approach protocol Animal { var name: String { get set } } @Model class Cat: Animal { var name: String var legs: Int } @Model class Bird: Animal { var name: String var legs: Int var wings: Int } @Model class Enviroment { //leads to error: //Type 'any Animal' cannot conform to 'PersistentModel' var animals: [any Animal] } So how to I get around of this? I would like to store multiple types of animals (classes that conform to protocol animal) … but how can I achieve that? Thanks
0
1
316
Jun ’24