UITextField configuresFontSizeToFitWidth not working
In iOS 7, it textField.adjustsFontSizeToFitWidth = YES
doesn't work. minimumFontSize
is also correctly installed. I expect the font size to be reduced if the text is too long to fit within the textField frame. But what actually happens is that the text is cut off and "..." is added to the end.
I tried:
- Setting the width limit for a textField
- Setting the font for the textField in places other than the init method of the containing view
Any ideas?
EDIT:
The code is a bit confusing, but here it is:
self.captionView = [[CaptionView alloc] initWithFrame:CGRectMake(0, 0, self.width, 50)];
self.captionView.textField.font = [self.captionView.textField.font fontWithSize:20.f];
self.captionView.textField.leftPadding = 2.f;
self.captionView.textField.rightPadding = 2.f;
self.captionView.textField.adjustsFontSizeToFitWidth = YES;
self.captionView.textField.minimumFontSize = 2.f;
self.captionView.captionViewDelegate = self;
[self addSubview:self.captionView];
CaptionView
has a textField property that is subclassed UITextField
.
This subclass overrides methods:
- (void)drawRect:(CGRect)rect;
- (void) drawPlaceholderInRect:(CGRect)rect;
- (CGRect) editingRectForBounds: (CGRect) bounds;
- (CGRect) textRectForBounds: (CGRect) bounds;
EDIT:
I just commented out each of these overrides and the font is still not set up well.
EDIT:
The most similar question I have found is here . And the accepted answer was to opt out of use adjustsFontSizeToFitWidth
.
source to share
No one has answered this question yet
See similar questions:
or similar: