简单的可以参考这个博客TopShelf
官网TopShelf
var topShelfStyle: TVTopShelfContentStyle {
return .sectioned
}
var topShelfItems: [TVContentItem] {
let ID = TVContentIdentifier(identifier: "identifier1", container: nil)
let Item = TVContentItem(contentIdentifier: ID)
var Items = [TVContentItem]()
for i in 0 ..< 8 {
do {
let identifier = TVContentIdentifier(identifier: "identifier2", container: ID)
let contentItem = TVContentItem(contentIdentifier: identifier )
if let url = NSURL(string: ["https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=1416240957,410020165&fm=58","https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=216248366,1253432148&fm=58","https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=3314685794,229436694&fm=58","https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=1316079114,162208842&fm=58","https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=470891324,227323529&fm=58","https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=3495368848,1024610533&fm=58","https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=3305383698,853442007&fm=58","https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=1778394871,4237479606&fm=58"][i])
{
contentItem.imageURL = url as URL
contentItem.imageShape = .poster
contentItem.title = ["星球大战","老炮儿","寻龙诀","我滴个神啊","神探夏洛克","夏洛特烦恼","游戏","不可思异"][i]
contentItem.displayURL = NSURL(string: "hehe://\(i)") as! URL
contentItem.playURL = NSURL(string: "hehe://\(i)") as! URL
}
Items.append(contentItem)
}
}
Item.title = "热门电影"
Item.topShelfItems = Items
let ID1 = TVContentIdentifier(identifier: "identifier2", container: nil)
let Item1 = TVContentItem(contentIdentifier: ID1)
Item1.title = "呵呵"
Item1.topShelfItems = Items
return [Item,Item1]
}
效果如图:
效果图
网友评论