[英]swift 4 add a image literal to a string
我希望能夠將圖像添加到帶有一些文本的字符串中。 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字符串是unicode字符串,因此您可以直接在字符串文字中鍵入表情符號字符。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.