1
votes

I have an NSTextField in a container:

[textField setFrameOrigin:NSMakePoint(0, -t.frame.size.height)];
content = [[NSView alloc] init];
[content setWantLayer:YES]
content.layer=[CALayer layer];
[content addSubview:textField];
[content scaleUnitSquareToSize:NSMakeSize(1, -1)];
content.frame=textField.frame;
content.layer.backgroundColor=textBGColor.CGColor;

The container itself is located in a view with

[view scaleUnitSquareToSize:NSMakeSize(1, -1)];

This is all for obtaining a top left origin for the TextField and it works great, the only problem consist in the InsertionPoint not drawing (at least not in the visible frame).

I presume the InsertionPoint is either not Scaled or translated with the TextField. Other possibility is that InsertionPoint can't be drawn in a layer backed View.

Is there a way to display the InsertionPoint cursor ?

EDIT

After trying all the possibilities out, it seems the InsertionPoint (and the focusRing) are not drawing because of its frame being positioned out of the superviews bounds and its dirtyDrawRect. Is there a way to remove the clipping of an NSView ? I need to be able to place my TextField on every absolute position possible.

2

2 Answers

1
votes

I found a way through: implementing the drawing myself.

1) giving a custom TextView as Editor for the window.

- (id)windowWillReturnFieldEditor:(NSWindow *)sender toObject:(id)anObject
{

    if (!myCustomFieldEditor) {
        myCustomFieldEditor = [[TextView alloc] init];
        [myCustomFieldEditor setFieldEditor:YES];
    }
    return myCustomFieldEditor;
}

2) Overiding the drawInsertionPoint method in the custom TextView class.

-(void)drawInsertionPointInRect:(NSRect)rect color:(NSColor *)color turnedOn:(BOOL)flag{
    [color set];
    NSRectFill(rect);
    [super drawInsertionPointInRect:rect color:color turnedOn:flag];
}
0
votes

For insertion point just make your textfield to first responder.

  [myTextField becomeFirstResponder];