NSMutableAttributedString Fails When Font Changes?

I'm sure mutable means it can be changed, so why is this happening?

attrString = [[NSMutableAttributedString alloc] initWithString:@"Tip 1: Aisle Management The most obvious step – although one that still has not been taken by a disconcerting number of organisations – is to configure cabinets in hot and cold aisles. If you haven’t got your racks into cold and hot aisle configurations, we can advise ways in which you can achieve improved airflow performance."];

        [attrString setFont:[UIFont systemFontOfSize:20] range:NSMakeRange(0, 23)];
        [attrString setFont:[UIFont systemFontOfSize:15] range:NSMakeRange(24, 325)];
        [attrString setTextColor:[UIColor blackColor] range:NSMakeRange(0,184)];
        [attrString setTextColor:[UIColor blueColor] range:NSMakeRange(185,325)];
        break;

Both my catextlayer and my nsmutableattributedsring are defined in my header file. I make changes to my line above in the switch and then call this code to update catextlayer, the line is shown in:

//updates catext layer
TextLayer = [CATextLayer layer];

TextLayer.bounds = CGRectMake(0.0f, 0.0f, 245.0f, 290.0f);
TextLayer.string = attrString;
TextLayer.position = CGPointMake(162.0, 250.0f);
TextLayer.wrapped = YES;

[self.view.layer addSublayer:TextLayer];

It fires when it tries to install a font, but I can’t understand why?

- [NSConcreteMutableAttributedString setFont: range:]: unrecognized selector sent to instance 0xd384420 * Application terminated due to an uncaught exception "NSInvalidArgumentException", reason: '- [NSConcreteMutableAttributedString setFont: range:]: unrecognized instance38, 0x3838d

Why is this happening?

+5
2

NSMutableAttributedString setFont: range:

.... iphone/ipad: NSAttributedString?

, .

...

[NSMutableAttirbutedString setAttributes:NSDictionary range:NSRange];

, - ...

[string setAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"Helvetice-Neue"]} range:NSMakeRange(0, 2)];

[string setAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"Helvetice-Neue"], NSFontAttributeName", nil] range:NSMakeRange(0, 2)];

ObjC.

, .

+10

, attrString, ? , , copy, ? . . NSAttributedString, NSMutableAttributedString.

- , mutableCopy, , ARC:

- (void)setTextCopy:(NSMutableAttributedString *)text {
   textCopy = [text mutableCopy];
}

, :

- (void)setTextCopy:(NSMutableAttributedString *)text {
    [textCopy release];
    textCopy = [text mutableCopy];
}

, textCopy NSAttributedString, NSMutableAttributedString, .

: 1 ️⃣ NSMutableAttributedString 2 ️⃣ NSConcreteAttributedString mutableString crash

+1

All Articles