ios - 在 iOS 中加载旁遮普语文本
问题描述
我收到了来自后端的以下表格的回复,我想同时显示旁遮普语、Gurmukhi 旁遮普语和英语的内容,
{
"AK_Index" = "APNE SEVAK KEE AAPE RAKE";
Ang = 747;
Author = "Guru Arjan Dev Ji";
Bani = "<null>";
"Bani_ID" = "<null>";
English = "Guru Nanak has met the Supreme Lord God; I am a sacrifice to Your Feet. ||4||1||47||";
"English_Initials" = gnmptckb;
Gurmukhi = "guru nwnku imilAw pwrbRhmu qyirAw crxw kau bilhwrw ]4]1]47]";
"Gurmukhi_Initials" = "gnmpqckb]";
ID = 32133;
Kirtan = Kirtan;
"Kirtan_ID" = 2853;
Punjabi = "gurU nwnk Awpxy prm pRBU nUM iml ipAw hY Aqy aus dy pYrW qoN GolI jWdw hY[";
Raag = "Raag Soohee";
"Teeka_Arth" = "hy pRBU! mYN qyry crnW qoN sdky jWdw hW[ ijs mnu`K nUM gurU nwnk iml ipAw, aus nUM prmwqmw iml ipAw ]4]1]47]";
"Teeka_Pad_Arth" = "kau = nUM, qoN ]4]1]47]";
}
附件是屏幕截图,结果会是什么样子。截图来自安卓。我想在 iOS 中得到完全相同的结果。
解决方案
我创建了一个扩展来更改某些特定字符串的颜色字体。
extension NSMutableAttributedString {
func setFontColorAndSize(_ textToFind : String,withColor color: UIColor,andFont font :UIFont){
let range = self.mutableString.range(of: textToFind, options: .caseInsensitive)
if range.location != NSNotFound {
setAttributes([NSAttributedStringKey.font : font,NSAttributedStringKey.foregroundColor :color], range: range)
}
}
// This is how you change
let resultString = NSMutableAttributedString(string: "hello") // convert any string to mutable attributed
resultString.setFontColorAndSize("hel", withColor: UIColor.grey, andFont: UIFont.boldSystemFont(ofSize: 17)) // pass the string you want to set particular color and font
UILabel.attributedText = resultString // than update the label
推荐阅读
- javascript - 在 ng-bootstrap 模式中构建数据表的问题
- javascript - 在 index.html 中使用环境变量
- vega - Vega-Lite - 处理大量数据的最佳方式是什么?
- sql-server - 为什么下面的 t-sql 事务不能按预期工作?
- r - R:如果日期差小于 7,则按组从前一行添加值
- java - 在 setItems() 之后无法在表格视图中查看单元格中的数据
- codeigniter - 错误链接到带有 href 的另一个页面(我的 localhost url 中的 %E2%80%8B 代码出错)
- c# - 可以从应用程序中删除“政策后参考”吗?
- r - 如何在 R 的系统命令中运行“conda ***”
- jpa - Spring JPA DDL 文件生成 - 如何在生成之前删除或清理文件