所以我试图在iOS中实现一个简单的英语到波斯语词典
我希望在一个表格单元格中包含这两个单词,问题是英语是L&gt; R而波斯语是R> L,我也想让波斯语单词更大一些。< / p>
我创建了一个AttributedMutableString,我认为我放下了所有正确的值,但它看起来有问题,因为它没有正确呈现。
代码:
cell.textLabel?.numberOfLines = 0
var myString = "\(englishConvo[indexPath.row])\n\(farsiConvo[indexPath.row])"
var mutableString = NSMutableAttributedString()
var lenOfLang1 = englishConvo[indexPath.row].characters.count
var lenOfLang2 = farsiConvo[indexPath.row].characters.count
let increaseFontSize = UIFont(name: (cell.textLabel?.font.fontName)!, size: (cell.textLabel?.font?.pointSize)! + 5)
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = NSTextAlignment.Right
mutableString = NSMutableAttributedString(string: myString)
mutableString.addAttribute(NSParagraphStyleAttributeName, value: paragraphStyle, range: NSRange(location: lenOfLang1 + 1, length: lenOfLang2))
mutableString.addAttribute(NSFontAttributeName, value: increaseFontSize!, range: NSRange(location: lenOfLang1 + 1, length: lenOfLang2))
cell.textLabel?.attributedText = mutableString
如果我使用此代码转换为字符串,这就是我得到的
cell.textLabel?.text = String(mutableString)
任何想法/想法都会受到超级赞赏