0

画像のように設定したのですが、年/月/日/時/分になっており、年が表示されてしまいます。
これを年を無くし[月/日/時/分]表示にするにはどうしたら良いのでしょうか?
Elementsでは対処することができずわかりません、よろしくお願いいたします。
画像の説明をここに入力

2 件の回答 2

0

Storyboardエディターで表示されるElementsの項目は、NSDatePickerのこちらのプロパティに対応するようです。

datePickerElements

A bitmask that indicates which visual elements of the date picker are
currently shown, and which won't be usable because they are hidden.

Discussion

See “Constants” in NSDatePickerCell for a description of the possible values.

リンク先を辿ると、使用可能な定数の一覧が出てきます。

NSDatePickerElementFlags

Constants

static var hourMinuteDatePickerElementFlag: NSDatePickerElementFlags

Display and allow editing of the hour and minute elements of the date.

static var hourMinuteSecondDatePickerElementFlag: NSDatePickerElementFlags

Display and allow editing of the hour, minute and second elements of
the date.

static var timeZoneDatePickerElementFlag: NSDatePickerElementFlags

Display and allow editing of the time zone.

static var yearMonthDatePickerElementFlag: NSDatePickerElementFlags

Display and allow editing of the year and month elements of the date.

static var yearMonthDayDatePickerElementFlag: NSDatePickerElementFlags

Display and allow editing of the year, month and day elements of the
date.

static var eraDatePickerElementFlag: NSDatePickerElementFlags

Display and allow editing of the era of the date, if applicable.

定義されているのは、上記6つの定数だけです。MonthとDayだけを定義した定数がないのは、英語の説明部分を読まなくてもすぐにお分かりだと思います。

最初のプロパティの説明にあるように、こちらの値は bitmask なので、月と日に対応すると思われるビットだけを設定してみたのですが、そのような不正な値を指定すると 日付部分自体が全く表示されなくなってしまいました

私の試し方・探し方が悪かっただけという可能性もありますが、NSDatePickerは、年を省いた「月/日」の形式で日付部分を表示・編集することはできないようにデザインされている と考えた方が良いように思います。

どうしても「月/日」の表示にしたければ、NSDatePickerを使わず、他のコントロールを組み合わせたり、カスタムコントロールを自作する必要があるでしょう。

1
  • ご回答ありがとうございます。 自前での実装をしたいと思います。
    – ra-men
    2017年4月22日 1:25
0

iOSではなく、macOSのNSDatePickerですよね?

Appleの公式ドキュメントを見る限り、
https://developer.apple.com/reference/appkit/nsdatepickerelementflags
「年」抜きの「月/日」は用意されていないようです。
おそらく、2/29が問題になるためかと思われます

ですので、

これを年を無くし[月/日/時/分]表示にするにはどうしたら良いのでしょうか?

については「月/日」は自前で実装してやる必要があります。

1
  • ご回答ありがとうございます。 自作で実装を目指します
    – ra-men
    2017年4月22日 1:28

この質問に回答するには、ログインする必要があります。

求めていた回答ではありませんか? のタグが付いた他の質問を参照する。