objective-c – 使用子类化在NSSecureTextField中垂直居中文本

前端之家收集整理的这篇文章主要介绍了objective-c – 使用子类化在NSSecureTextField中垂直居中文本前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图在NSTextFields中垂直居中的文本,但其中一个是密码,所以它是一个NSSecureTextField.我把它设置为 MDVerticallyCenteredSecureTextFieldCell,具有以下实现:
- (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];
}

类似的子类已经适用于常规的NSTextFieldCells,只是不是安全的版本.苹果似乎以某种方式保护这些方法不被覆盖.

现在密码字段是唯一的一个不对齐:

任何人都可以提出一种方式,让NSSecureTextFieldCell子类的方法调用,或者另一种方式来垂直居中的文本字段?

@H_502_11@解决方法
尝试使用常规NSTextField,其中包含您的NSSecureTextFieldCell子类.我有同样的问题,这个组合有效.
原文链接:https://www.f2er.com/c/112545.html

猜你在找的C&C++相关文章