如何在iphone应用程序中叠加图像?

时间:2010-08-25 05:50:43

标签: iphone objective-c cocoa-touch uikit core-animation

我想在按钮上叠加图像。按钮有一个背景图像。如果我想在按钮上叠加半透明图像,假设我覆盖了一个半透明的红色图像。任何人都可以建议如何做到这一点?建议一些文件。

2 个答案:

答案 0 :(得分:2)

UIImageView *overlay = [[UIImageView alloc] initWithImage:...];
[overlay setAlpha:0.5];

UIButton *button = [[UIButton alloc] initWithType:UIButtonTypeRoundedRect];
[button setBackgroundImage:...];

[button addSubview:overlay];
[overlay release];

UIButton还有一个image属性以及一个backgroundImage属性,但我不确定透明度如何与它一起使用。

http://developer.apple.com/iphone/library/documentation/uikit/reference/UIButton_Class/UIButton/UIButton.html

答案 1 :(得分:1)

在直接回答后,请注意更改按钮alpha也会影响叠加透明度,因此请检查按钮alpha是否为1.0f(默认值)。

另请注意,在将其作为子视图添加到按钮后应释放重叠变量,否则会导致内存泄漏。