Picker and PickerStyles in SwiftUI | Bootcamp #38

  Рет қаралды 39,367

Swiftful Thinking

Swiftful Thinking

Күн бұрын

Пікірлер: 64
@rayhaanalykhan
@rayhaanalykhan 11 ай бұрын
So it turns out that the completion used in the video is deprecated, instead we have to use a similar completion, which has 'content' first then the 'label'. *The issue is that now the label (content of label) won't show If we just placed the picker on it's own, we have to place it in a list for the label to show.* List { Picker(selection: $selection) { ForEach(filterOptions, id: \.self) { option in Text(option) // .font(.headline) // .foregroundStyle(.red) .tag(option) } } label: { // This will only work if our picker is in a list. HStack { Text("Filter: ") Text(selection) } .font(.headline) .foregroundStyle(.white) .padding() .padding(.horizontal) .background(.blue) .clipShape(.rect(cornerRadii: RectangleCornerRadii(topLeading: 10, bottomLeading: 10, bottomTrailing: 10, topTrailing: 10))) .shadow(color: .blue.opacity(0.3), radius: 10, x: 0, y: 10) } .background(.green.opacity(0.1)) .pickerStyle(.menu) /* Label will only show in these picker styles, when picker is in a list: - inline - menu */ } *Alternatively we can use a 'Menu' and use a different picker view completion with it. Note: This is a workaround.* Menu { Picker("Filter", selection: $selection) { ForEach(filterOptions, id: \.self) { option in HStack { Text(option) Image(systemName: "heart.fill") } .tag(option) } } .pickerStyle(InlinePickerStyle()) } label: { HStack { Text("Filter:") Text(selection) } .font(.headline) .foregroundColor(.white) .padding() .padding(.horizontal) .background(.blue) .cornerRadius(10) .shadow(color: Color.blue.opacity(0.3), radius: 10, x: 0, y: 10) }
@Ameer-pl9hl
@Ameer-pl9hl 4 ай бұрын
thank you, this actually really helped 🙏🏼
@raymundoortiz7269
@raymundoortiz7269 2 жыл бұрын
all programming tutorials should be like this!!, showing only 1 thing, but detailing many ways to use it... BRAVO!!!!
@Nortiz1349
@Nortiz1349 2 жыл бұрын
iOS 16+ Put the picker in the list ex) List { Picker(selection: $selection) { ForEach(filterOptions, id: \.self) { option in Text(option) .tag(option) } } label: { Text("Filter") } .pickerStyle(.inline) // .automatic .segement whatever }
@marlhex6280
@marlhex6280 Жыл бұрын
Thanks for styling the picker! on the todoList set pages per segmentedControl
@DavidShaw-dc4re
@DavidShaw-dc4re Жыл бұрын
This example no longer works in xcode 15.0.1
@afdreadbrizgaming1436
@afdreadbrizgaming1436 3 жыл бұрын
I am having a problem following along. I get all the way into the program until you Show the alternative, once you get to the @8:15 mark it gets tricky for me because Im not sure if its a different version of xcode. Im just getting into it now. I don't get the same result that you do. for some reason I still get the "1" instead of picker to come up on my view and I cannot write code for the button because it does not show up but I don't get any compilation errors when I follow along and that bothers me because I really want to understand it and I cant grasp it past that point
@rohitkulkarni4616
@rohitkulkarni4616 2 жыл бұрын
hey I think you and I are having the same issue, it works fine if you load it on a sim for ios 14.5 btw
@jamesgilligan671
@jamesgilligan671 10 күн бұрын
Love the video but my only wish is that you show us what to DO with the picker. IE how it works in a function, how to call the tags, etc. Good to have a picker but if I cant do anything with it then i am stuck. Thanks again.
@jay8412
@jay8412 3 жыл бұрын
Thanks for the video, please could you do a tutorial on implementing a Contact Picker
@serhii_rs
@serhii_rs 2 жыл бұрын
Thanks for the video lesson! You made my day!
@marinash231
@marinash231 2 жыл бұрын
Thank you for your brilliant videos!
@husseinawada8845
@husseinawada8845 Жыл бұрын
hello nick , the Label is not showing in the picker for xcode 14 , I've surffed the web about this problem and no one have an answer , so if you know how to solve it please upload a new video about it . thanks
@elemento_arts
@elemento_arts Жыл бұрын
I'm sure it's a bug. Can't show it either.
@erenoz87
@erenoz87 10 ай бұрын
Great content
@mhfs61
@mhfs61 3 жыл бұрын
Thank you for the video. You might want to consider a video about the picker view’s behaviour in other container views, like List, Form, ScrollView. Quite challenging.
@danielwatson6529
@danielwatson6529 3 жыл бұрын
Yea, picker is well picky. I hope this tut helps me out 🤣
@serhii_rs
@serhii_rs 2 жыл бұрын
Picker for iOS is changed in iOS 16. Could you make update for this?
@arnie9405
@arnie9405 Жыл бұрын
+1 here, the tutorial still sort of works the API seems to be the same but the rendered result is slightly different
@rohitkulkarni4616
@rohitkulkarni4616 2 жыл бұрын
Love this tutorial, seems as though the ability to customize the picker itself has some issues with iOS 15 (basically no matter what code you have itll just show the raw text), and this works perfectly fine if i load it onto an iOS 14.5 sim, has anyone found a way to make it work? I've seen a workaround to use Menu instead of picker but given the amount of people facing the issue i find it odd its been like this and also so close to iOS 16 release
@mattbinkowski3310
@mattbinkowski3310 3 жыл бұрын
Any thoughts on how to populate the picker when you've previously saved the selection in CoreData?
@SwiftfulThinking
@SwiftfulThinking 3 жыл бұрын
Hi Matt! This is very possible. You first need to download the data from CoreData, store it in an array, and then reference the array in your Picker! I will be doing a few videos on CoreData in the next week or two.
@raymundoortiz7269
@raymundoortiz7269 2 жыл бұрын
Very good video!!!
@andresraigoza2082
@andresraigoza2082 3 жыл бұрын
I love your way of teaching, thank you so much!!! I wanted to ask you. I am using Xcode 13 and now the label in the MenuPickerStyle does not show up on the screen. Do you know why?
@SwiftfulThinking
@SwiftfulThinking 3 жыл бұрын
Are you using the initializer with a Picker and a "label" ? It should still work in Xcode 13.
@andresraigoza2082
@andresraigoza2082 3 жыл бұрын
@@SwiftfulThinking Yes I am using picker with label. I found a way to do it on stack overflow, this is the code: Menu { Picker("Filter", selection: $selection) { ForEach(filterOptions, id: \.self) { option in HStack { Text(option) Image(systemName: "heart.fill") } .tag(option) } } .pickerStyle(InlinePickerStyle()) } label: { HStack { Text("Filter:") Text(selection) } .font(.headline) .foregroundColor(.white) .padding() .padding(.horizontal) .background(.blue) .cornerRadius(10) .shadow(color: Color.blue.opacity(0.3), radius: 10, x: 0, y: 10) } Do you think this is a good solution?
@AndresGutierrez-nb6qr
@AndresGutierrez-nb6qr Жыл бұрын
@@andresraigoza2082 Thank you for this work around 😉
@frankz2933
@frankz2933 2 жыл бұрын
I tried just now, and I found these modifiers for picker label don't work any more. -_-
@deanspann8163
@deanspann8163 2 жыл бұрын
Would it be possible for you to create a tutorial on creating dropdown pickers and storing that data in a firebase collection? Essentially creating a collection for user profile information, and then create a variable for gender that is displayed as a dropdown picker in the UI interface.
@marvinmeinhard4711
@marvinmeinhard4711 Жыл бұрын
Thank you for these Tutorials! Is there any native functionality to have a picker that allows multiple selections? e.g. whe i want a user to be able to select up to 3 options at a time? it seems that you have to build a workaround using a list...
@ostanjaffcompany173
@ostanjaffcompany173 3 жыл бұрын
Previously I tried this, but it doesn't work in a subview where a @Binding is used, It can only be used where the selected is kept in an @State variable, so it is not very useful as if it is used in the main view, this will be applied in all the pickers. init() { UISegmentedControl.appearance().selectedSegmentTintColor = UIColor.red UISegmentedControl.appearance().setTitleTextAttributes([.foregroundColor : UIColor.white], for: .selected) } Thanks anyway, I hope you can keep it up.
@SwiftfulThinking
@SwiftfulThinking 3 жыл бұрын
Yea,
@chuansun1269
@chuansun1269 3 жыл бұрын
讲得不错 ,对我帮助很大,谢谢你
@TeemoChan
@TeemoChan Жыл бұрын
This is how I did it to costumes the picker for the new update , I embedded the picker inside a menu {} label{} : @State var selectedNumber: Int = 0 var body: some View { Menu { Picker(selection: $selectedNumber , label: EmptyView()) { ForEach(0..
@vedantk23
@vedantk23 5 ай бұрын
Hey Nick, Is there any way to change the segmentColor without using UIKIT ?
@knowledgeispower4953
@knowledgeispower4953 10 ай бұрын
Good bro..☺
@muradjam
@muradjam Жыл бұрын
can you change the font of the Text in the picker (style = MenuPickerStyle) ?
@irfanrizvi161
@irfanrizvi161 3 жыл бұрын
Hi Nick, How do I make this Picker() select onLoad a default value from the filterOptions array?
@SwiftfulThinking
@SwiftfulThinking 3 жыл бұрын
Hey Irfan, you just need to set the "selection" to whatever value you want it to start at!
@dikshagaonkar1797
@dikshagaonkar1797 3 жыл бұрын
How to create a pickerview with multiple selection? Please help if possible
@SwiftfulThinking
@SwiftfulThinking 3 жыл бұрын
Hi Diksha, this is not a feature that's build into SwiftUI. You would have to make a custom picker, which is much more advanced. I will be covering some customizations like this in my SwiftUI Advanced Learning course coming soon.
@bigfoot131
@bigfoot131 2 жыл бұрын
Hi. Am currently teaching myself swift using ur tuts all is smooth apart from this picker is there another way to implement it am using Xcode 13.4 and apparently the picker is working but not the label part the text component and it’s modifiers.
@MahidAli6
@MahidAli6 5 ай бұрын
can we increase height of picker segment?? also the color of segement of picker isn't changing...
@mykosen5679
@mykosen5679 2 ай бұрын
To change the height, you can add this to the initializer: UISegmentedControl.appearance().setContentHuggingPriority(.defaultLow, for: .vertical) And then you'll be able to change the height with .frame(height: 100) for example.
@vladimirmoor
@vladimirmoor 3 жыл бұрын
Thanks for the video. A little comment: is iOS13 you can use only a wheel picker.
@Whyhardable
@Whyhardable 2 жыл бұрын
How would you get this picker to display on a ViewController?
@billsouthwick8123
@billsouthwick8123 2 жыл бұрын
I’m running iOS 15 and Xcode 13. In my first picker the picker is going from 99 to 18 even though I have 18..
@raymundoortiz7269
@raymundoortiz7269 2 жыл бұрын
Is it possible chance the strings inside the picker for ICONS or images?
@JeckyKA
@JeckyKA 3 жыл бұрын
awesome, thanks a lot!
@katoaapps5376
@katoaapps5376 2 жыл бұрын
Idk if I'm just broken or what but I have the exact same code running 15.2 emulator with xcode 13.2.1 and the style for the picker doesn't change from the default button blue text
@TheSpiralnotizblock
@TheSpiralnotizblock 2 жыл бұрын
Thats a bug from SwiftUI
@abdullahkardas8887
@abdullahkardas8887 2 жыл бұрын
accentColor will change it
@clewis9223
@clewis9223 2 жыл бұрын
Hi Nick, great video as always but I am afraid there is a big issue when placing two pickers side by side. The select overlays hit boxes clash and you have to select before the picker or after the picker to update the number. Luckily someone has provided an extension override. extension UIPickerView { open override var intrinsicContentSize: CGSize { return CGSize(width: UIView.noIntrinsicMetric, height: super.intrinsicContentSize.height) } }
@RahulSingh-s2m
@RahulSingh-s2m Жыл бұрын
editing on label is not working buddy in my code
@prabhakaryadav1759
@prabhakaryadav1759 9 ай бұрын
deprecated init format
@MrSkyydude
@MrSkyydude 2 жыл бұрын
You can pick your nose. You can pick your friends. But you can't pick your friends' nose.
@Horizon-tr6iy
@Horizon-tr6iy 2 жыл бұрын
14:50
@robertmartens7839
@robertmartens7839 3 жыл бұрын
indices is pronounced IN-DUH-SEES
@SwiftfulThinking
@SwiftfulThinking 3 жыл бұрын
😰 I really shoulda known that LOL c'est la vie.
@chezchezchezchez
@chezchezchezchez Жыл бұрын
For the love of God, stop saying "a-TRIB-utes" We stress the FIRST syllable with the word: attributes.
@rdr9999
@rdr9999 Ай бұрын
Because that’s what’s important here 🙄
@lowlydeveloper3693
@lowlydeveloper3693 29 күн бұрын
I think Nick has a license to pronounce "attributes" any way he likes considering the quality of his lessons. In fact, I am perfectly fine with "forward/backward slashes". Whichever. Don't matter. Just keep teaching the way you teach, Nick!
How to use ColorPicker in SwiftUI | Bootcamp #39
6:05
Swiftful Thinking
Рет қаралды 12 М.
How to use NavigationStack in SwiftUI | Bootcamp #62
23:59
Swiftful Thinking
Рет қаралды 37 М.
If people acted like cats 🙀😹 LeoNata family #shorts
00:22
LeoNata Family
Рет қаралды 31 МЛН
How Much Tape To Stop A Lamborghini?
00:15
MrBeast
Рет қаралды 252 МЛН
Евгений Елчев. SwiftUI и DI
42:34
CodeFest Russia
Рет қаралды 3,1 М.
Beat Ronaldo, Win $1,000,000
22:45
MrBeast
Рет қаралды 54 МЛН
Creating pickers in a form - WeSplit SwiftUI Tutorial  8/11
7:00
SwiftUI GeometryReader
27:53
Stewart Lynch
Рет қаралды 12 М.
Build 5 Apps in 5 Minutes with Flutter… But should you?
8:53
Display pop-up Sheets and FullScreenCovers in SwiftUI | Bootcamp #28
14:14
Super Power Scroll Views - SwiftUI - iOS 17
9:14
Sean Allen
Рет қаралды 29 М.
Stop using GeometryReader in SwiftUI
4:27
Flo writes Code
Рет қаралды 6 М.
If people acted like cats 🙀😹 LeoNata family #shorts
00:22
LeoNata Family
Рет қаралды 31 МЛН