iWatch开发:UI 组件说明

摘要:
WKInterfaceLabel在iOS组件中使用与WKInterfaceLabel类似的UILabel。可以使用setText设置详细值。使用WKInterfaceImage时,WKInterfaceImage类似于UIImageView。使用WKInterfaceImage时,可以使用setImage设置图片。其界面如下:@classUIImage@protocolWKImageAnimationable//使用界面描述中指定的持续时间重复播放所有图像-启动动画制作;//播放一组图像,持续时间为0分钟,直到停止-startAnimationWithImagesInRange:imageRangeduration:durationrepeatCount:repeatCount;-停止动画制作;@endWK_CLASS_AVAILABLE_IOS@interfaceWKInterfaceImage:WKInterfaceObject<WKImageAnimation>-setImage:image;-setImageData:imageData;-setImageNamed:imageName;-setTintColor:tintColor;@endNS_ ASSUME_ NONULL_与iOS中的UITableViewController相比,iwatch中的WKInterfaceTable函数要简单得多。它没有委托,也不需要设置数据源。这里我们使用静态数据来加载Table控件。例如,代码如下:NSMutableDictionary*phoneContact=[[NSMutabbleDictionaryalloc]initWithObjectsAndKeys:@“13776054770”,@“John”,@”1377605477“,@”John 1“,@“137760 4771”,@”John 2“,@“1377604772”,@:“John 3”,@;[_contactTableVsetNumberOfRows:phoneContact.countwithRowType:@“MyTableRowControl”];NSArray*namesArray=电话联系人。所有键;对于{NSString*name=[nameArrayobjectAtIndex:i];NSString*phone=[phoneContactobjectForKey:name];MyTableRowControl*row=[_contactTableVrowControllerAtIndex:i];[row.contactNamesetText:name],[row.phoneNosetText:phone];}table单击事件并重写它以实现InterfaceController来处理它:-table:tabledidSelectRowAtIndex:rowIndex{NSLog;}控件上的WKInterfaceButtonWatchbutton。

这里写图片描写叙述


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

好了。祝大家生活愉快。

多多收获友谊和爱情。

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

这里写图片描写叙述

免责声明:文章转载自《iWatch开发:UI 组件说明》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇UISwitch开关OpenCV——常用函数查询下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

ios开发 静态库制作

IOS程序是由Objective-c语言构成,而是Objective-c语言中每一个类又分成 .h .m 文件。静态库可以将这些程序的类封装成一个.a文件,第三方应用程序只需要拿到这个.a文件和代码对应的.h文件即可使用静态库中封装的方法。总的来说IOS静态库适合去制作第三方提供的SDK,废话不多说了我们直接进正题。 制作静态库 代码如下 1 #i...

iOS NSDictionary 转Json 去掉换行去掉空格

//dic 转json 如果用系统自带的会出现空格。 + (NSString *)returnJSONStringWithDictionary:(NSDictionary *)dictionary{ //系统自带 // NSError * error; // NSData *...

iOS获取所有机型

1.手机系统版本:10.3 NSString* phoneVersion = [[UIDevice currentDevice] systemVersion]; 2.手机类型:iPhone 6 NSString* phoneModel = [self iphoneType];//方法在下面 3.手机系统:iPhone OS NSString * ipone...

iOS 数据持久化 NSUserDefault

每一个应用都有一个 NSUserDefaults 实例,向 NSUserDefaults 类发送 standardUserDefaults 消息可以得到该实例。 NSUserDefaults 实例类似与 NSMutableDictionary,可以通过键存取或删除该对象。 当应用第一次使用 NSUserDefaults 实例时,NSUserDefaults...

iOS 拼接字符串

NSString  *str1=@"我爱"; NSString *str2=@"祖国"; (1)  NSString *all= [NSString stringWithFormat:@"%@>%@",str1,str2];    (2)  NSString *all2= [type stringByAppendingString:subtype];...

iOS项目之wifi局域网传输文件到iPhone的简单实现

如今手机发展非常迅速,app的种类也琳琅满目,而自从有了4G网之后,手机流量也越来越不够用了。所以现在越来越多的app有了本地文件的管理功能,方便用户随意浏览手机文件的同时,也为用户节约了流量的使用。 如上面的app截图中的功能,现在越来越多的app都具有了在电脑上通过网页wifi传输文件到手机端的功能,不仅有文字类,也有图片类,还有视频类,前提是电脑和...