UIButton image gets pixelated when highlighted
I have an UIButton (type:custom) in an UIView set up in the interface builder, add an image for the default state to it with retina sizes. When I try on my iPhone, I see the retina version of the image, when I highlight it by tapping it it gets pixelated while being highlighted.
The funny 开发者_高级运维part is when I change the image of the UIButton by code, there is no pixelated error.
Does anyone know a workaround without loading all my button images by code? thnx!
In interface builder you can specify both regular state and highlighted state images: simply choose the required "State Config" and configure the button.
If you specified an image for Default state, and left the image for "Highlighted" state empty, and checked the "Highlighted Adjusts Image" property on, then the button will use the Default state image and gray it out when it's pressed.
However, if your Highlighted state image is also set, the button will use that instead of generating its own highlighting.
Other things to check: make sure both versions of the image are included in the project.
E.g. say you have "button_image.png" and "button_image@2x.png". Make sure both of them are in the project. Also when you specify the image in the interface builder, use the name of the standard definition image, cocoa will pick the 2x version automatically - i.e. you would put "button_image.png" as your button's image, not "button_image@2x.png"
Hope this helps
精彩评论