0

I have some attributes:

var myAttributeMainText = [ NSFontAttributeName: UIFont(name: "Arial", size: 24.0)! ]
var myAttributeUpperText = [ NSBaselineOffsetAttributeName: 8, NSFontAttributeName: UIFont(name: "Arial", size: 14.0)! ]

I'm using those attributes in a text label

var allMurableAttributedString = NSMutableAttributedString(string: "")
var userAttribute = NSMutableAttributedString(string: "USER", attributes: myAttributeMainText)
var newAttribute = NSMutableAttributedString(string: "NEW", attributes: myAttributeUpperText)
allMurableAttributedString.appendAttributedString(userAttribute)
allMurableAttributedString.appendAttributedString(newAttribute)

result

Then I'm adding those attributes in CoreData allMurableAttributedString and have something like this:

USER{
    NSFont = "<UICTFont: 0x79feec20> font-family: \"Helvetica\"; font-weight: normal; font-style: normal; font-size: 0.00pt";
}

NEW{
    NSBaselineOffset = 6;
    NSFont = "<UICTFont: 0x79fed8e0> font-family: \"Thonburi\"; font-weight: normal; font-style: normal; font-size: 10.00pt";
}

How can i change the font size of my attribute allMurableAttributedString when I call it?

Necreaux
  • 9,451
  • 7
  • 26
  • 43
Skie
  • 91
  • 1
  • 2
  • 13
  • Have you considered just applying the desired fonts to the correct text regions again? That is, building a new attributed string using just the text from the original attributed string? In this case, this may be easier than trying to remove and then add attributes... – JRG-Developer Apr 23 '16 at 03:10
  • You have to enumerate the `NSFontAttributeName` of your `NSMutableAttributedString`, and then change its value, like this: http://stackoverflow.com/questions/36064762/change-font-size-without-change-uitextview-attributedtext/36066082#36066082 – Larme Apr 23 '16 at 14:11

1 Answers1

0

to remove Font settings from NSMutableAttributedString I'm used this code

allMurableAttributedString.removeAttribute(NSFontAttributeName, range: NSMakeRange(0, 7))

then i can add new Attributes

allMurableAttributedString.setAttributes(myAttributeMainText, range: NSMakeRange(0, 4))
allMurableAttributedString.setAttributes(myAttributeUpperText, range: NSMakeRange(4, 3))
Skie
  • 91
  • 1
  • 2
  • 13
  • Since attributes are stored in a NSDictionary for each range, it can have only one valu per key. So you don't have to remove the `NSFontAttributeName` key/value if you're setting a new value for it afterwards. – Larme Apr 25 '16 at 07:43