【问题标题】:UITextField drawTextInRect is never calledUITextField drawTextInRect 永远不会被调用
【发布时间】:2017-08-25 16:58:46
【问题描述】:

我已经安装了 iOS11 beta5 并发现了一些问题。我为我的自定义 UITextField 覆盖 drawTextInRect 方法,但它从未被调用。

注意: 是的,我已经看到this 的答案,但它在 10.3 上运行良好。

重现该行为的代码示例:

#import <UIKit/UIKit.h>  

@interface MYCustomTextField : UITextField  

@end  

@implementation MYCustomTextField  

-(void)drawTextInRect:(CGRect)rect {  
  [super drawTextInRect:rect];  
  NSLog(@"drawTextInRect calling");  
}  

@end  

我还在 Apple 的开发者论坛上创建了一个 new thread

【问题讨论】:

标签: ios objective-c ios11 xcode9-beta


【解决方案1】:

drawTextInRect 永远不会调用 UITextField。为此,您必须使用 UILabel。

【讨论】:

  • 那么为什么它可以在带有 xcode8 的 iOS 10.3 上运行? @swapnil 帕特尔
  • drawTextInRect/drawText(in:) 应该在 UITextField 上工作。 Apple 在文档 (developer.apple.com/documentation/uikit/uitextfield/…) 中提到了这个功能。而且我遇到了完全相同的问题,在 Xcode 8/iOS 10 中工作,在 Xcode 9/iOS 11 中不起作用。正在调用 draw(_ rect: CGRect) 函数,但它仍然在顶部绘制文本那个。
  • @ChristopherHannah drawRect 实际上不一样。它只对我调用过一次,例如在辞职焦点后不要重绘。
猜你喜欢
  • 2010-12-27
  • 2012-10-27
  • 2013-10-12
  • 2012-03-27
  • 2013-08-29
  • 2013-11-03
  • 1970-01-01
  • 1970-01-01
  • 2015-05-06
相关资源
最近更新 更多