SwiftUI:- Image won't show on the View - swiftui

I am playing around with SwiftUI and I am stuck on this View. everything is working fine but this little bug is very frustrating.I am trying to display the images as a vertical view and it won't show on the view . I know the Images are loaded but the view is not showing it . Its covered in blue color.
import SwiftUI
struct PlanetHome : View {
var planets : [Planet]
var body : some View {
NavigationView {
ScrollView {
ZStack {
Color.black .edgesIgnoringSafeArea (.all)
VStack (alignment: .center)
{
ForEach (self.planets.identified(by: \.imageName))
{
planet in NavigationLink (destination: PlanetDetail(planets: planet))
{
PlanetsView (planets: planet)
.frame (width: 500, height: 500)
.padding (.vertical, 5)
}
}
}
}
}
.navigationBarTitle (Text("Planets"))
}
}
}
I tried to put the NavigationView under the ZStack but it did not work.I have no Idea what I did wrong on the code. No error message on the debugger. just doesn't show the images.

The NavigationLink applies a button style to the objects it holds. Button does the same. To remove the blue color, add the buttonStyle modifier:
NavigationLink(destination: ...) {
...
}
.buttonStyle(PlainButtonStyle())
You can create and apply your own button style as well.

Its covered in blue color.
You can change blue color to whatever you want with .foregroundColor(.YourColor) or just change Render as Default to Render as Original Image at Assets.xcassets -> Pick Any Image -> Show the Attribute inspector
To fix other problem you should include PlanetsView because when i put Image(systemName: "photo") instead your view it's shows correctly

Related

How to display a black transparent view over a view in swiftUI?

I am trying to present a transparent view with black background over current view, so that we can still see the content of the current view. I have worked around the opacity modifier but it is not doing the job.
this is my code:
ZStack {
Rectangle()
.fill(.black)
.ignoresSafeArea()
VZScrollViewIfNeeded {
VStack(alignment: .leading) {
// some code
}
}
later I am presenting this view on click of other view:
buttonActionView()
.fullScreenCover(isPresented: $isPresenting, content: transparentView.init)```
Try changing the order of your elements. Currently your Rectangle that should overlay the view is behind the ScrollView. Should look like this:
ZStack {
VZScrollViewIfNeeded {
VStack(alignment: .leading) {
// some code
}
Rectangle()
.foregroundColor(Color.black.opacity(0.5))
.edgesIgnoringSafeArea(.all)
}

How to make a transparent navigation bar using SwiftUI in iOS 16?

In iOS 16, there are now new SwiftUI modifiers for adjusting navigation bars.
The following:
struct ContentView: View {
var body: some View {
NavigationStack {
Rectangle()
.fill(.red)
.frame(width: 200)
.edgesIgnoringSafeArea(.top)
.navigationTitle("Hello")
.navigationBarTitleDisplayMode(.inline)
// New modifiers
.toolbarBackground(.clear, for: .navigationBar)
.toolbarColorScheme(.dark, for: .navigationBar)
.toolbarBackground(.visible, for: .navigationBar)
}
}
}
Produces:
Notice there is an translucent effect applied.
Does anyone know how to remove this translucent effect and instead make it transparent whilst keeping dark color scheme (title/status bar is white)?
Maybe this could work for you:
.toolbarBackground(.hidden, for: .navigationBar
Edit:
You can try:
.toolbarColorScheme
You can find more information here:
How to change status bar color in SwiftUI

Does Xcode SwiftUI button default layout has border?

I am using Xcode to create an app that requires buttons. Right now, when I create a button, I get the text label, which I want, but I also get a background with rounded corners around it. I want to have the button with just the label but without the background. I was using Swift Playgrounds before Xcode and did not have this problem.
Here is my code:
import SwiftUI
struct ContentView: View {
var body: some View {
ZStack {
Rectangle()
.frame(width: 1000, height: 500)
.foregroundColor(.red)
Button(action: {
}) {
Text("Button")
}
}
}
}
Customize the button's style with the .buttonStyle view modifier:
Button(action: {}) {
Text("Button")
}
.buttonStyle(.borderless)
.borderless, .plain, and .link are the options that will result in no border.
Here is a Button without any background or border.
Button("Click") {
//do something
}
.background(.clear) //this

How to change the Color of SwiftUI redacted shimmer effect

I added a shimmer effect for my home screen like the code below.
VStack{
TopView()
HomeView()
}
.redacted(.placeholder)
I got the output like the below image.
https://ibb.co/xFXQ2sk
the shimmer view showing color for the colored view but the normal view shows gray colored.
can i change the whole shimmer view into gray color without showing the colored view in shimmer?
One approach might be to adjust your custom subviews to respond to whether they're being asked to display as a redaction.
For example, if you have a view that adds a piece of text within a red background, e.g.:
struct LabelView: View {
var text: String
var body: some View {
Text(text)
.padding()
.background(Color.red)
}
}
you could then adapt it to use grey when being redacted:
struct LabelView: View {
#Environment(\.redactionReasons) var redactionReasons
var text: String
var body: some View {
Text(text)
.padding()
.background(redactionReasons.contains(.placeholder) ? Color.gray : Color.red)
}
}

Change background color of lists in iOS15

With the new XCode 13 and it‘s iOS 15 support the presentation of Lists have apparently changed.
Now a List has an additional gray background. Before, the background was plain white, just as I would like it to be. When I add other elements like texts, the default background color is still white.
Is there any way to get rid of the gray surrounding of the List without switching to a ForEach() solution?
I tried changing the background color from gray to white on various places and adding additional stacks in hope to override the default background color.
This I want be be all white without the gray surrounding:
struct ContentView: View {
var body: some View {
VStack {
Text("Test")
List {
ForEach(1..<20) { i in
Text(String(i))
}
}.frame(maxWidth: .infinity)
}
}
}
Change the listStyle to .plain. The default for iOS 14 is .plain, and .insetGrouped for iOS 15.
Code:
struct ContentView: View {
var body: some View {
VStack {
Text("Test")
List {
ForEach(1 ..< 20) { i in
Text(String(i))
}
}
.listStyle(.plain)
}
}
}
Result: