nstextcontainer

NSLayoutManager with multiple NSTextContainers causes UITextViews to not be selectable/editable

五迷三道 提交于 2020-05-10 20:56:11
问题 I am trying to achieve a multi page text editing layout, as in Pages, MS Word, ... . On OS X I can achieve this by creating one NSLayoutManager with one NSTextStorage for multiple NSTextViews. Each NSTextView has its own NSTextContainer. See below code for OS X. A simple example with text spreading between two NSTextViews: import Cocoa class ViewController: NSViewController { let layoutManager = NSLayoutManager() let textStorage = NSTextStorage(attributedString: NSAttributedString(string:

NSLayoutManager with multiple NSTextContainers causes UITextViews to not be selectable/editable

笑着哭i 提交于 2020-05-10 20:55:56
问题 I am trying to achieve a multi page text editing layout, as in Pages, MS Word, ... . On OS X I can achieve this by creating one NSLayoutManager with one NSTextStorage for multiple NSTextViews. Each NSTextView has its own NSTextContainer. See below code for OS X. A simple example with text spreading between two NSTextViews: import Cocoa class ViewController: NSViewController { let layoutManager = NSLayoutManager() let textStorage = NSTextStorage(attributedString: NSAttributedString(string:

NSLayoutManager with multiple NSTextContainers causes UITextViews to not be selectable/editable

不打扰是莪最后的温柔 提交于 2020-05-10 20:55:48
问题 I am trying to achieve a multi page text editing layout, as in Pages, MS Word, ... . On OS X I can achieve this by creating one NSLayoutManager with one NSTextStorage for multiple NSTextViews. Each NSTextView has its own NSTextContainer. See below code for OS X. A simple example with text spreading between two NSTextViews: import Cocoa class ViewController: NSViewController { let layoutManager = NSLayoutManager() let textStorage = NSTextStorage(attributedString: NSAttributedString(string:

Extra whitespace that causes a newline by UITextView at end is ignored

拜拜、爱过 提交于 2019-12-25 17:19:50
问题 This is my code: import UIKit class ViewController: UIViewController { init() { super.init(nibName: nil, bundle: nil) let textView = UITextView(frame: .zero) textView.isScrollEnabled = false textView.translatesAutoresizingMaskIntoConstraints = false view.addSubview(textView) NSLayoutConstraint.activate([ textView.widthAnchor.constraint(equalToConstant: 150), textView.centerXAnchor.constraint(equalTo: view.centerXAnchor), textView.centerYAnchor.constraint(equalTo: view.centerYAnchor) ]) // As

TextContainer isn't resizing while changing bounds of UITextView

半城伤御伤魂 提交于 2019-12-24 15:59:29
问题 After resizing textView, I want textContainer to be the same size (I want text to be the same width as resized textView) as textView. So what I am doing right now is I create a UITextView programatically, then (with or without text inside textView) I resize textView by changing it's bounds but textContainer stays with the same size (text is in smaller rectangle than textView which looks bad). Here is some code: let textStorage = NSTextStorage() let layoutManager = NSLayoutManager()

In my programmatically instantiated UITextView (initialized with NSTextContainer) the .text property is always nil

試著忘記壹切 提交于 2019-12-21 06:15:05
问题 [UPDATED w/ SOLUTION and WORKING CODE in bottom section] In -viewDidLoad I alloc, initWithFrame: Add myTextView to subView Set some basic properties (alignment, background color, text color, etc) Set default text The .text does not appear. myTextView appears (as indicated by background color), set breakpoint, it has a frame, memory, etc. Everything looks right. myTextView looks good, but the .text is nil. I change it, set it, update it. No matter what the .text remains nil. I have read the

Exact height of NSTextContainer

大兔子大兔子 提交于 2019-12-11 04:08:02
问题 I have a method used to calculate the exact height size for a text container. The method returns not correct values when trying to measure the height of an attributed string filled with arabic html content. This is the code used : - (CGFloat)textViewHeightForAttributedText:(NSAttributedString *)text andWidth:(CGFloat)width { NSTextStorage *textStorager = [[NSTextStorage alloc] initWithAttributedString:text]; NSTextContainer *textContainerr = [[NSTextContainer alloc] init]; textContainerr.size

iOS文本布局探讨之一——文本布局框架TextKit浅析

北战南征 提交于 2019-12-10 13:38:11
iOS文本布局探讨之一——文本布局框架TextKit浅析 一、引言 在iOS开发中,处理文本的视图控件主要有4中,UILabel,UITextField,UITextView和UIWebView。其中UILabel与UITextField相对简单,UITextView是功能完备的文本布局展示类,通过它可以进行复杂的富文本布局,UIWebView主要用来加载网页或者pdf文件,其可以进行HTML,CSS和JS等文件的解析。 TextKit是一个偏上层的开发框架,在iOS7以上可用,使用它开发者可以方便灵活处理复杂的文本布局,满足开发中对文本布局的各种复杂需求。TextKit实际上是基于CoreText的一个上层框架,其是面向对象的,如果TextKit中提供的API无法满足需求,可以使用CoreText中的API进行更底层的开发。 官方文档中的一张图片很确切,经常会被用来描述TextKit框架在iOS系统文本渲染中所处的位置。 二、TextKit框架的结构 界面在进行文本的渲染时,有下面几个必要条件: 1.要渲染展示的内容。 2.将内容渲染在某个视图上。 3.内容渲染在视图上的尺寸位置和形状。 在TextKit框架中,提供了几个类分别对应处理上述的必要条件: 1.NSTextStorage对应要渲染展示的内容。 2.UITextView对应要渲染的视图。 3

Getting CGRect for text in a UITextView for the purpose of highlighting with a CALayer

Deadly 提交于 2019-12-05 01:08:11
问题 I am trying to draw a transparent CALayer in a UITextView in order to highlight matched text in a search. I've figured out the correct way to do this, but still haven't found the correct coordinates. I need to find the origin of the text container. Right now, I get the textView's origin, and offset the layer's origin by that: NSRange match = [[[self textView]text]rangeOfString:@"predict the future"]; NSRange glyphRange = [manager glyphRangeForCharacterRange:match actualCharacterRange:NULL];

Getting CGRect for text in a UITextView for the purpose of highlighting with a CALayer

为君一笑 提交于 2019-12-03 20:06:26
I am trying to draw a transparent CALayer in a UITextView in order to highlight matched text in a search. I've figured out the correct way to do this, but still haven't found the correct coordinates. I need to find the origin of the text container. Right now, I get the textView's origin, and offset the layer's origin by that: NSRange match = [[[self textView]text]rangeOfString:@"predict the future"]; NSRange glyphRange = [manager glyphRangeForCharacterRange:match actualCharacterRange:NULL]; CGRect textRect = [manager boundingRectForGlyphRange:glyphRange inTextContainer:[[self textView