Hide dots indica - swiftui

I've searching for this answer and realized there was no content on Internet (or i couldn't find it). Finally I figured it out so I'm here to share the response of this answer.
How to pass from this:
To this:

You just have to add .page(indexDisplayMode: .never) in the .tabViewStyle constructor like this:
TabView(selection: $selection){
Text("ORDER")
.tag(TicketDetailViewPages.ORDER)
Text("ORIGINAL")
.tag(TicketDetailViewPages.ORIGINAL)
Text("PRIZES")
.tag(TicketDetailViewPages.PRIZES)
}
.tabViewStyle(.page(indexDisplayMode: .never))

Related

how to match the font of an existing view

I'm curious, is there a way to make the fonts in a view match those of an existing view in SwiftUI? I don't like the default selections of swiftUI in a certain context, and I'd like some control over the situation.
Here's some code to illustrate:
struct FontMatchView: View {
var body: some View {
Form {
Section {
Text("Some Controls Here")
} header: {
HStack {
Text("Header")
Spacer()
Button("Option") {
}
}
}
}
}
}
This gives this result:
In the Section Header, I'd like the font in the button on the right (with label "OPTION") to match the label to its left ("HEADER"). I'm guessing this will be hard because the font is not known at the time of view definition. But the choices SwiftUI has made here are "clearly wrong" :-), and I need to fix this.
Is there a way we solve this (other than overriding both fonts)? Ideally, I could say "use a font that is 0.8 x the height of whatever font will be used in view X". But I'd settle for "use the same font as will be used in view X".
You can remove "buttonizing" (which includes adjusting the font) by applying .buttonStyle(.plain). This will make it match the other Text in the current context. If you then want to re-accent it, you may:
Button("Option") {}
.buttonStyle(.plain)
.foregroundColor(.accentColor)
That said (and somewhat unrelated), making the button as small as the HEADER text may make it uncomfortably small as a hit area. It may be better to make HEADER larger rather than OPTION smaller.

Swiftui list: trigger an action on tap and mimic basic select then auto-unselect

I'm starting to learn swiftui and I've run into a problem that is both very basic and easily solvable in UIKit; but after spending days searching the internet and watching WWDC videos I've found no native solution.
The premise is simple: I have an array of songs I want to display in a list; when a user taps on a song view it should highlight the view on press, unhighlight after release, and then play the song (ie trigger an action). Sounds simple right?
Here's what I tried and spent way too much time on:
Using List(selection) + .onEvent(changed): I end up with a UUID (because i've only gotten selection to work with a UUID) that I then have to check against an array of songs to match AND the cell won't unhighlight/select itself; even when I try to manually set the State variable to nil or another generated UUID.
Using .onTap (either on or in the cell): I have to tap on the text of the cell to trigger onTap so I get a lot of taps that just don't work (because I have lots of white space in the cell). I also don't get a nice UI color change on press/release.
So after spending hours trying many different things I've finally come up with a solution and I basically wanted to create an account and share it to hopefully help other developers in my position. Because this so very annoyed me that something so basic took so much effort and time to do.
In the end the best solution I came up with was this:
Using ZStack and an empty button:
edit: I found I need to include and hide the content otherwise the button doesn't grow to fill the space (seems in lists it does for some reason). Though not sure what the hit on performance is of rendering the content twice when hiding it. Maybe a GeometryReader would work better?
struct SelectionView: ViewModifier {
let onSelect: () -> Void
func body(content: Content) -> some View {
ZStack (alignment: .leading) {
Button {
onSelect()
} label: {
content
.hidden()
}
content
}
}
}
extension View {
func onSelection(_ selection: #escaping () -> Void) -> some View {
self.modifier(SelectionView(onSelect: selection))
}
}
then to use it:
SongCell(song: song)
.onSelection {
// Do whatever action you want
}
No messing around with list selection, no weird tap hit boxes, and get the press/release color change. Basically put an empty button in a ZStack and trigger off it's action. Could possibly cause tap/touch issues with more complicated cells (?) but it does exactly what I need it to do for my basic app. I'm just not sure why it took so much effort and why apple doesn't support such a basic use case by default? If I've overlooked something native please do inform me. Thanks.
I got the basic idea what you are trying to do. I'm Going to show simple example. Maybe using this you will be able to find proper solution.
First let's create a color : -
#State var colorToShow : Color = Color.blue
Now in body we have our ZStack or Your cell that we want to deal with : -
ZStack{
colorToShow
}.frame(width: 50, height: 50).padding()
.onLongPressGesture(minimumDuration: 3) {
print("Process Complete")
colorToShow = .green
} onPressingChanged: { pressing in
if pressing {
print("Pressing")
colorToShow = .red
} else {
print("Pressing Released")
colorToShow = .blue
}
}
Here we are using .onLongPressGesture. You can set minimum duration on which you want to perform action. Now on process completion You set what you want to do. OnPressingChange give you a bool value that changes according to user is pressing that button or not. Show color change(Highlight) or do action while bool value is true. When user release button do action or unhighlight since bool value turns false.
Hope you find it useful.

SwiftUI underline() results in broken underline

I'm trying to underline some text in a home screen widget but the underline always appears broken:
struct NotLoggedInSmallView: View {
var body: some View {
Text("Ready to write a new chapter in travel?")
.underline()
}
}
Changing font/sizae/baseline... doesn't help.
I worked around this in another places by just drawing line below the field but that doesn't handle wrapped text. Seems like pretty basic stuff but I can't seem to find a way that works.
Try attributed string instead
var body: some View {
Text(AttributedString("Ready to write a new chapter in travel?",
attributes: AttributeContainer([.underlineStyle: 1])))
}
Tested with Xcode 13.4 / watchOS 8.5

Extra Space in List (left and right side) SwiftUI

I am trying to create list screen but while creating a cell it drop a extra space right and left side.
I put only text for reference. I refer some link but it not helps me. and also tried other padding related modifier but not help it also to me.
Code
.......
let text = "Hello stack work is going very fine. let's check the code is woking or not properly"
var body: some View {
List {
Text(text).background(Color.blue)
Text(text).background(Color.blue)
}.foregroundColor(.white)
}
.....
image I attached space indicated with arrow
List drop a extra space right and left side, so you can use padding() modifier to resolve issue.
VStack(alignment: .leading) {
List {
Text("Hello stack work is going very fine. let's check the code is woking or not properly")
.background(Color.blue)
Text("Hello stack work is going very fine. let's check the code is woking or not properly")
.background(Color.blue)
}
.foregroundColor(.white)
}
.padding(.leading, -16) // you can use as per your requirement(-16)
.padding(.trailing, -20)
The List adds a bit of padding on both sides, just like UITableView does. It generally helps readability, but if you insist on removing it, you can add
.padding(-10.0)
to your body.

Semantic React Dropdown with search prop prevents styling

I'm changing the color of a dropdown's caret with
.myclass .ui.dropdown {
color:transparent!important;
}
This hides the caret, as expected, however not when I send the prop 'search' to the Dropdown component.
Has anyone faced this?
I've tried these alternatives
.myclass .ui.dropdown.search
.myclass .ui.search.dropdown
.myclass .ui.search
I also need to change it this way, rather than with icon=null, because I want to show the caret on hover with
.myclass .ui.dropdown:hover {
color: white!important;
}
Thanks in advance.
Answering my own question, shouldn't have given up so quickly. Leaving the post up for others:
SOLUTION:
.myclass .ui.dropdown i {
color:transparent!important;
}
.myclass .ui.dropdown:hover i {
color:white!important;
}
Although this doesn't explain why the search prop changes things, it works.