标签: nsattributedstring

为什么 - [NSTextStorage replaceCharactersInRange:withAttributedString:]有时,有时候不尊重其他字符集中的字体?

我正在尝试在UKSyntaxColoredTextDocument 0.4 http://www.zathras.de/angelweb/blog-uksctd-oh-four.htm中诊断出一个问题,其中实际上使用与您指定的字体不同的字体的文本会消失类型.(您可以下载并试用这个很酷的实用工具来自己查看这个问题...)

这是背景:这是一些在您键入时重新着色的语法着色代码.它工作得很好,但如果你输入的某些字符不是该文本视图的字体集的一部分(例如Monaco,Helvetica)...例如,日语中的符号字符或其他东西,实际上使用的字体如ZapfDingbatsITC或HiraKakuProN-W3显示它,然后键入时不显示这些字符.

假设你有这样的文字:fdsafd [☀] sfds‡[☀☀☀] [日本语] ......

如果将其粘贴到文本字段中,并在弹出窗口中切换语法着色oldRecolorRange:,则使用以下行调用:

[[textView textStorage] replaceCharactersInRange: range withAttributedString: vString];
Run Code Online (Sandbox Code Playgroud)

在这里,事情就像我期望的那样.ASCII文本,符号和日文文本都是可见的.[textView textStorage]的值开始,结束,如下所示:( 这是gdb的输出;它没有显示unicode字符,不用担心.)

df{
    NSFont = "LucidaGrande 20.00 pt. P [] (0x001a3380) fobj=0x001a4970, spc=6.33";
}?{
    NSFont = "ZapfDingbatsITC 20.00 pt. P [] (0x001ae720) fobj=0x001bb370, spc=5.56";
}fdsafd[{
    NSFont = "LucidaGrande 20.00 pt. P [] (0x001a3380) fobj=0x001a4970, spc=6.33";
}?{
    NSFont = "HiraKakuProN-W3 20.00 pt. P [] (0x001b59e0) fobj=0x001bb600, spc=6.66";
}]sfds[{
...

...即使在设置新值之后

dffdsafd[?]sfds[???][???] Nihddfdfffdfdd{
    NSFont = "LucidaGrande 20.00 pt. P [] (0x001a3380) fobj=0x001a4970, …

cocoa nsattributedstring

5
推荐指数
1
解决办法
1834
查看次数

NSTextField(标签)归属文本:选择

我有一个NSTextField标签,其中包含文本.颜色和大小与默认值不同.(文本有点大,绿色)现在,我需要能够选择标签中的文本,以便单击属性文本中嵌入的超链接.这很好用; 但是,在选择文本时,文本的格式将恢复为默认值(较小的黑色字体).

反正有没有停止此行为,以便在用户单击(选择文本)标签时保留我的样式?

编辑:为了记录,我有另一个白色文字标签,选择时不会改变颜色,只有大小.

cocoa textselection nstextfield nsattributedstring

5
推荐指数
2
解决办法
2910
查看次数

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)]; …
Run Code Online (Sandbox Code Playgroud)

objective-c nsattributedstring nsmutablestring ios

5
推荐指数
1
解决办法
1万
查看次数

NSAttributedString setFont不适用于表情符号字符

我正在使用Nimbus NIAttributedLabel类来显示有时包含表情符号字符的文本.我将字体大小设置为,[UIFont systemFontOfSize:15]但表情符号字符似乎忽略了这一点.使用UILabel,所有字符都会正确显示.

NIAttributedLabel内部调用

[self addAttribute:(NSString*)kCTFontAttributeName value:(id)fontRef range:range];
Run Code Online (Sandbox Code Playgroud)

我想NSAttributedString在看到表情符号字符时必须切换到不同的字体.有没有什么技巧可以确保它使用相同的字体大小?

nsattributedstring ios emoji

5
推荐指数
0
解决办法
622
查看次数

Latex到NSAttributedString?

是否有可用的库可以转换Latex或其他数学符号并将其转换为漂亮的NSAttributedString?我已经看到了AttributedMarkdown和其他Markdown-to-NSAttributedString或Markdown-to-HTML(可以转换为NSAttributedString)库.但乳胶怎么样?

math latex nsstring nsattributedstring ios

5
推荐指数
1
解决办法
442
查看次数

为什么即使在调用之后我也无法获得类别实例方法?

我试图更好地理解Objective-C运行时.考虑NSAttributedString.h哪个具有最小接口,后跟更广泛的类别NSExtendedAttributedString.

现在考虑以下代码:

NSAttributedString *attributedString = [[NSAttributedString alloc] initWithAttributedString:[[NSAttributedString alloc] initWithString:@"ABC"]];
NSLog(@"Result: %@", attributedString); 
NSLog(@"Exists? %@", [NSString stringWithUTF8String:sel_getName(method_getName(class_getInstanceMethod(NSAttributedString.class, @selector(initWithAttributedString:))))]);    
NSLog(@"Exists? %@", [NSString stringWithUTF8String:sel_getName(method_getName(class_getInstanceMethod(NSAttributedString.class, @selector(string))))]);

// Produces this output
2013-04-19 10:17:35.364 TestApp[53300:c07] Result: ABC{
}
2013-04-19 10:17:35.364 TestApp[53300:c07] Exists? <null selector>
2013-04-19 10:17:35.365 TestApp[53300:c07] Exists? string
Run Code Online (Sandbox Code Playgroud)

我们发现实例方法是规范接口的一部分,但不是类别中的实例方法.这怎么可能发生,但它可以被成功调用?有没有办法反省并找到类别方法?

objective-c nsattributedstring objective-c-category

5
推荐指数
1
解决办法
217
查看次数

将click事件添加到ios NSString中的某些文本

我有以下代码,并希望使我的文本的一部分可以点击并调用另一个UIViewController(而不是一个网站).

NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"testing it out @clickhere"];
NSInteger length = str.length;
[str addAttribute:NSForegroundColorAttributeName value:[UIColor bestTextColor] range:NSMakeRange(0,length)];
Run Code Online (Sandbox Code Playgroud)

