我有以下自定义按钮:
_button = [UIButton buttonWithType:UIButtonTypeCustom];
_button.backgroundColor = [UIColor darkGrayColor];
UIImage *bg = [UIImage imageNamed:@"btn_bg_highlighted.png"];
[_button setBackgroundImage:bg forState:UIControlStateHighlighted];
正如所料,该按钮具有深灰色背景。当我按下按钮时,会显示背景图像(红色方块)。
稍后在程序中我将按钮前景图像设置为透明(红色矩形)。之后,灰色背景变为白色。当我按下按钮时,它变成灰色。
当我在[UIButton buttonWithType:UIButtonTypeCustom]
之后立即设置图像时效果很好。
你知道问题是什么吗?
答案 0 :(得分:0)
NSData
对象获取图像。在服务器上,UIImage
将NSData
转换为UIImageJPEGRepresentation(image, quality)
。但这应该是UIImagePNGRepresentation(image)
,否则透明度会在客户端丢失。现在一切都很棒!