UITextField blurred text

前端 未结 8 640
逝去的感伤
逝去的感伤 2020-12-16 02:42

I am having a problem with a UITextField\'s text being blurred/anti-aliased even with a standard font size. The text will appear crisp when the control is the first responde

相关标签:
8条回答
  • 2020-12-16 03:48

    i tried using CGRectIntegral and stuff. In my case changing min font size and font size in IB did it.

    0 讨论(0)
  • 2020-12-16 03:49

    OK I'm answering my own question here.

    I found a number of references to this bug through Google, but everybody worked around it by playing with font sizes. After much hunting I found this thread that says anti-aliasing is applied when a view's frame contains fractional pixel values, e.g. if you calculate its size as a fraction of the super view.

    Sure enough, casting the CGRect values to (int) for the view's frame worked perfectly. So as an example, if you wanted your text field to be centered vertically in the superview, you should use an (int) cast like this:

    textFieldWidth = 300;
    textFieldHeight = 31;
    offsetX = 0;
    offsetY = (superview.bounds.size.height - textFieldHeight) / 2;
    
    textField.frame = CGRectMake((int) offsetX,
                                 (int) offsetY,
                                 (int) textFieldWidth,
                                 (int) textFieldHeight);
    

    There is also the CGRectIntegral function that you can use to convert a CGRect to integral values.

    0 讨论(0)
提交回复
热议问题