我確定mutable意味着它可以改變,所以爲什麼會發生這種情況?NSMutableAttributedString在更改字體時崩潰?
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;
我的catextlayer和我的nsmutableattributedsring都是在我的頭文件中定義的。我對上面的開關改變我的字符串,然後把這個代碼更新catextlayer字符串顯示在:
//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];
它崩潰時,它試圖設置字體,但我不能明白爲什麼?
- [NSConcreteMutableAttributedString setfont程序:範圍:]:無法識別的選擇發送到實例0xd384420 *終止應用程序由於未捕獲的異常 'NSInvalidArgumentException',原因:「 - [NSConcreteMutableAttributedString setfont程序:範圍:]:無法識別的選擇發送例如0xd384420'
這是怎麼發生的?
下面是一些免費代碼,演示如何使用歸因字符串:github.com/artmayes167/Attribute – AMayes