Hey 😊
The way I went around this is by setting my variable to the current date when dismissing the picker.
@IBOutlet weak var dateTextField: UITextField!
var selectedDate: String = ""
private func createDatePicker() {
let currentDate = Date()
datePicker = UIDatePicker()
datePicker.datePickerMode = .date
if #available(iOS 14.0, *) {
datePicker.preferredDatePickerStyle = .inline
}
datePicker.maximumDate = currentDate
datePicker.addTarget(self, action: #selector(datePickerValueChanged(_:)), for: .valueChanged)
dateTextField.inputView = datePicker
dateTextField.inputAccessoryView = createToolbar()
}
private func createToolbar() -> UIView {
let toolbar = UIToolbar()
let doneButton = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(dismissDatePicker))
let flexSpace = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.flexibleSpace, target: nil, action: nil)
toolbar.sizeToFit()
toolbar.setItems([flexSpace, doneButton], animated: true)
return toolbar
}
private func setupDateFormatter() {
dateFormatter.dateStyle = .long
dateFormatter.locale = Locale(identifier: "en_GB")
}
@objc func dismissDatePicker() {
selectedDate = dateFormatter.string(from: datePicker.date)
dateTextField.text = selectedDate
endEditing(true)
}
@objc func datePickerValueChanged(_ sender: UIDatePicker) {
selectedDate = dateFormatter.string(from: sender.date)
dateTextField.text = selectedDate
}
Hope that helps.
Post
Replies
Boosts
Views
Activity
Hey @kaoko,
I don't know if you've found a solution to your problem, but the code below should be the solution to your problem.
import SwiftUI
import Lottie
struct LottieEmptyStateView: UIViewRepresentable {
var fileName: String
func makeUIView(context: UIViewRepresentableContext<LottieEmptyStateView>) -> some UIView {
let view = UIView(frame: .zero)
let lottieAnimationView = AnimationView()
let animation = Animation.named(fileName)
lottieAnimationView.animation = animation
lottieAnimationView.contentMode = .scaleAspectFit
lottieAnimationView.loopMode = .loop
lottieAnimationView.play()
lottieAnimationView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(lottieAnimationView)
NSLayoutConstraint.activate([
lottieAnimationView.widthAnchor.constraint(equalTo: view.widthAnchor),
lottieAnimationView.heightAnchor.constraint(equalTo: view.heightAnchor)
])
return view
}
func updateUIView(_ uiView: UIViewType, context: UIViewRepresentableContext<LottieEmptyStateView>) {
}
}
Hope that helped!
Kind regards,
William
Looks like hexadecimal data?
If that's the case, it could be translated using a hexadecimal to decimal converter.
Could you try to measure an object you know the length of, translate the values to decimal and see if they match?
If yes, then that could be a potential solution. Also, I think you can convert those values directly in Swift, following this StackOverflow post. - https://stackoverflow.com/questions/36966442/convert-between-decimal-binary-and-hexadecimal-in-swift
Best,
William