Giving an NSTextView some padding/a margin

前端 未结 4 2033
无人共我
无人共我 2021-02-02 00:08

How would I give a NSTextView some padding/a margin to the left? I know how you do it in a NSTextField (by subclassing NSTextFieldCell) but how do you do it in a NSTextView?

4条回答
  •  感情败类
    2021-02-02 01:09

    You could try subclassing NSTextView and override the textContainerOrigin.

    Details here.

    For example this subclass will give a top and bottom margin of 5 left of 20 and right of 10.

    @implementation MyTextView
    
    - (void)awakeFromNib {
        [super setTextContainerInset:NSMakeSize(15.0f, 5.0f)];
    }
    
    
    - (NSPoint)textContainerOrigin {
        NSPoint origin = [super textContainerOrigin];
        NSPoint newOrigin = NSMakePoint(origin.x + 5.0f, origin.y);
        return newOrigin;
    }
    
    @end
    

提交回复
热议问题