Scriptable制作iOS14小组件(3)

每天背诗三百首,不懂也是文化人!?????

“今日诗词”小组件代码

let url = "https://v2.jinrishici.com/one.json"
let req = new Request(url);
let json = await req.loadJSON();

// log(json)

let poem=json.data.origin.content[0]

let dotflag = /。|,|!|?/g
let dot=poem.match(dotflag)

poem=(poem.split(dotflag))
log(poem)

let str1=poem[0]
let str2=poem[1]

let str3=json.data.origin.author
let str4=json.data.origin.title


console.log(json.data.origin)

let widget = new ListWidget()

let lineColor=new LinearGradient()
// 自定义背景颜色
// widget.backgroundColor=new Color("#DC143C")

// 背景图片
let bgImg="https://d2w9rnfcy7mm78.cloudfront.net/8867234/original_63cd43c88048a9ff6279c0340faea9db.jpg?1601084036?bc=0"
const i = await new Request(bgImg);
const img = await i.loadImage();
widget.backgroundImage=img

log(str1.length)

  let first=widget.addText(str1+dot[0])
// 第一行自定义字体大小
  first.font=new Font("KaiTi", 35)
  first.textColor=new Color("#ffffff")

  let second=widget.addText(str2+dot[1])
//  第二行自定义字体大小 
  second.font=new Font("KaiTi", 35)
  second.textColor=new Color("#ffffff")
  second.rightAlignText()
  
  widget.spacing=14
//   作者信息
  let author=widget.addText("-"+str3+"《"+str4+"》")
  author.textColor=new Color("#ffffff")
  author.rightAlignText()
  
  widget.presentMedium()


Script.setWidget(widget)
Script.complete()

才艺展示

Scriptable制作iOS14小组件(3)

参考

Scriptable Docs

Scriptable制作iOS14小组件(3)

上一篇:114 01 Android 零基础入门 02 Java面向对象 04 Java继承(上)02 继承的实现 04 继承的初始化顺序


下一篇:https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/4.0.1/gradle-4.0.1.pom‘.