1

I've install iOS11 beta5 and catch some problems. I override drawTextInRect method for my custom UITextField, but it is never called.

Note: yes, i've already seen this answer, but it is works fine on 10.3.

Code sample to reproduce that behavior:

#import <UIKit/UIKit.h>  

@interface MYCustomTextField : UITextField  

@end  

@implementation MYCustomTextField  

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

@end  

I've also created a new thread on Apple's developer forum.

t3ft3l--i
  • 1,372
  • 1
  • 14
  • 21

1 Answers1

-1

drawTextInRect will never called for UITextField. You have to use UILabel for that.

swapnil patel
  • 384
  • 2
  • 17
  • So why it works on iOS 10.3 with xcode8? @swapnil patel – t3ft3l--i Aug 26 '17 at 21:36
  • drawTextInRect/drawText(in:) should work on a UITextField. Apple mention this function in the documentation (https://developer.apple.com/documentation/uikit/uitextfield/1619587-drawtext?changes=latest_minor). And I'm having the exact same issue, worked in Xcode 8/iOS 10, doesn't work in Xcode 9/iOS 11. The draw(_ rect: CGRect) function is being called, but it still draws text on top of that. – Christopher Hannah Sep 14 '17 at 09:35
  • @ChristopherHannah drawRect not actualy the same. Its called for me only once, and do not redraw for example after resign focus. – t3ft3l--i Sep 16 '17 at 18:33