:wave: Is anyone knows why `UIDatePicker` is not c...
# ios
a
👋 Is anyone knows why
UIDatePicker
is not centered ? Simulator, iOS 17 🧵 Same on the real device
1
Screenshot 2024-08-01 at 10.36.30 PM.png
Copy code
val controller = LocalUIViewController.current
val controllerView = controller.view
val screenWidth = UIScreen.mainScreen.bounds.useContents { size.width }.toDouble()
val screenHeight = UIScreen.mainScreen.bounds.useContents { size.height }.toDouble()

UIDatePicker(
   frame = CGRectMake(
      x = 0.0,
      y = screenHeight - datePickerHeight,
      width = screenWidth,
      height = datePickerHeight
)
For anyone who is curious, that how I fixed it: By adding following lines in
UIDatePicker
initialization:
Copy code
translatesAutoresizingMaskIntoConstraints = false

            controllerView.addSubview(this)

            NSLayoutConstraint.activateConstraints(
                listOf(
                    this.leftAnchor.constraintEqualToAnchor(controllerView.leftAnchor),
                    this.rightAnchor.constraintEqualToAnchor(controllerView.rightAnchor),
                    this.bottomAnchor.constraintEqualToAnchor(controllerView.bottomAnchor),
                )
            )
m
Thank you for this 🙏