SwiftUI as a drawing board for printer label designer

How can I use SwiftUI as a drawing board for a printer label designer? I want to combine views (or add multiple views to a parent view) for different images, text and barcode etc. (after the user select what they want to design and print).

Currently I have put different views (separate view for image, text, barcode etc) inside an instance of TabView and use the tabItem() modifier for each view. I tried using different stacks (ZStack, HStack) but it does not work.

I also want to create a bounding box for each view/object created and have it resized when the user resize the image/text.

Here is part of the code for the label designer with only text:

var body: some View
    {
            ZStack(alignment: .center)
            {
                ZStack(alignment: .topTrailing) //Label Design Area
                {
                    Rectangle()
                        .opacity(0.3)
                        .offset(x:0,y:0)
                        .frame(width: (LabelWidth * mmTOpt), height: (LabelHeight * mmTOpt))                    
                    ZStack()
                    {
                        TextField("", text: $Text1)
                            .offset(x:offsetx + location.x , y:offsety + location.y)
                            .multilineTextAlignment(.center)
                            .submitLabel(.done) // changed to IOS 15
                            .font(Font.custom(fontused, size: fontsize))
                            .disabled(tfdisabled)
                            .gesture(simpleDrag.simultaneously(with: fingerDrag))
                            .underline(textunderlined)
                            .bold(textbold)
                            .italic(textitalic)
                            .strikethrough(textstrikethrough)

I tried to combine the image view using HStack with the following code:

HStack(alignment: .center) {
                        PhotosPicker(selection: $selectedItem, matching: .images, photoLibrary: .shared()) {
                            Text("Select a photo")
                        }
…….

Is there any other methods I can use?

Assuming the label will be ultimately printed? What goes into each label? How are you planning on doing the actual label draw and printing? (or are those the questions?)

Yes, the label will be printed. Each label can have text, images, barcodes and date stamp etc (depending on what the user select when designing the label, each feature can be selected with a button).

For the printing we are using an API to connect and print on a specific printer. Currently I can print each feature (text, images or barcode) separately (on different labels), since I am using TabView. I want to create a drawing board so all the features can be combined together and the user can print them on one label.

Sounds like you may be using GUI components to draw the labels? Why not actually do drawings using Canvas ?

This topic was automatically closed after 166 days. New replies are no longer allowed.