nstextfieldcell

NSTextFieldCell with Multiple Lines

℡╲_俬逩灬. 提交于 2019-12-09 17:46:33
问题 I need to show an NSTextFieldCell with multiple lines with different format on each line. Something like this: Line 1: Title Line 2: Description I subclassed NSTextFieldCell but I don't know how to go on with it. Any ideas? 回答1: First off, you don't have to subclass NSTextFieldCell to achieve this, since, as a subclass of NSCell , NSTextFieldCell inherits -setAttributedStringValue: . The string you provided can be represented as a NSAttributedString . The following code illustrates how you

Adding an editable NSTextFieldCell to my NSTableView

妖精的绣舞 提交于 2019-12-07 19:23:27
问题 I have an NSTableView which displays some information representing a custom object of mine. I am not using bindings. Typically, I create my own NSCells to display data, but for once I'm after an NSTextFieldCell that will display a string value of the object, as well as let the user edit it. I can successfully add the NSTextFieldCell using the code below, but it is not editable. NSTextFieldCell *textField = [[NSTextFieldCell alloc] init]; [textField setFont:[NSFont fontWithName:@"Helvetica

How to make NSTextField use custom subclass of NSTextFieldCell?

痴心易碎 提交于 2019-12-05 05:13:49
I've been looking for a solution to make my NSTextField bottom-aligned and I've found this and adjusted it for my needs. So now I have this custom NSTextFieldCell but how do I tell my NSTextFields to use this class (programmatically)? Have you tried setCell: method of the NSControl class? - (void)setCell:(NSCell *)aCell Since you ask how to do it programmatically, you can also use the setCellClass: method on your NSTextField subclass. Call it in the load or initialize class methods: +(void)load { [self setCellClass:[MyTextFieldCell class]]; } It will not have any bearing on your text fields

How to create a NSTextFieldCell, that in edit mode displays a custom view instead of NSTextField?

╄→尐↘猪︶ㄣ 提交于 2019-12-04 17:28:32
I have a tableView, with 3 columns containing NSTextFieldCell. Everything is populated with bindings. The text of the cells of one of the column is computed and is not editable directly. For this column, I would like when the cell goes into edit mode , to display a button or a custom view instead of the textField . Said in an other way, I want an NSCell that is a NSTextFieldCell when not being edited, and a NSButtonCell (or a custom view) when being edited. Any hint to move on to this? Here is what I tried, without success: Try #1 : I subclassed a NSTextFieldCell and override

NSTextFieldCell with Multiple Lines

半世苍凉 提交于 2019-12-04 07:39:56
I need to show an NSTextFieldCell with multiple lines with different format on each line. Something like this: Line 1: Title Line 2: Description I subclassed NSTextFieldCell but I don't know how to go on with it. Any ideas? NSGod First off, you don't have to subclass NSTextFieldCell to achieve this, since, as a subclass of NSCell , NSTextFieldCell inherits -setAttributedStringValue: . The string you provided can be represented as a NSAttributedString . The following code illustrates how you could achieve the desired text with an ordinary NSTextField . MDAppController.h: @interface

NSTextFieldCell vertical alignment, solutions seem to squash the horizontal alignment

怎甘沉沦 提交于 2019-12-03 05:17:57
问题 I have a NSTextFieldCell that I wish to display with middle vertical alignment. Thanks to an older question here and a blog entry I have two working solutions. However, both solutions seem to squash my ability to set the cell as right aligned. Can anyone help me make either of these solutions support both forms of alignment? Here is the code for one solution: @implementation MiddleAlignedTextFieldCell - (NSRect)titleRectForBounds:(NSRect)theRect { NSRect titleFrame = [super titleRectForBounds

Drawing a rounded cornered NSTextFieldCell

Deadly 提交于 2019-12-02 05:43:37
My code for my NSTextFieldCell is: - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView { // Drawing code here. NSGradient *gradient = [[NSGradient alloc] initWithStartingColor:[NSColor lightGrayColor] endingColor:[NSColor grayColor]]; [gradient drawInRect:cellFrame angle:90]; [[self title] drawInRect:cellFrame withAttributes:nil]; } I would like to have the NSTextFieldCell to have rounded corners.... how could I do this? Use the layer property of NSView, then you can set a corner radius for this. 来源: https://stackoverflow.com/questions/1938925/drawing-a-rounded

NSTextFieldCell's cellSizeForBounds: doesn't match wrapping behavior?

╄→гoц情女王★ 提交于 2019-12-01 14:01:57
It seems to be commonly accepted that cellSizeForBounds: allows one to calculate a text field's "natural" size. However, for NSTextField, I've found that it doesn't quite match: @interface MyTextField : NSTextField @end @implementation MyTextField - (void)textDidChange:(NSNotification *)notification { [super textDidChange:notification]; [self validateEditing]; // Forces updating from the field editor NSSize cellSize = [self.cell cellSizeForBounds: NSMakeRect(0, 0, self.bounds.size.width, CGFLOAT_MAX)]; NSRect frame = self.frame; CGFloat heightDelta = cellSize.height - frame.size.height; frame

How do I set the font size in a text cell so that the string fills the cell's rect?

房东的猫 提交于 2019-11-30 13:36:55
问题 I have a view that contains two NSTextFieldCell s. The size at which these cells are drawn is derived from the size of the view, and I want the text in each cell to be the largest that will fit in the derived size of the cell. Here's what I have, which doesn't set the font size: - (void)drawRect:(NSRect)dirtyRect { /* * Observant readers will notice that I update the whole view here. If * there is a perceived performance problem, then I'll switch to just * updating the dirty rect. */ NSRect

Truncate the last line of multi-line NSTextField

风格不统一 提交于 2019-11-30 10:00:42
I'm trying to create a text field similar to Finder's file labels. I would like the last (second) line to be truncated in the middle. I started with a multi-line NSTextField . However, calling [self.cell setLineBreakMode:NSLineBreakByTruncatingMiddle]; results in a the text field showing only a single truncated line (no line breaks anymore). Here is what it looks like in Finder: deleted_user If you want to wrap text like finder labels, using two labels doesn't do you any good since you need to know what the maximum breakable amount of text is on the first line. Plus, if you're building