NSMutableAttributedString设置为UILabel,如下所示:

label.attributedText = str;
Run Code Online (Sandbox Code Playgroud)

什么是最好的方法呢?我似乎无法找到一个好的答案.

我想要的一个例子是假设我有一个UILabel,如下所示:

This is my label.  Click here to go to UIViewController1 and then go to UIViewController1 by this #tag.
Run Code Online (Sandbox Code Playgroud)

我希望第一次单击事件传递"here"文本,并将"#tag"一词传递给同一个click事件.

iphone uibutton nsattributedstring ios uitapgesturerecognizer

5
推荐指数
1
解决办法
9988
查看次数

在TextView中查找子字符串的CGPoint位置

我正在寻找一个位于UITextView内部子串位置的SpriteKit节点.我如何检索CGPoint位置,以便我可以在那里定位SKNode?

    let textFont = [NSFontAttributeName: UIFont(name: "GillSansMT", size: 30.0) ?? UIFont.systemFontOfSize(18.0)]
    attrString1 = NSMutableAttributedString(string: "My name is Dug.", attributes: textFont)
    textShown1 = CustomTextView(frame: CGRectMake(CGRectGetMidX(self.frame), 175 + (90 * paragraphNumber), CGRectGetWidth(self.frame) - 80, CGRectGetHeight(self.frame)-400))
    textShown1.attributedText = attrString1

    self.view?.addSubview(textShown1)
Run Code Online (Sandbox Code Playgroud)

uitextview nsattributedstring ios sprite-kit swift

5
推荐指数
1
解决办法
3031
查看次数

NSAttributedString支持的HTML标记列表是什么?

我无法在文档中找到NSAttributedString支持哪些HTML标记的位置?有谁知道列表是什么?谢谢.

html nsattributedstring ios

5
推荐指数
1
解决办法
466
查看次数

在Swift 4中设置textView.typingAttributes前景色

我正在使用下面的方法在Swift 3中将textView.typingAttributes前景色设置为红色.

textView.typingAttributes[NSForegroundColorAttributeName] = UIColor.red
Run Code Online (Sandbox Code Playgroud)

现在,我已经向Swift 4迁移了它的显示错误,我尝试如下,但它仍然显示错误.什么是正确的设置方式?

textView.typingAttributes[NSAttributedStringKey.foregroundColor] = UIColor.red
Run Code Online (Sandbox Code Playgroud)

uitextview nsattributedstring ios swift4 xcode9-beta

5
推荐指数
1
解决办法
1516
查看次数