Can't get UITextField to autoshrink text

后端 未结 11 816
逝去的感伤
逝去的感伤 2020-12-05 14:25

I have a UITextField on a table view cell, and when it\'s text becomes too long I would like the font size to decrease. I want to make it very clear that I am t

11条回答
  •  暖寄归人
    2020-12-05 15:07

    I had this same problem with UITextFields created in StoryBoard in Xcode 5.0.2, running iOS 7.0.4. I figured out that the .minimumFontSize property could not be changed by StoryBoard, or viewDidLoad, or viewWillAppear, but that it could be changed in viewDidAppear. So the following code solved my problem:

    - (void) viewDidAppear:(BOOL)animated  {
        [super viewDidAppear:animated];
        self.myTextField.minimumFontSize = 4.0;
        [self.myTextField setNeedsLayout];
        [self.myTextField layoutIfNeeded];
    }
    

提交回复
热议问题