Post

Replies

Boosts

Views

Activity

Swift TextField with label on macOS
Why is there no label for SwiftUI TextField but only a placeholder text? Or is there a modifier that I haven't found yet or a style property? On macOS every control seems to have now a label that is shown on the left side and that is correctly aligned with the other controls in a form. The TextField is also aligned with the other controls but has an empty space left to it. Using the label parameter as a placeholder is not very helpful having multiple textfields and the user entered already some values in them. In this case you cannot see anymore the meaning for all these values. I tried to implement a HStack with a Text and a TextField as a workaround but had trouble to align it with the other controls that have already label parameters in their SwiftUI syntax.
2
0
1.7k
Jul ’20
How to add a label to the side of a TextField on macOS
In the latest beta most of the SwiftUI controls have now a labels that are displayed on the left side of the controls. The alignment of the controls and labels works pretty well. Also the TextField is aligned with the other controls. But its title parameter is used as a placeholder inside the TextField while the left side of the TextField is empty. In my application I have a SwiftUI form with some controls and some number input fields. After the user has entered values the placeholders are not visible and the user cannot see the meaning of each value he entered anymore. Is there a way that the title of a TextField can be displayed as a label on the left side similar to the other controls instead of a placeholder inside the input field?
2
0
1k
Jul ’20
How to position child views within a parent view
Please apologize if this question is really trival. I implementent a content view with two buttons on it. One button should be 8px below the top, the other 8px above the bottom. Maybe I am doing something wrong. But I would use a simple ZStack here. Only problem is that I can set only one alignment for the ZStack at a time. So I can either align all views from the top border or from the bottom border but not one from the top and one from the bottom. Is there a way to solve this layout problem with these three views and a ZStack?
3
0
2.8k
Apr ’20
Why does @Published removes the codable protocol conformance
I have a simple class conforming to the codable protocol. Here is an example which is the same like in the developer documentation...class Landmark: Codable { var name: String var foundingYear: Int }Because the two properties inside the class body are basic Swift types the compiler has nothing to complain.But if I want to edit these properties using SwiftUI I must also make sure that the class conforms also to the ObservableObject protocol.class Landmark: Codable, ObservableObject { @Published var name: String @Published var foundingYear: Int }Now I get an Xcode error message that type Landmark does not conform to the codable protocol anymore.This is something I cannot understand. The property wrapper @Published should not change the type of the properties String and Int. The codable conformance should imho still be given to the class without additional lines of codes.
4
0
3.5k
Dec ’19
How to use a SwiftUI touchbar with a NSWindow
Inside the app delegate I uses a simple SwiftUI view as the root for my macOS main window.func applicationDidFinishLaunching(_ aNotification: Notification) { // Create the SwiftUI view that provides the window contents. let contentView = ContentView().touchBar(myTouchbar) // Create the window and set the content view. window = NSWindow( contentRect: NSRect(x: 0, y: 0, width: 480, height: 300), styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView], backing: .buffered, defer: false) window.center() window.setFrameAutosaveName("Main Window") window.contentView = NSHostingView(rootView: contentView) window.makeKeyAndOrderFront(nil) }This contentView has a touchbar asigned to it. If the contentView is a simple view that can hold a focus (like a Textield) then the touchbar becomes visible on my MacBook. But in my application the contentView (the root view of the NSWindow) is a layout container like a HSplitView. In this case the window appears but the touchbar is not visible. How can I use a SwiftUI touchbar with a window without focusable or input elements so that the touchbar is always visible together with the window.
1
0
1.1k
Dec ’19
How to align slider labels in SwiftUI
On macOS we can add labels directly to SwiftUI slider. Has someone found a way how we can align two or more sliders in a VStack?- label text right aligned- all labels should have the same width (given by the largest text)- all slider bars should have the same but flexible width within the containers frame
4
0
3.6k
Dec ’19