I need to bottom align the text in my NSTextField so that the bottom pixel rows of my text always stays in the same spot when dynamically changing the font size (I use this to do that).
Right now I have this scenario: whenever the font size gets smaller e.g from 55 to 20, the text hangs at the top of the bounds/frame and this is not what I need.
I haven't found anything that lets me align the text at the bottom but I did find this and adjusted it for my custom NSTextFieldCell subclass:
- (NSRect)titleRectForBounds:(NSRect)theRect {
NSRect titleFrame = [super titleRectForBounds:theRect];
// NSSize titleSize = [[self attributedStringValue] size];
titleFrame.origin.y = theRect.origin.y;
return titleFrame;
}
- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
NSRect titleRect = [self titleRectForBounds:cellFrame];
[[self attributedStringValue] drawInRect:titleRect];
}
I also used [myTextField setCell:myTextFieldCell];
so that my NSTextField uses the NSTextFieldCell but nothing has changed. Did I not adjust this correctly or what else am I doing wrong?