2017-05-10 6 views
1

J'ai récemment remarqué que le texte en exposant comme un NSAttributedString ne fonctionne plus sur iOS 10.3.L'attribut exposant ne fonctionne plus sur iOS 10.3

Est-ce que quelqu'un d'autre a remarqué cela? Ce code utilisé pour travailler et faire mon symbole enregistré superscript:

func setSuperScript(forSuperScriptString superScriptString:String, withFont font:String, atSize size:CGFloat){ 

    if self.text != nil { 

     let mutableAttString:NSMutableAttributedString = NSMutableAttributedString(string:self.text!) 

     for (i,c) in self.text!.characters.enumerated() { 

      if c == Character(superScriptString) { 

       let range = NSRange(location:i,length:1) 

       // for each occurence of the character to superscript 
       mutableAttString.addAttribute(NSFontAttributeName, value: UIFont(name: font, size: size)!, range: range) 
       mutableAttString.addAttribute(kCTSuperscriptAttributeName as String, value:1, range: range) 
      } 
     } 

     self.attributedText = mutableAttString 
    } 
} 

Cette ligne mutableAttString.addAttribute(kCTSuperscriptAttributeName as String, value:1, range: range) fonctionne sur les appareils fonctionnant sous iOS 10.2 mais ne pas sur la dernière version d'iOS.

+0

Que * exactement * ne fonctionne plus? S'il vous plaît montrer un code Swift (?) Qui a fonctionné avant et ne fonctionne plus. – luk2302

+2

https://openradar.appspot.com/31321619? – Larme

+0

Pas seulement moi alors! THX. –

Répondre

0

J'ai ce code à SuperScript cents sur une étiquette de monnaie et il fonctionne très bien depuis iOS 8 à 10.3.1:

func formatLabelToCurrency(label: UILabel)-> UILabel { 
    var decimalSeparator: String = "." 
    let font:UIFont? = UIFont(name: "Helvetica", size:20) 
    let fontSuper:UIFont? = UIFont(name: "Helvetica", size:10) 
    let attString:NSMutableAttributedString = NSMutableAttributedString(string: label.text!, attributes: [NSFontAttributeName:font!]) 
    attString.setAttributes([NSFontAttributeName:fontSuper!,NSBaselineOffsetAttributeName:10], range: NSRange(location:(label.text?.index(of: decimalSeparator))!,length:3)) 
    label.attributedText = attString; 
    return label 
} 
+0

Bonne correction. J'ai utilisé ceci pour réparer mon problème. Mais, ce n'est pas la réponse, et il semble que ce soit un bug dans iOS 10.3 ou une dépréciation. –

+0

Oui, c'est un bug dans iOS 10.3 lorsque les attributs sont appliqués à une plage de chaînes. Cela arrive aussi avec d'autres attributs. – Koen