I have added custom target as a framework to use in my codebase. I can't see image in preview canvas. When I run in simulator, image is there.
VStack(alignment: .leading) {
Text("Hello World")
Image("icon_star")
.resizable()
.renderingMode(.original)
.frame(width: 14, height: 14)
}.background(Color.white)
Any suggestion
Thanks
Related
I have two TextEditors in a VStack in my app. I would like each of them to expand to fit the text they contain, but remain hugging the text. Unfortunately, long text in the first TextEditor expands both TextEditors equally. It is as if the total height of the VStack they are in is expanded correctly, but the extra height is shared between the two editors.
This only occurs when I use a maxWidth on the VStack. If I fix the width it behaves correctly.
Is there some way to solve this without losing the resize behaviour maxWidth gives?
ScrollView {
VStack(alignment: .leading) {
TextEditor(text: Binding($note.details)!)
.font(.body)
TextEditor(text: Binding($note.title)!)
.font(.title)
}.frame(maxWidth: 450)
}
Try to put .fixedSize(horizontal: false, vertical: true) on both editors.
I need to do textfield design like this. I tried many way but not found any solutions for it.
And in Google Material not yet for SwiftUI.
You may use it with .overlay and .storke:
TextField("Enter your email", text: $text)
.overlay(
RoundedRectangle(cornerRadius: 30)
.stroke(Color(.blue, lineWidth: 2))
Using iOS14.5, Swift5.4, XCode12.5, and SwiftUI,
I am trying to build simple DetailView to which you can navigate to using a NavigationLink.
It all works, except that I have no idea about the height of my NavigationBar inside the DetailView. (note that I use the .inline Version by calling .navigationBarTitleDisplayMode(.inline) on the DetailView).
I am trying to show a simple two-line VStack in the DetailView.
And it turns out that the DetailView's body is covered by the NavigationBar unless I move the whole thing down by 56 Pixels (by using Spacer().frame(height: 56)).
And I don't even know the precise height of the NavigationBar
And even worse, I don't know how to determine it dynamically for Portrait and Landscape rotations.
How do you make the DetailView's body start below the NavBar no matter rotation-states ?
Here example Screenshots for Portrait :
Left side: the title is cut off ! Right side: using a Spacer makes title appear
Here is how I open the navigationLink:
NavigationLink(
destination: DetailView(session: session).navigationBarTitleDisplayMode(.inline),
tag: session.id ?? "",
selection: $selectedTag,
label: { EmptyView() }
)
And here is the entire Detail-Screen:
(please notice the Spacer-distance of 56 in order to make the title visible at all)
import SwiftUI
struct DetailView: View {
#State var session: THSession
var body: some View {
VStack(alignment: .leading) {
Spacer().frame(height: 56) // !!!!!!!!!! without this the title sits behind NavBar !!!!!!!!!!!!!!!!!!!
Text(session.title)
.font(.title)
.fontWeight(.bold)
.foregroundColor(.white)
Spacer().frame(height: 16)
HStack {
Text(session.invitationCode)
.font(.title)
.fontWeight(.bold)
.foregroundColor(.white)
}
Spacer()
}
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .topLeading)
.background(Color.red)
.ignoresSafeArea()
}
}
I'm assuming that you're using ignoresSafeArea() because you want the background to extend into the safe area. But, where you have it placed is having a side effect of making the titles extend into the nav bar area.
Instead, place ignoresSafeArea() inside the background modifier:
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
.background(Color.red.ignoresSafeArea())
Now, your titles won't extend into the safe area and you can avoid using a Spacer at the top of the View altogether.
If I have a Label that uses a system image and some text, let's call the text "title". How would I align the subtitle to the the leading edge of the title text and not the image?
This seems to work, but is there another way? Something just seems off about setting the top alignment.
HStack(alignment: .top) {
Image(systemName: "gift")
VStack(alignment: .leading) {
Text("Title")
Text("Subtitle")
}
}
I'm studying SwiftUI and when I using TextField then I have a problem with TextField's cursor is still at left-center of TextField's area.
How can I set it to left-top of TextField area.
Thanks!
This is my code:
TextField("What is your mind?", text: $statusContent)
.clipped()
.frame(height: 100, alignment: .leading)
.multilineTextAlignment(.leading)