编程知识 cdmana.com

How to use the old style picker in IOS

  iOS 14 UIDatePicker stay 13.4 Added 2 The attributes are as follows

  @property (nonatomic, readwrite, assign) UIDatePickerStyle preferredDatePickerStyle API_AVAILABLE(ios(13.4)) API_UNAVAILABLE(tvos, watchos);

  @property (nonatomic, readonly, assign) UIDatePickerStyle datePickerStyle API_AVAILABLE(ios(13.4)) API_UNAVAILABLE(tvos, watchos);

  

  1. typedef NS_ENUM(NSInteger, UIDatePickerStyle) { /// Automatically pick the best style available for the current platform & mode.
  2. UIDatePickerStyleAutomatic, /// Use the wheels (UIPickerView) style. Editing occurs inline.
  3. UIDatePickerStyleWheels, /// Use a compact style for the date picker. Editing occurs in an overlay.
  4. UIDatePickerStyleCompact, /// Use a style for the date picker that allows editing in place.
  5. UIDatePickerStyleInline API_AVAILABLE(ios(14.0)) API_UNAVAILABLE(tvos, watchos), }
  6. API_AVAILABLE(ios(13.4)) API_UNAVAILABLE(tvos, watchos);

   The original interface selector style becomes a new one , The default is set to UIDatePickerStyleAutomatic, Take a look at the notes Use the wheels (UIPickerView) style. Editing occurs inline.

  

   It's on the top when it's displayed , When you select a date, it becomes a calendar control

   Then how can we change it into the original style ?

   Go straight to the code

  if (@available(iOS 13.4, *))

{ _datePicker.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];// The new discovery here doesn't change according to the language of the system

_datePicker.preferredDatePickerStyle = UIDatePickerStyleWheels; }

else

{ // Fallback on earlier versions }

   According to the interface style in the project , Found out 2 A question ,
1.UIDatePicker It's no use setting the background color , It's transparent .
2. The language doesn't change according to the system language , Set it to Chinese by yourself .

  

 

 

  

   We'll find that it's really the rolling gear style before , But the position is not the width of the screen , Here we need to reset it after the style UIDatePicker Of frame

 

   // I set it up here before frame No problem , however iOS13.4 And then it doesn't work

  self.datePicker = [[UIDatePicker alloc]initWithFrame:CGRectMake(0,40, KscreenWidth, 230)];

    // Set the style of the date selector

    if (@available(iOS 13.4, *))

    {

        self.datePicker.preferredDatePickerStyle=UIDatePickerStyleWheels;

    } else {

        // Fallback on earlier versions

    }

    // Notice the date selector's frame You need to reset after setting the style , Set... On it frame It doesn't work

    [self.datePicker setFrame:CGRectMake(0,40, KscreenWidth, 230)];

 

 

   The effect is as follows

 

 

版权声明
本文为[Happy son of heaven]所创,转载请带上原文链接,感谢
https://cdmana.com/2020/12/20201224135554223p.html

Scroll to Top