How to put View on top of all other views in SwiftUI
Try to put everything in ZStack
and use zIndex
for DropdownButton
to put it atop, like
ZStack {
// ... other content here
DropdownButton(displayText: "This month",
selectedKey: .constant("Test"),
options: options).zIndex(10)
// ... other content here
Presenting - Show a view on top in SwiftUI (I don't want to navigate)
I solved it by placing
if(incomeFill_show) {
BudgetAlert(amount: .constant("400"))
}
at the bottom of the List: like this
var body: some View {
VStack(alignment: .leading, spacing: 8) {
headerView.padding().background(Color.white)
ZStack(alignment: .center) {
List() {
VStack {
Section(header: self.getHeaderView()) {
ForEach(categoriesData) { category in
HStack(alignment: .bottom) {
CategoryProgressView(category: category, value: .constant(.random(in: 0.1 ... 1)))
self.valuesText(category: category)
}
}
.colorMultiply(Colors.SharedColors.backgroundColor)
}
}
}
.colorMultiply(Colors.SharedColors.backgroundColor)
.onAppear {UITableView.appearance().separatorStyle = .none}
.onDisappear { UITableView.appearance().separatorStyle = .singleLine }
if(incomeFill_show) {
BudgetAlert(amount: .constant("400"))
}
}
}.background(Colors.SharedColors.backgroundColor)
}
}
for blurred background you can see this code here:
var body: some View {
VStack {
Spacer()
ZStack(alignment: .center) {
RoundedRectangle(cornerRadius: 10).foregroundColor(Color.white)
VStack {
Text("Add your Income").font(Fonts.mediumFont)
HStack(alignment: .center, spacing: 0) {
CustomTextField(placeHolderLabel: "Amount", val: $amount, keyboardType: UIKeyboardType.decimalPad).padding()
HStack {
Button("\(currency.rawValue)"){
self.show_currencyActionsheet = true
}
.font(Fonts.callout)
.foregroundColor(Colors.textFieldFloatingLabel)
.actionSheet(isPresented: self.$show_currencyActionsheet) {self.actionSheetCurrency}
Image(systemName: "chevron.down")
.imageScale(.small)
}.padding()
}.padding([.leading,.trailing])
Button(action: {
self.callBack()
}) {
Text(" Add Income ").font(Fonts.callout).foregroundColor(Color.white)
}
.padding()
.background(Colors.darkGreen)
.clipShape(Capsule())
}
}.frame(minHeight: 150, idealHeight: 182, maxHeight: 200)
.padding()
Spacer()
}.background(VisualEffectView(effect: UIBlurEffect(style: .dark))
.edgesIgnoringSafeArea(.all))
}
struct VisualEffectView: UIViewRepresentable {
var effect: UIVisualEffect?
func makeUIView(context: UIViewRepresentableContext<Self>) -> UIVisualEffectView { UIVisualEffectView() }
func updateUIView(_ uiView: UIVisualEffectView, context: UIViewRepresentableContext<Self>) { uiView.effect = effect }
}
but I prefer to go with faded background
Place view on top of others SwiftUI
SwiftUI uses ZStack{}
for layered views.
Here’s a good primer: https://www.hackingwithswift.com/quick-start/swiftui/how-to-layer-views-on-top-of-each-other-using-zstack
I’m sorry it’s nearly 1am here and I don’t have time now for a more thorough answer, but I see you’re active 3min ago, and that should point you in the right direction.
How can I make a view align it's center to the top of another view in SwiftUI?
A possible approach is to use alignmentGuide
modifier, which allows to fit specific internal alignment line to parent container. So by default containers have center alignment, so using top anchor instead for one of views result in align other's center to top.
Tested with Xcode 13.2 / iOS 15.2
struct DemoView: View {
var body: some View {
ZStack {
Rectangle().fill(.red)
.frame(width: 300, height: 200)
.alignmentGuide(VerticalAlignment.center) { // << here !!
$0[VerticalAlignment.top]
}
Rectangle().fill(.green)
.frame(width: 100, height: 80)
}
.border(Color.black)
}
}
Related Topics
Parametrized Unit Tests in Swift
Navigation Bar Items After Push from Swiftui to UIkit
How to Draw a Line Between Two Points Over an Image in Swift 3
How to Create a Cocoapod with .Swift
How Is Commoncrypto Used in Swift3
Difference Between @Propertydelegate and @Propertywrapper
Navigationlink Inside .Searchable Does Not Work
How to Write to a Variable from Within The Firebase Getdocument Function (Swift)
Error "[Sharesheet] Connection Invalidated" Error iOS13+ But Not on iOS 11.4
Swift Error: Failed to Get Module 'My_App' from Ast Context
Swift Error "Domain=Nscocoaerrordomain Code=3840 "Invalid Value Around Character 1."
Preferredstatusbarupdateanimation Being Ignored
Difference Between Object(Forkey:) and Value(Forkey:) in Userdefaults
Carthage Update Error: "Github API Request Failed: Bad Credentials"
What Are The Benefits of an Immutable Struct Over a Mutable One