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?
EDIT: A bit more info: 1. The Text View just has plain text no rich text and no other fancy stuff like a proper text editor (e.g Paragraph insets). 2. Is it possible to use setTextContainerInset: for this?
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
Just to add an update to this. iOS7 adds a property to UITextView called textContainerInset. Calling setTextContainerInset will create margins inside the TextView for the content.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With