11
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

watchOS 2から追加されたWKInterfacePickerメモ

Last updated at Posted at 2015-06-10

watchOS 2からWKInterfacePickerが使えるようになってました。

iOSで言う UIPickerView のWatch版といったところでしょうか。
NDA期間のため、スクリーンショットは自粛します。

特徴は次の通り。

  • デジタルクラウンでPickerを回せる
  • 各アイテムにはテキストだけでなく、画像も使える(テキストの左に小さく表示される)
  • Pickerは複数設置可能
    • フォーカスを合わせるためには - focusForCrownInput メソッドを使う
  • 選択された値が変わる度に任意のアクションメソッドを呼べる
    • 選択中の index が取れる

サンプルコード:

@interface InterfaceController()
@property (strong, nonatomic) IBOutlet WKInterfacePicker *picker;
@property (strong, nonatomic) NSArray *pickerItems;
@end

@implementation InterfaceController

- (void)awakeWithContext:(id)context
{
    [super awakeWithContext:context];

    // Configure interface objects here.
    WKPickerItem *pickerItem1 = [WKPickerItem alloc];
    [pickerItem1 setTitle:@"First item"];
    [pickerItem1 setAccessoryImage:[WKImage imageWithImageName:@"Smile"]];
    
    WKPickerItem *pickerItem2 = [WKPickerItem alloc];
    [pickerItem2 setTitle:@"Second item"];
    [pickerItem2 setAccessoryImage:[WKImage imageWithImageName:@"Smile"]];

    WKPickerItem *pickerItem3 = [WKPickerItem alloc];
    [pickerItem3 setTitle:@"Third item"];
    [pickerItem3 setAccessoryImage:[WKImage imageWithImageName:@"Smile"]];

    self.pickerItems = [[NSArray alloc] initWithObjects:pickerItem1, pickerItem2, pickerItem3, nil];
    [self.picker setItems:self.pickerItems];
}

- (IBAction)pickerAction:(NSInteger)value
{
    NSLog(@"value = %d", value);
}
11
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?