dev*_*546 5 objective-c nsattributedstring nsmutablestring ios
我确信可变性意味着它可以改变,为什么会发生这种情况呢?
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;
Run Code Online (Sandbox Code Playgroud)
我的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];
Run Code Online (Sandbox Code Playgroud)
它试图设置字体时崩溃,但我不知道为什么?
- [NSConcreteMutableAttributedString setFont:range:]:无法识别的选择器发送到实例0xd384420 *由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:' - [NSConcreteMutableAttributedString setFont:range:]:无法识别的选择器发送到实例0xd384420'
为什么会这样?
Fog*_*ter 10
NSMutableAttributedString没有setFont:range:function.
从这里采取.... iphone/ipad:如何使用NSAttributedString?
所以我从文档中做了一些阅读.
功能是......
[NSMutableAttirbutedString setAttributes:NSDictionary range:NSRange];
Run Code Online (Sandbox Code Playgroud)
所以你应该可以做这样的事......
[string setAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"Helvetice-Neue"]} range:NSMakeRange(0, 2)];
Run Code Online (Sandbox Code Playgroud)
要么
[string setAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"Helvetice-Neue"], NSFontAttributeName", nil] range:NSMakeRange(0, 2)];
Run Code Online (Sandbox Code Playgroud)
如果您仍在使用旧的ObjC语法.
希望有所帮助.
| 归档时间: |
|
| 查看次数: |
14254 次 |
| 最近记录: |