簡體   English   中英

迅捷4將圖像文字添加到字符串

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM