Scriptable制作iOS14小组件(2)昨天、今天、明天
把近三天放在桌面上,做啥就有了盼头!😁
“昨天、今天、明天”小组件代码
let g = new LinearGradient()
g.locations = [0, 2]
// 背景渐变色
g.colors = [
new Color("#FFFFE0"),
new Color("#E1FFFF")
]
// 昨天明天字体大小
let smallsize=80
// 今天字体大小
let bigsize=100
let date=new Date()
const str=date.getFullYear()+"年"+(date.getMonth()+1)+"月"
let day=new Date().getDate().toString()
let stamp= new Date().getTime()-60*60*24*1000
let stamp1= new Date().getTime()+60*60*24*1000
let prev=new Date(stamp).getDate().toString()
let next=new Date(stamp1).getDate().toString()
let widget = new ListWidget()
widget.backgroundGradient=g
widget.setPadding(0, 0, 0, 0)
let full=widget.addText(str)
full.centerAlignText()
full.textColor=new Color("#999")
let body = widget.addStack()
body.bottomAlignContent()
addDate(
prev,
smallsize,
body)
body.addSpacer()
addDate(
day,
bigsize,
body)
body.addSpacer()
addDate(
next,
smallsize,
body)
widget.presentMedium()
function addDate(name, size,r) {
let stack = r.addStack()
// stack.layoutVertically()
let wname = stack.addText(name)
// wname.font = Font.semiboldRoundedSystemFont(size)
wname.font=new Font("KaiTi", size)
wname.textColor = new Color("#999")
// stack.backgroundColor=new Color("#ccc")
if(size===smallsize){
let size=new Size(100, 100)
stack.size=size
stack.setPadding(0, 0, 0, 0)
wname.textColor = new Color("#999",0.6)
}
}