Questions tagged [nstextview]

NSTextView is the front-end class to MacOS's Application Kit text system. It draws the text managed by the back-end components and handles user events to select and modify its text. While NSTextView is a subclass of NSText—which declares the most general Cocoa interface to the text system—NSTextView adds major features beyond the capabilities of NSText.

Text views are user interface objects instantiated from the NSTextView class. Text views typically display multiple lines of text laid out in paragraphs with all the characteristics of sophisticated typesetting. A text view is the main user interface to the Cocoa text-editing system. It handles user events to provide text entry and modification, and to display any font, including those of non-English languages, with arbitrary colors, styles, and other attributes.

The Cocoa text system supports text views with many other underlying objects providing text storage, layout, font and attribute manipulation, spell checking, undo and redo, copy and paste, drag and drop, saving of text to files, and other features. NSTextView is a subclass of NSText, which is a separate class for historical reasons. You don’t instantiate NSText, although it declares many of the methods you use with NSTextView. When you put an NSTextView object in an NSWindow object, you have a full-featured text editor whose capabilities are provided “for free” by the Cocoa text system.

871 questions
52
votes
12 answers

How to get height for NSAttributedString at a fixed width

I want to do some drawing of NSAttributedStrings in fixed-width boxes, but am having trouble calculating the right height they'll take up when drawn. So far, I've tried: Calling - (NSSize) size, but the results are useless (for this purpose), as…
bonaldi
  • 992
  • 1
  • 8
  • 11
32
votes
1 answer

NSTextField or NSTextView?

Could someone explain to me what are the main differences between NSTextField and NSTextView? I know that NSTextView has more features and is usually used for longer texts, and NSTextField is usually used for one-line plain text fields, but if I…
Kuba Suder
  • 7,587
  • 9
  • 36
  • 39
31
votes
6 answers

Change the text of a NSTextView programmatically

I can't find any parameter that seems to be related with the text value showed in a NSTextView. I understood that a NSTextView uses a complex structure (with NSLayoutManager etc...), but I can't find a valid way to modify the current text value.
MatterGoal
  • 16,038
  • 19
  • 109
  • 186
29
votes
3 answers

How does line spacing work in Core Text? (and why is it different from NSLayoutManager?)

I'm trying to draw text using Core Text functions, with a line spacing that's as close as possible to what it would be if I used NSTextView. Take this font as an example: NSFont *font = [NSFont fontWithName:@"Times New Roman" size:96.0]; The line…
Steven Vandeweghe
  • 2,170
  • 2
  • 20
  • 24
29
votes
6 answers

'sizeWithFont:constrainedToSize:lineBreakMode:'is deprecated:

Converting a project from iOS5.0 to iOS7 / iOS6 on Xcode 5. The code below is giving a compile time warning: 'sizeWithFont:constrainedToSize:lineBreakMode:'is deprecated: first deprecated in ios 7.0 - Use -…
iSrini
  • 905
  • 2
  • 9
  • 18
27
votes
4 answers

Using Autolayout with expanding NSTextViews

My app consists of an NSScrollView whose document view contains a number of vertically stacked NSTextViews — each of which resizes in the vertical direction as text is added. Currently, this is all managed in code. The NSTextViews resize…
jemmons
  • 18,605
  • 8
  • 55
  • 84
26
votes
5 answers

Append to NSTextView and scroll

OK, what I need should have been very simple. However, I've looked everywhere and I'm not sure I've found something that works 100% (and it's something that has troubled me in the past too). So, here we are : I want to be able to append to an…
Dr.Kameleon
  • 22,532
  • 20
  • 115
  • 223
22
votes
5 answers

How to disable word-wrap of NSTextView?

NSTextView does word-wrap by default. How can I disable this? I'm making a JSON code viewer, so I have to disable this.
eonil
  • 83,476
  • 81
  • 317
  • 516
22
votes
4 answers

How to resize NSTextView according to its content?

I am trying to set an attributed string within NSTextView. I want to increase its height based on its content, initially it is set to some default value. So I tried this method: I set content in NSTextView. When we set some content in NSTextView its…
Miraaj
  • 353
  • 2
  • 3
  • 8
21
votes
1 answer

IBOutlet for NSTextView in a ARC project

As you read here in most cases a IBOutlet should be weak. Now as you can read in the development library not all classes support weak references. (e.g. NSTextView). This means you have to use assign: @property (assign) IBOutlet NSTextView…
Stephan
  • 4,263
  • 2
  • 24
  • 33
20
votes
4 answers

How to find the text in an NSTextView?

I need to find the text in an NSTextView, and save it to a file. I can do the saving fine. I have used -stringValue, and -textStorage so far, but neither have worked. When I put -stringValue in, it just gave me (null), and when I put -textStorage…
Justin
  • 2,122
  • 3
  • 27
  • 47
19
votes
5 answers

What is the best way to implement syntax highlighting of source code in Cocoa?

I'm working on Cocoa Application that should be able to analyze and highlight a source code written in such languages as Objective-C, SQL, JavaScript, Python etc. The text should be editable too (by using NSTextView, for example). Please advise what…
Vadim
  • 9,383
  • 7
  • 36
  • 58
19
votes
5 answers

NSTextView syntax highlighting

I'm working on a Cocoa text editor which uses an NSTextView. Is it possible to change the color of certain portions of the text?
igul222
  • 8,557
  • 14
  • 52
  • 60
18
votes
3 answers

How is a paragraph defined in an NSAttributedString?

I see that there is an attribute name (NSParagraphStyleAttributeName) for applying paragraph styles to text in Cocoa. Text is stored in an NSAttributedString, but what defines a "paragraph" in that string -- is it the newline character \n? Other…
Rob N
  • 15,024
  • 17
  • 92
  • 165
18
votes
3 answers

NSAttributedString highlight/background color shows between lines (ugly)

I'm trying to nicely display paragraphs of highlighted in a NSTextView. Right now, I'm doing this by creating a NSAttributedString with a background color. Here's some simplified code: NSDictionary *attributes =…
stevel
  • 1,612
  • 1
  • 14
  • 13
1
2 3
58 59