首页 > 解决方案 > 在 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 中得到完全相同的结果。

在此处输入图像描述 如何在 iOS 中实现这一点。任何帮助将不胜感激。

标签: iosswifttextmultilingual

解决方案


我创建了一个扩展来更改某些特定字符串的颜色字体。

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

推荐阅读