【发布时间】:2019-05-22 19:15:06
【问题描述】:
我希望能够将图像添加到带有一些文本的字符串中。 headerViews 上有一个示例视频,他包含了在字符串中嵌入图像的数据。
我不知道他是怎么做到的。
这是数据
Section(genre: "???? Superhero",
movies: ["Guardians of the Galaxy", "The Flash", "The Avengers", "The Dark Knight"],
expanded: false,
subtitle: "Please select a movie"),
Section(genre: "???? Horror",
movies: ["The Walking Dead", "Insidious", "Conjuring"],
expanded: false,
subtitle: "Please select a movie")
Section是一个简单的数据结构:
struct Section {
let genre: String!
let movies: [String]!
let expanded: Bool!
let subtitle: String!
init(genre: String, movies: [String], expanded: Bool, subtitle: String){
self.genre = genre
self.movies = movies
self.expanded = expanded
self.subtitle = subtitle
}
之后我尝试使用#imageLiteral(resourceName) 和一些文本,例如
" #imageLiteral(resourceName: "pos") + "a title" "
语法不正确。
如何在字符串中的某些文本之前添加图像?
【问题讨论】:
标签: swift string image-literals