Post not yet marked as solved
I think this works. Try on simulator. Preview gives unpredictable results.
import SwiftUI
struct Amount {
var value: Decimal
var currency: CurrencyCode
}
struct ContentView: View {
@State var amount = Amount(value: Decimal(), currency: .GBP)
var body: some View {
CurrencyAmount(title: "Some label", amount: $amount)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView(amount: Amount(value: Decimal(), currency: .GBP))
}
}
struct CurrencyAmount: View {
let title: String
let prompt: String = ""
@Binding var amount: Amount
@State var currency: CurrencyCode = .GBP
var body: some View {
HStack {
Spacer(minLength: 80)
TextField(title, value: $amount.value, format: .currency(code: amount.currency.rawValue), prompt: Text(prompt))
CurrencyPicker(selected: $currency)
Spacer(minLength: 80)
}
.onChange(of: currency) { newValue in
amount.currency = newValue
}
}
}
struct CurrencyPicker: View {
@Binding var selected: CurrencyCode
let label = "Currency"
var body: some View {
Picker(label, selection: $selected) {
ForEach(CurrencyCode.allCases) {
Text($0.rawValue)
.tag($0)
}
}
}
}
enum CurrencyCode: String, CaseIterable, Identifiable {
var id: String { self.rawValue }
case AUD, CAD, EUR, GBP, NZD, USD
}
Post not yet marked as solved
In viewWillAppear, you are trying to trying to scroll to the first item? Does your collectionView have any data at this point?
For iOS 14, I think you have to subclass UICollectionViewListCell and override updateConfiguration(using state: UICellConfigurationState). It should work for iOS 15 also.
let cellConfiguration = UICollectionView.CellRegistration<MyCell, String>....
override func updateConfiguration(using state: UICellConfigurationState) {
super.updateConfiguration(using: state)
guard var cConfig = self.contentConfiguration?.updated(for: state) as? UIListContentConfiguration else { return }
cConfig.textProperties.colorTransformer = UIConfigurationColorTransformer { color in
state.isSelected || state.isHighlighted ? .white : .black
}
cConfig.secondaryTextProperties.colorTransformer = UIConfigurationColorTransformer { color in
state.isSelected || state.isHighlighted ? .white : .black
}
self.contentConfiguration = cConfig
guard var bConfig = self.backgroundConfiguration?.updated(for: state) else { return }
bConfig.backgroundColorTransformer = UIConfigurationColorTransformer { color in
state.isSelected || state.isHighlighted ? .systemPink : .systemGray5
}
self.backgroundConfiguration = bConfig
}
}
let cellConfigiuration = UICollectionView.CellRegistration<UICollectionViewListCell, String> { cell, indexPath, itemIdentifier in
var contentConfiguration = UIListContentConfiguration.sidebarSubtitleCell()
contentConfiguration.text = "Primary Text: \(itemIdentifier)"
contentConfiguration.secondaryText = "Secondary Text"
cell.contentConfiguration = contentConfiguration
var backgroundConfiguration = UIBackgroundConfiguration.listSidebarCell()
backgroundConfiguration.backgroundColor = .systemGray5
cell.backgroundConfiguration = backgroundConfiguration
cell.configurationUpdateHandler = { cell, state in
guard var cConfig = cell.contentConfiguration?.updated(for: state) as? UIListContentConfiguration else { return }
cConfig.textProperties.colorTransformer = UIConfigurationColorTransformer { color in
state.isSelected || state.isHighlighted ? .white : .black
}
cConfig.secondaryTextProperties.colorTransformer = UIConfigurationColorTransformer { color in
state.isSelected || state.isHighlighted ? .white : .black
}
cell.contentConfiguration = cConfig
guard var bConfig = cell.backgroundConfiguration?.updated(for: state) else { return }
bConfig.backgroundColorTransformer = UIConfigurationColorTransformer { color in
state.isSelected || state.isHighlighted ? .systemMint : .systemGray5
}
cell.backgroundConfiguration = bConfig
}
}
struct CardView: View {
@State var isFaceUp = false
var body: some View {
ZStack {
let shape = RoundedRectangle(cornerRadius: 20)
if isFaceUp {
shape.fill().foregroundColor(.white)
shape.stroke(lineWidth: 3)
Text("😀").font(.system(size: 80))
} else {
shape.fill()
}
}
.rotation3DEffect(Angle(degrees: isFaceUp ? 180 : 0), axis: (x: 0, y: 1, z: 0))
.animation(.spring(), value: isFaceUp)
.onTapGesture {
isFaceUp.toggle()
}
}
}
struct OpenTotal: Decodable {
var total: Double?
var overOdds: Int?
var underOdds: Int?
}
struct CurrentTotal: Decodable {
var total: Double?
var overOdds: Int?
var underOdds: Int?
}
Post not yet marked as solved
This might help
https://www.hackingwithswift.com/quick-start/swiftui/whats-the-difference-between-observedobject-state-and-environmentobject
Set horizontal hugging priority for 60 to 252 as suggested
Add a equal height constraint between EDIT TIMER DURATION and ANOTHER LABEL
Set vertical hugging priority for Duration to 1000
Set vertical hugging priority for Horizontal Slider to 1000
Post not yet marked as solved
https://support.apple.com/macos
Post not yet marked as solved
WKWebView does not handle anything automatically. You have to implement it.
Post not yet marked as solved
This API is broken https://developer.apple.com/documentation/mapkit/mklocalpointsofinterestrequest/ and either returns MKErrorGEOError=-8 or returns invalid results.
Have you tried this before you add the tableview as a subview to your view:
noteTableView.translatesAutoresizingMaskIntoConstraints = false
Post not yet marked as solved
This comes close
var body: some View {
List {
Section {
VStack (spacing: 20) {
HStack (spacing: 20) {
RoundedRectangle(cornerRadius: 12, style: .continuous)
.foregroundColor(Color(.systemRed))
RoundedRectangle(cornerRadius: 12, style: .continuous)
.foregroundColor(Color(.systemYellow))
}
.frame(height: 100)
HStack (spacing: 20) {
RoundedRectangle(cornerRadius: 12, style: .continuous)
.foregroundColor(Color(.systemGreen))
RoundedRectangle(cornerRadius: 12, style: .continuous)
.foregroundColor(Color(.systemBlue))
}
.frame(height: 100)
}
}
Section(header: Text("My Lists")) {
ForEach(1..<21) { index in
Text("\(index)")
}
}
}
.listStyle(InsetGroupedListStyle())
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
.preferredColorScheme(.dark)
}
}
Post not yet marked as solved
This appears to work
struct ContentView: View {
var body: some View {
NavigationView {
Text("Hello, world!")
.padding()
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
NavigationLink(
destination: Text("Destination"),
label: {
Label("Search", systemImage: "magnifyingglass")
})
}
}
}
}
}