用UIImage和UIButton画出的按钮,使用透明的png图片,为什么会出现白边


我们使用下面这个图片作为按钮图片,这个图片的边缘没有任何白色的像素

按钮图片

但是最后显示的效果确是

效果截图

这是放大后的效果,实际效果就是显示出两个很醒目的白点,我不知道这两个白点是如何出现的,原图中并没有

UIImage *btnImage = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"button-add" ofType:@"png"]];

UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.bounds = CGRectMake(0, 0, btnImage.size.width, btnImage.size.height);
[btn setImage:faceImage forState:UIControlStateNormal];

以上是我用来画按钮的代码,是否针对透明的png图片,还有一些特殊的设置?

ios xcode objective-c iphone

天下无敌1 10 years, 9 months ago

虽然不知道原因,但是经尝试,在做图片的时候把背景图层的颜色去掉能解决问题(尽管这个图层在导出时我们根本就没让它显示出来)。我是在改一个mac app的图标的时候发现这个问题的,见图:
白边版:
请输入图片描述
正常版:
请输入图片描述
解决方式:
请输入图片描述

改好以后从dock上移除一下图标就Ok了,dock会对图标文件缓存

MIXture answered 10 years, 9 months ago

Your Answer