UITextField blurred text

前端 未结 8 639
逝去的感伤
逝去的感伤 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:22

    Solution from this site explains that it can be related to resizing and iOS does not take care of this bug for layers, only the various views. I updated it to Swift 4:

    view.contentScaleFactor = UIScreen.main.scale
    
    0 讨论(0)
  • 2020-12-16 03:22

    I would love to contribute as I just discovered the answer on my own after quite a bit of frustration.

    The UITextField in InterfaceBuilder has a forced frame height of 31 pixels. This cannot be click-dragged to resize nor can it be set in the frame properties in IB. You need to go to viewDidLoad and adjust the frame height to 32 pixels, and this should solve the problem.

    Hopefully, future versions of IB will correct this.

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

    Use CGRectIntegral to make sure the text fields' frames are based on integer coordinates. You'll get fuzzy antialiasing when things lie on fractional coordinates.

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

    In addition to using non-fractional positioning one should make sure to use a non-centered vertical alignment for the UITextField. Looks like centered vertical alignment in combination with an odd font size results in blurred text, too.

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

    Simply setting the UITextField frame height to an even value fixed it for me.

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

    I encountered this problem before. The solution below works perfectly for any text or frame size because it uses the round function to get rid of the fractional pixel values. Insert the following code after your instantiation of the uitextfield in question.

    CGRect temp = textField.frame;
    temp.origin.x = round(temp.origin.x);
    temp.origin.y = round(temp.origin.y);
    textField.frame = temp;
    
    0 讨论(0)
提交回复
热议问题