0

我对可可触摸中的 iPad 编程比较陌生。

我有一个带有 alpha 通道的 PNG。我想将它作为一个子视图覆盖在 UIButton 上,这样它看起来好像 Button 周围有一个边框。(Alpha 通道是图像的中心,因此用户仍然必须看穿它)。

我似乎找不到正确显示 Alpha 通道的方法。中心仍显示为不透明的白色。

如果我不能这样做,我将如何在 UIButton 周围绘制边框?子类 UIButton 并覆盖 -drawRect?请记住,按钮和边框都是以编程方式(动态)添加的。(我不想删除按钮以添加边框。) alpha - 解决方案会更可取,因为这样我可以在超级视图(滚动视图)上覆盖边框图像并设置偏移量以对应于按钮.

4

1 回答 1

1

您可以向 UIButton 添加图像或设置图像,但据我所知,您无法为整个事物设置 alpha 蒙版(如果我正确理解您的问题)。因此,不可能使用带有孔的标准按钮。但是您可以使用自定义类型按钮并将图像设置为您想要的任何图像,所以这应该会给您任何想要的效果。如果您以后需要对其进行细化,可以向其添加更多子视图。

使用叠加编辑:

    UIButton *button = [UIButton buttonWithType....]; // your ordinary button here
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"youroverlay.png"]];
    // maybe adjust your overlay position here, e.g. imageView.center = .... (use bounds of button, not its frame), or the size directly
    [button addSubview:imageView];
于 2010-06-10T12:16:04.067 回答