Preventing line breaks in part of an NSAttributedString

后端 未结 3 811
一个人的身影
一个人的身影 2020-12-28 17:56

I am working on a UILabel which features large main text followed by smaller text that tells you who said it:

3条回答
  •  执笔经年
    2020-12-28 18:05

    @brian-nickel great solution in Swift 5.1 and in a String extension

    extension String {
        var withoutLineBreak: String {
            self.replacingOccurrences(of: " ", with: "\u{a0}")
                .replacingOccurrences(of: "-", with: "\u{2011}")
        }
    }
    

提交回复
热议问题