Question: 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 responder, but blurred again when it loses focus:

[![alt text](https://i.stack.imgur.com/kmcmI.png)](https://i.stack.imgur.com/kmcmI.png)  

(source: [mikeweller.com](http://www.mikeweller.com/images/blog/UITextFieldBlur.png)) 

Does anybody know how to fix this?

Answer: 
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](http://www.iphonedevsdk.com/forum/iphone-sdk-development/1216-fuzzy-graphics-when-cgrect-given-float-value.html) 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.
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.