ios - UITextField adjustsFontSizeToFitWidth not working -
on ios 7, textfield.adjustsfontsizetofitwidth = yes
has no effect. minimumfontsize
set. expect font size reduced if text long fit in textfield's frame. but, happens text gets clipped , "..." gets appended on end.
i tried:
- setting width constraint textfield
- setting font textfield in places other init method of containing view
any ideas?
edit:
code bit convoluted, here 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 property textfield, subclass of uitextfield
.
this subclass overrides methods:
- (void)drawrect:(cgrect)rect; - (void) drawplaceholderinrect:(cgrect)rect; - (cgrect) editingrectforbounds: (cgrect) bounds; - (cgrect) textrectforbounds: (cgrect) bounds;
edit:
i commented out each of these overrides, , font still not adjusted well.
edit:
most similar question found here. , accepted answer give on using adjustsfontsizetofitwidth
.
ios 9.2.1, xcode 7.2.1, arc enabled
i experienced similar behavior, self.captionview.textfield.adjustsfontsizetofitwidth = yes;
should work expect. please make sure have following properties set in ib or programmatically:
- number of lines set other 0.
- minimum font size (double check).
- and "line breaks" not set character or word wrap.
and finally...
- make sure of properties configured text field before setting text.
hope helps! cheers.
Comments
Post a Comment