nstextview

Set the placeholder string for NSTextView

依然范特西╮ 提交于 2019-11-30 07:29:05
问题 Is there any way to set the placeholder string for NSTextView like that in NSTextField ? I have checked the property but couldn't find it. I have searched some questions but there isn't a proper explanation. 回答1: I found this answer online. Philippe Mougin made this. static NSAttributedString *placeHolderString; @implementation TextViewWithPlaceHolder +(void)initialize { static BOOL initialized = NO; if (!initialized) { NSColor *txtColor = [NSColor grayColor]; NSDictionary *txtDict =

NSString boundingRectWithSize slightly underestimating the correct height - why?

巧了我就是萌 提交于 2019-11-30 07:25:55
问题 I'm attempting to resize a text field / view automatically depending on its current width. In other words I want the width to stay constant but resize the height according to the text supplied to it. It seems to be working but for some reason is aligning to the bottom of my window despite efforts to manually move it back. Can anybody see what I'm doing wrong here? NSString *temp = @"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer vel felis nec massa ultricies blandit non id

'sizeWithFont:constrainedToSize:lineBreakMode:'is deprecated:

瘦欲@ 提交于 2019-11-30 07:20:02
问题 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 - boundingRectWithSize:options:attribiutes:context - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == 0) { self.lblHidden.frame = CGRectMake(58, 228, 945, 9999); self.lblHidden.text = detailShareObj.pDesc; CGSize size =

How can I make the Tab key move focus out of a NSTextView?

倾然丶 夕夏残阳落幕 提交于 2019-11-30 06:43:16
I'm using an NSTextView to allow multi-line input. However, due to the nature of my app, users will be more comfortable moving to the next input element when they press TAB. How can I make TAB exit the NSTextView, while keeping the newline behaviour of the Enter key? Wevah You could implement -textView:doCommandBySelector: in your text view's delegate: - (BOOL)textView:(NSTextView *)aTextView doCommandBySelector:(SEL)aSelector { if (aSelector == @selector(insertTab:)) { [[aTextView window] selectNextKeyView:nil]; return YES; } return NO; } See http://developer.apple.com/documentation/Cocoa

How to resize NSTextView according to its content?

一个人想着一个人 提交于 2019-11-30 04:59:12
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 size automatically increases. So I increased height of its super view that is NSScrollView to its height, but NSScrollView is not getting completely resized, it is showing scroller on right. float xCoordinate = 15.0; [xContentViewScroller setFrame:NSMakeRect(xCoordinate, 0.0, 560.0, 10.0)]; [[xContentView textStorage] setAttributedString:xContents]

Cocoa: looking for a general strategy for programmatic manipulation of NSTextView storage without messing up undo

我的梦境 提交于 2019-11-30 02:00:20
I am writing a special-purpose text editor in cocoa that does things like automatic text substitution, inline text completions (ala Xcode ), etc. I need to be able to programmatically manipulate the NSTextView ’s NSTextStorage in response to 1) user typing, 2) user pasting, 3) user dropping text. I have tried two different general approaches and both of them have caused the NSTextView ’s native undo manager to get out of sync in different ways. In each case, I am only using NSTextView delegate methods. I have been trying to avoid subclassing NSTextview or NSTextStorage (though I will subclass

NSAttributedString highlight/background color shows between lines (ugly)

点点圈 提交于 2019-11-30 01:37:05
问题 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 = @{NSBackgroundColorAttributeName:NSColor.greenColor}; NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:@"Here is a single line of text with single spacing" attributes:attributes]; [textView.textStorage setAttributedString:attrString]; This approach basically

NSTextField or NSTextView?

不想你离开。 提交于 2019-11-29 22:58:00
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 understand correctly, NSTextField can be also used with attributed strings and with multiple lines... What I need specifically is a control that would display the text of messages inside a timeline view like in Tweetie or any other similar software. The only requirements I have are: it should display text in about 1-4 lines it should be able to show

Truncate NSTextView?

自作多情 提交于 2019-11-29 21:06:49
问题 I tried using defaultParagraphStyle, but I can't seem to get a NSTextView (programmatically added) to truncate text with an ellipsis (...). I am setting the frame during the initWithFrame (150, 20) and I also set the maxSize (150,20). However, text simply overflows. If I set the height where half a line is visible, I can see the top half of the text, however I would like to see the text truncated with ellipsis instead. How can I do this? 回答1: If you hover over the corresponding control in IB,

Using Autolayout with expanding NSTextViews

烂漫一生 提交于 2019-11-29 20:38:09
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 automatically, but I observe their resizing with an NSViewFrameDidChangeNotification , recalc all their origins so that they don't overlap, and resize their superview (the scroll view's document view) so that they all fit and can be scrolled to. This seems as though it would be the perfect candidate for autolayout! I set NSLayoutConstraints between the first