zoukankan      html  css  js  c++  java
  • iWatch开发:UI 组件说明

    这里写图片描写叙述


    WKInterfaceLabel使用

    WKInterfaceLabel 相似iOS 组件中的UILabel, 可通过使用 setText 的方式来设置详细的值。这里就不做多阐述。

    WKInterfaceImage 使用

    WKInterfaceImage 相似于 UIImageView, 使用时,可用setImage 来设置图片。

    它的接口例如以下:

    @class UIImage;
    
    @protocol WKImageAnimatable <NSObject>
    
    // Play all images repeatedly using duration specified in interface description.
    - (void)startAnimating;
    
    // Play a subset of images for a certain number of times. 0 means repeat until stop.
    - (void)startAnimatingWithImagesInRange:(NSRange)imageRange duration:(NSTimeInterval)duration repeatCount:(NSInteger)repeatCount;
    
    - (void)stopAnimating;
    
    @end
    
    WK_CLASS_AVAILABLE_IOS(8_2)
    @interface WKInterfaceImage : WKInterfaceObject <WKImageAnimatable>
    
    - (void)setImage:(nullable UIImage *)image;
    - (void)setImageData:(nullable NSData *)imageData;
    - (void)setImageNamed:(nullable NSString *)imageName;
    
    - (void)setTintColor:(nullable UIColor *)tintColor;
    
    @end
    
    NS_ASSUME_NONNULL_END

    WKInterfaceTable

    相比于iOS 中的UITableViewController来说,iwatch中的WKInterfaceTable功能就简单多了。它没有delegate 也无需设置数据源。

    在组件库中选中WKInterfaceTable 拖入Interface.storyboard中,并在代码中形成相应的关联,这里有一点要注意一下,那就是这个必需要设置 Row Controller 的identifier, 不然数据就无法载入出来。

    在这里就使用静态的数据让这个Table 控件来载入出来。 代码例如以下:

    NSMutableDictionary *phoneContact = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"13776054770", @"约翰",
                                             @"13776054770", @"约翰1",
                                             @"13776054771", @"约翰2",
                                             @"13776054772", @"约翰3",
                                             @"13776054773", @"约翰4", nil];
    
        [_contactTableV setNumberOfRows:phoneContact.count withRowType:@"MyTableRowControl"];
        NSArray *namesArray = phoneContact.allKeys;
    
        for(int i = 0; i < phoneContact.count; i++){
            NSString *name = [namesArray objectAtIndex:i];
            NSString *phone = [phoneContact objectForKey:name];
    
            MyTableRowControl *row = [_contactTableV rowControllerAtIndex:i];
            [row.contactName setText:name];
            [row.phoneNo setText:phone];
        }

    table点击事件,通过重写实现InterfaceController 来处理:

    - (void)table:(WKInterfaceTable *)table didSelectRowAtIndex:(NSInteger)rowIndex{
        NSLog(@"我点击了 %ld 行", (long)rowIndex);
    }

    这里写图片描写叙述

    WKInterfaceButton

    iWatch button控件。可用的API 例如以下:

    NS_ASSUME_NONNULL_BEGIN
    
    @class UIImage, UIColor;
    
    WK_CLASS_AVAILABLE_IOS(8_2)
    @interface WKInterfaceButton : WKInterfaceObject
    
    - (void)setTitle:(nullable NSString *)title;
    - (void)setAttributedTitle:(nullable NSAttributedString *)attributedTitle;
    
    - (void)setBackgroundColor:(nullable UIColor *)color;
    - (void)setBackgroundImage:(nullable UIImage *)image;
    - (void)setBackgroundImageData:(nullable NSData *)imageData;
    - (void)setBackgroundImageNamed:(nullable NSString *)imageName;
    
    - (void)setEnabled:(BOOL)enabled;
    
    @end
    
    NS_ASSUME_NONNULL_END

    button点击事件,能够通过storyboard 拖拽的方式来实现,也可通过代码来实现。

    WKInterfaceDate

    日期控件,可用API 例如以下:

    NS_ASSUME_NONNULL_BEGIN
    
    @class UIColor;
    
    WK_CLASS_AVAILABLE_IOS(8_2)
    @interface WKInterfaceDate : WKInterfaceObject
    
    - (void)setTextColor:(nullable UIColor *)color;
    
    - (void)setTimeZone:(nullable NSTimeZone *)timeZone;
    - (void)setCalendar:(nullable NSCalendar *)calendar;
    
    @end
    
    NS_ASSUME_NONNULL_END

    WKInterfaceTimer

    时间控件, 可用 API 例如以下:

    NS_ASSUME_NONNULL_BEGIN
    
    @class UIColor;
    
    WK_CLASS_AVAILABLE_IOS(8_2)
    @interface WKInterfaceTimer : WKInterfaceObject
    
    - (void)setTextColor:(nullable UIColor *)color;
    
    - (void)setDate:(NSDate *)date; // count up/down from current date to this date
    - (void)start;
    - (void)stop;
    
    @end
    
    NS_ASSUME_NONNULL_END

    好了。祝大家生活愉快。

    多多收获友谊和爱情。

    假设想获取很多其它的讯息。请扫描下方二维码关注我的微信公众号:

    这里写图片描写叙述

  • 相关阅读:
    完爆!用边缘容器,竟能秒级实现团队七八人一周的工作量
    手把手教你使用 cert-manager 签发免费证书
    手把手教你使用 Nginx Ingress 实现金丝雀发布
    Codeforces 534B Covered Path 贪心
    Codeforces 534A Exam 水
    Topcoder open 2015 Round 1A 250 Similars 枚举 + 状压
    Topcoder SRM 654 DIV1 500 FoldingPaper2 递归 + 枚举
    Topcoder SRM655 DIV2 250 BichromeBoard 水
    2015 Google code jam Qualification Round B 枚举 + 贪心
    2015 Google code jam Qualification Round A 水
  • 原文地址:https://www.cnblogs.com/llguanli/p/8647212.html
Copyright © 2011-2022 走看看