问题标签 [textkit]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
0 回答
711 浏览

objective-c - 解析 HTML hpple 替换 [element raw]

我在使用 hpple 库解析 HTML 内容时遇到问题。

我想使用 textkit 来显示一个好的 html 内容。

所以这是我的问题。

我想用我自己的标签替换所有图像或视频标签,然后在 UITextview 上用 textkit 插入它。

我的算法:

我解析我的 html 内容

如果 [the element raw] 包含带有正则表达式的 a ,我会使用正则表达式进行测试

如果是这样,我会提取我的视频图像的“src”并创建一个个性化的字符串

然后我想用我的新字符串替换整个 [element raw]

例如:

看起来像:

然后我使用正则表达式删除所有 HTML 标签

我的问题是当我想用我的新标签“\IMG\blablabla.jpg”替换 [element raw] 时

我使用的正则表达式

初始化我的自定义 NSTextstorage

用我自己的标签格式化我的 HTML 字符串

在这种方法中,我的长度范围总是等于 0

这是我得到的一个例子:

初始html内容

提取的[元素原始]

范围

编辑

我已经手动提取了我希望我的算法提取的部分并将其与 HTML 解析器返回的 [element raw] 匹配,并且似乎 HTML 解析器删除了空格字符......

0 投票
0 回答
846 浏览

ios - textkit自定义文本属性在跨越多行时绘制大矩形

我基本上是在使用下面的 drawGlyphsForGlyphRange 方法创建一个自定义属性来在我的文本子类 NSLayoutManager 中绘制一个圆角矩形。下面的工作就像一个跨越一条线的魅力。但是,当文本范围跨越两行时,我得到一个大矩形,它沿着这两行绘制属性。我想我应该在这里使用不同的方法,我尝试 nsbackgroundattribute 来绘制高光,但不幸的是我无法使用它来制作高光圆角矩形。

我会很感激任何方向。

}

0 投票
1 回答
2410 浏览

ios - 使用 CALayer 突出显示跨越多行的 UITextView 中的文本

这是为UITextView 中的文本获取 CGRect 的延续,目的是使用 CALayer 突出显示。我无法为每个线段中的范围获取正确的矩形。

这是我目前的尝试。我基本上使用 enumerateLineFragmentsForGlyphRange:usingBlock: 来循环遍历每一行。然后我使用 enumerateEnclosureRectsForGlyphRange:withinSelectedGlyphRange:usingBlock: 来确保当前行上的文本范围与行的范围匹配并且具有相同的 Y 坐标。有时这有效,有时则无效。

似乎如果搜索文本接近返回,它会突出显示。(y坐标)。

高光已关闭。 似乎是关闭的Y坐标

在此屏幕截图中,应该突出显示“返回生成的字符范围”。

如果文本不在返回或空格附近,这似乎可以正常工作:

如果文本周围没有空格,则工作正常

我错过了什么吗?

更新:

我已经将问题缩小了一点,我相信 enumerateLineFragmentsForGlyphRange: usingBlock: 正在跳过有返回的行。

0 投票
5 回答
59662 浏览

ios - iOS 7 TextKit - 如何插入与文本内联的图像?

我正在尝试使用 UITextView 获得以下效果:

在此处输入图像描述

基本上我想在文本之间插入图像。图像只需占用 1 行空间,因此无需包装。

我尝试将 UIView 添加到子视图:

但它似乎漂浮在文本上并覆盖它。

我对排除路径做了一些阅读,这似乎是实现这一点的一种方式。但是,我不想绝对定位图像 - 相反,它应该与文本一起流动(类似于<span>HTML 中的行为方式)。

0 投票
3 回答
2826 浏览

ios - How to clear a UITextView with a custom NSTextStorage? [iOS7 only]

I'm currently trying to create an SMS-like screen, where the user can write some text and send it to other users. Everything goes as expected until I try to clear my text view and encounters a crash. I've been trying to find a way around this issue, but I just cannot find enough documentation online. So here it is, and hopefully one of you will know a fix for this.


The implementation

My UITextView is a subclass of Peter Steinberger's implementation for iOS7, and I use it with a custom NSTextStorage subclassed as showed in objc.io's 'Getting to Know TextKit' and especially that source code in order to highlight usernames in the message.

In my ViewController, I configure my text storage like this:

