Watch OS 2 Complication开发教程(三)基本数据(持续连载中)

那么经过讲解,我们来看一看怎么实现数据的传输

首先我们先在最后面加入一个帮助函数

private func templateForWatch() ->CLKComplicationTemplate{
        let template = CLKComplicationTemplateModularLargeStandardBody()
        template.headerImageProvider = CLKImageProvider(onePieceImage: UIImage(named: "x2")!)
        template.headerTextProvider = CLKSimpleTextProvider(text: "TitleHello")
        template.body1TextProvider = CLKSimpleTextProvider(text: "HelloWorld, the content is not blank any more")
        return template
    }

如果不明觉厉的话请看我的 上一篇Blog

里面的

        template.headerTextProvider = CLKSimpleTextProvider(text: "TitleHello")
        template.body1TextProvider = CLKSimpleTextProvider(text: "HelloWorld, the content is not blank any more")

可以在text:后面传值,只要传的是一个字符串(String)即可

那么完成了这个函数后我们找到getCurrentTimelineEntryForComplication这个函数

往里面加入以下代码

        let entries = CLKComplicationTimelineEntry(date: NSDate(), complicationTemplate: templateForWatch())
        handler(entries)

这是什么呢?

我们首先构造一个CLKCompliactionTimelineEntry常量,包含一个NSDate和一个Template(也就是我们的templateForWatch返回的Template)

然后把这个常量传给handler

大功告成!

PS:因为这个Complication目前没有任何的在时间改变时改变内容的操作,我们可以在getSupportedTimeTravelDirectionsForComplication函数中这样写

func getSupportedTimeTravelDirectionsForComplication(complication: CLKComplication, withHandler handler: (CLKComplicationTimeTravelDirections) -> Void) {
        handler([.None])
    }

这样的话就不支持timeTravel啦


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值