-
Notifications
You must be signed in to change notification settings - Fork 207
xuwhale6 edited this page Jan 21, 2021
·
31 revisions
ArgoUI作为一款高性能、小巧的开发框架,支持声明式开发和数据绑定技术,编程操作简单,代码简洁易维护。
现在让我们通过一个简单小例子来开启ArgoUI的学习之旅吧!
ui{
--layout views
--在这里编写声明式布局、放置控件和设置属性等
}
local function preview()
--在这里初始化数据
end
1.model声明
model(weChatData)
local function preview()
weChatData.background = "https://s.momocdn.com/w/u/others/custom/MLNUI/background.jpg"
weChatData.list = {
{
type = 1,
iconUrl = "https://s.momocdn.com/w/u/others/custom/MLNUI/case5.png",
name = "小小花",
content = "从明天开始,做一个幸福的人",
img = "https://s.momocdn.com/w/u/others/custom/MLNUI/naicha.jpg",
level = 18,
show = false
},
{
type = 2,
iconUrl = "https://s.momocdn.com/w/u/others/custom/MLNUI/case4.png",
name = "小小峰",
content = "玉枕佳人绮罗裙。将军令,勒石燕然。少年重帘黄粱梦,起坐思量待天明。昨夜星辰,昨夜风今宵酒,今宵梦,何处醒?可有春风得意马蹄疾;还能一日看尽长安花?青春早为,人无长少年。",
img = "https://s.momocdn.com/w/u/others/custom/MLNUI/bg1.jpg",
level = 10,
show = false
}
}
weChatData.unCheckedUrl = "https://s.momocdn.com/w/u/others/custom/MLNUI/unChecked.png"
weChatData.CheckedUrl = "https://s.momocdn.com/w/u/others/custom/MLNUI/Checked.png"
end
--子模块参数涉及model时,需使用mark_data标记
mIcon(mark_data(item)) {
VStack().subs(
ImageView(item.iconUrl).style(Style.iconImg),
Label(tostring(item.level)).style(Style.iconLevel)
).crossAxis(CrossAxis.CENTER)
}
--在UI布局中进行调用,运行效果如下图所示
--- UI
ui {
--- layout views
mIcon()
}
4.定义样式表
local Style = {
cellContentImg = {
height(100),width(150),
contentMode(ContentMode.SCALE_ASPECT_FILL),
paddingTop(20)
},
cellName = {
textColor(Color(0, 154, 205, 1)),fontSize(18)
},
cellContent = {
fontSize(16),paddingTop(10)
},
cellFavorite = {
height(20),width(20),crossSelf(CrossAxis.END)
},
iconImg = {
height(50),width(50)
},
iconLevel = {
fontSize(12),bgColor(Color(183, 223, 127)),
padding(2,8,2,8),cornerRadius(7.5),top(2)
}
}
infoCell(mark_data(item)) {
VStack()
.widthPercent(90)
.subs(
HStack()
.widthPercent(100)
.padding(20, 20, 3, 10)
.subs(
mIcon(item)
,
VStack().left(20)
.subs(
Label(item.name).style(Style.cellName)
,
Label(item.content).style(Style.cellContent).lines(6)
,
ImageView(item.img).style(Style.cellContentImg).display(item.type == 1)
).shrink(1)
),
ImageView((item.show and { weChatData.CheckedUrl } or { weChatData.unCheckedUrl })[1])
.style(Style.cellFavorite).crossSelf(CrossAxis.END)
.onClick(
function()
item.show.toggle()
end
)
)
}
--在ui中为List绑定cell,运行效果图如下
--- UI
ui{
--- layout views
List(weChatData.list)
.bindCell(function(item)
return infoCell(item)
end)
}
ui {
--- layout views
ImageView(weChatData.background)
.heightPercent(30)
.widthPercent(100)
.contentMode(ContentMode.SCALE_ASPECT_FILL)
,
List(weChatData.list)
.bindCell(function(item)
return infoCell(item)
end).basis(0).grow(1)
}
点击查看完整demo
model(weChatData)
local Style = {
cellContentImg = {
height(100), width(150), contentMode(ContentMode.SCALE_ASPECT_FILL),
paddingTop(20)
},
cellName = {
textColor(Color(0, 154, 205, 1)), fontSize(18)
},
cellContent = {
fontSize(16), paddingTop(10)
},
cellFavorite = {
height(20), width(20), crossSelf(CrossAxis.END)
},
iconImg = {
height(50), width(50)
},
iconLevel = {
fontSize(12), bgColor(Color(183, 223, 127)),
padding(2, 8, 2, 8), cornerRadius(7.5), top(2)
}
}
mIcon(mark_data(item)) {
VStack().subs(
ImageView(item.iconUrl).style(Style.iconImg),
Label(tostring(item.level)).style(Style.iconLevel)
).crossAxis(CrossAxis.CENTER)
}
infoCell(mark_data(item)) {
VStack()
.widthPercent(90)
.subs(
HStack()
.widthPercent(100)
.padding(20, 20, 3, 10)
.subs(
mIcon(item)
,
VStack().left(20)
.subs(
Label(item.name).style(Style.cellName)
,
Label(item.content).style(Style.cellContent).lines(6)
,
ImageView(item.img).style(Style.cellContentImg).display(item.type == 1)
).shrink(1)
),
ImageView((item.show and { weChatData.CheckedUrl } or { weChatData.unCheckedUrl })[1])
.style(Style.cellFavorite).crossSelf(CrossAxis.END)
.onClick(
function()
item.show.toggle()
end
)
)
}
---
--- UI
ui {
--- layout views
ImageView(weChatData.background)
.heightPercent(30)
.widthPercent(100)
.contentMode(ContentMode.SCALE_ASPECT_FILL)
,
List(weChatData.list)
.bindCell(function(item)
return infoCell(item)
end).basis(0).grow(1)
}
---
--- preview
local function preview()
weChatData.background = "https://s.momocdn.com/w/u/others/custom/MLNUI/background.jpg"
weChatData.list = {
{
type = 1,
iconUrl = "https://s.momocdn.com/w/u/others/custom/MLNUI/case5.png",
name = "小小花",
content = "从明天开始,做一个幸福的人",
img = "https://s.momocdn.com/w/u/others/custom/MLNUI/naicha.jpg",
level = 18,
show = false
},
{
type = 2,
iconUrl = "https://s.momocdn.com/w/u/others/custom/MLNUI/case4.png",
name = "小小峰",
content = "玉枕佳人绮罗裙。将军令,勒石燕然。少年重帘黄粱梦,起坐思量待天明。昨夜星辰,昨夜风今宵酒,今宵梦,何处醒?可有春风得意马蹄疾;还能一日看尽长安花?青春早为,人无长少年。",
img = "https://s.momocdn.com/w/u/others/custom/MLNUI/bg1.jpg",
level = 10,
show = false
}
}
weChatData.unCheckedUrl = "https://s.momocdn.com/w/u/others/custom/MLNUI/unChecked.png"
weChatData.CheckedUrl = "https://s.momocdn.com/w/u/others/custom/MLNUI/Checked.png"
end
- 附:运行效果图,可实现基本的点赞功能。编辑代码时可在模拟器中及时操作动态界面,快去动手试试吧!