self.textStorage = [[[MyCustomTextStorage alloc] init] autorelease]; [self.textStorage addLayoutManager:self.textView.layoutManager];

And then in my TextView's delegate method:

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text

I store the input in my custom TextStorage:

[self.textStorage.string stringByReplacingCharactersInRange:range withString:text];

The crash

I can retrieve my text via self.textStorage.string, and then I clear my text view by replacing characters in the range of the input string. This works quite well, but when I try to set my TextView as the first responder again, the application crashes.

Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSCFString _getBlockStart:end:contentsEnd:forRange:stopAtLineSeparators:]: Range {5, 0} out of bounds; string length 0'

The range mentioned is the range of my previously cleared string so it looks like I can clear the display, but my TextStorage / TextView is keeping a reference to the first edited range / string.


Any idea on what could be causing this crash and how to resolve it? Thanks for your attention; at this point any help is appreciated, so please feel free to post if you have some piece of advice. :)

0 投票
3 回答
34571 浏览

ios7 - 在 iOS 7 中调整字母间距

在 iOS 7 中,当使用新的从屏幕边缘滑动手势导航返回时,返回按钮的标题(“艺术家”)从粉红色(在下面的示例中)淡化,并且具有常规字体粗细到黑色并具有粗体字重。

在此处输入图像描述

在我看来,动画使用了两个不同的标签来达到这个效果;一个随着另一个淡入而淡出。然而,Apple 以某种方式调整了字体,使常规标签完美地覆盖了粗体标签,从而产生了单个标签在两种不同重量和颜色之间变形的错觉。

他们是否只是简单地调整了常规字体上的字母间距,使其与粗体匹配?在那种情况下,如何在 iOS 7 中实现呢?Text Kit 是否有任何很棒的功能可以做到这一点,或者我应该如何去做?

0 投票
4 回答
1371 浏览

ios - iOS中的NSLineSeparatorCharacter?

iOS 开发人员库中的字符串编程指南提到“行和段落分隔符”:NSParagraphSeparatorCharacterNSLineSeparatorCharacter. 但 Xcode 不接受它们(iOS7 是目标):

代码来自这个 SE 帖子

这是一个文档错误,它们仅在 OSX 上可用吗?如果是这样,有什么方法可以在iOS7 上使用 TextKit来实现同样的事情(同一段落中的新行)?

0 投票
4 回答
10403 浏览

ios - iOS 在形状中心绘制文本

我正在尝试在 iOS 的形状中心绘制文本,例如 Microsoft Office 的插入形状,请参阅:https ://www.dropbox.com/s/cgqyyuvy6hcv5g8/Screenshot%202014-01-21%2013.48.17 .png

我有一个用于形成形状的坐标数组,可以很好地创建实际形状。

我的第一个策略是遵循这个 stackoverflow 问题:Core Text With Asymmetric Shape on iOS但是我只能让它在形状底部绘制文本。有没有办法让文本垂直和水平居中?

然后,我查看了新的 TextKit,但我陷入了如何进行子类化NSTextContainer以接受一个CGPath或一个坐标数组来创建要在其中绘制的文本容器的问题。

我的备用解决方案是使用 Core Text 在形状的中心坐标处绘制文本,但是这会导致文本在某些形状(例如直角三角形)上绘制在形状之外。

或者,有没有其他方法可以让我在形状的中心获得一些文本?

0 投票
1 回答
58 浏览

xamarin.ios - 显示 Ui 后更改行高

在 monotouch.dialog 中是否可以在显示 Ui 后更改行的高度?

这样做的原因是 UI 被绘制,然后一旦从服务传回一些文本,我将填充一个 TextViewElement,它使用 Text Kit 将文本绘制到 Ui。

我想调整行的大小以适合文本。

我正在使用 IElementSizing 但这仅在第一次加载时调用。在此之后我需要修改行高。

我还在根上设置了不均匀的行。

0 投票
2 回答
1868 浏览

ios7 - iOS 7 using an HTML string as an NSAttributedString AND setting the font?

I have a UITextView in which I'm trying to display some attributed text which comes in the form of HTML. It uses things like inline bolding and italicizing. The client now wants the font on this to change. However, whenever I change the font, it seems to disregard any of the HTML formatting. Is there any way to change the font while retaining the other formatting attributes, like bolding an italicizing?