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

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

概述我试图在NSTextFields中垂直居中的文本,但其中一个是密码,所以它是一个NSSecureTextField.我把它设置为 MDVerticallyCenteredSecureTextFieldCell,具有以下实现: - (NSRect)adjustedFrameToVerticallyCenterText:(NSRect)frame { // super would normal 我试图在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子类的方法被调用,或者另一种方式来垂直居中的文本字段?

解决方法 尝试使用常规NSTextFIEld,其中包含您的NSSecureTextFIEldCell子类.我有同样的问题,这个组合有效. 总结

以上是内存溢出为你收集整理的objective-c – 使用子类化在NSSecureTextField中垂直居中文本全部内容,希望文章能够帮你解决objective-c – 使用子类化在NSSecureTextField中垂直居中文本所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1253141.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-07
下一篇 2022-06-07

发表评论

登录后才能评论

评论列表(0条)

保存