KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm trying to vertically centre text in my NSTextFields, but one of them is for a password, so it's a NSSecureTextField. I've set it's class to be MDVerticallyCenteredSecureTextFieldCell with the following implementation: - (NSRect)adjustedFrameToVerticallyCenterText:(NSRect)frame { // super would normally draw text at the top of the cell NSInteger offset = floor((NSHeight(frame) - ([[self font] ascender] - [[self font] descender])) / 2); return NSInsetRect(frame, 0.0, offset+10); } - (void)editWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)editor delegate:(id)delegate event:(NSEvent *)event { [super editWithFrame:[self adjustedFrameToVerticallyCenterText:aRect] inView:controlView editor:editor delegate:delegate event:event]; } - (void)selectWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)editor delegate:(id)delegate start:(NSInteger)start length:(NSInteger)length { [super selectWithFrame:[self adjustedFrameToVerticallyCenterText:aRect] inView:controlView editor:editor delegate:delegate start:start length:length]; } - (void)drawInteriorWithFrame:(NSRect)frame inView:(NSView *)view { [super drawInteriorWithFrame: [self adjustedFrameToVerticallyCenterText:frame] inView:view]; } -(void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView { [super drawWithFrame:cellFrame inView:controlView]; } A similar subclass is already working for regular NSTextFieldCell s, just not secure versions of this. It seems like Apple has somehow protected these methods from being overridden. Now the password field is the only one misaligned: <img src="https://i.sstatic.net/b
Tags (comma-separated)
Save Edits
Cancel