3

如何创建像图片中一样的 iPhoto 按钮

在此处输入图像描述

我已经使用圆形纹理按钮或将按钮的图像设置为模板尝试了几件事。但这些方法都没有真正奏效。

到目前为止,感谢您的回答。

编辑:按钮的图像应该只是一个简单的 pdf。渐变和白色阴影应该是自动绘制的。

4

3 回答 3

1

正如贾斯汀所说,您应该创建一个NSButton类型为Momentary Change的类型。然后,您应该通过在文件名中包含后缀 Template 来表明它是模板图像,例如EditTemplate.png.

我知道您说过您尝试将图像设置为模板,但我发现如果我不使用Momentary Change按钮类型,这并不总是有效的。

于 2012-02-13T21:38:54.730 回答
0

我认为最简单的解决方案是创建具有以下类型的按钮:Momentary Change 并在其上添加具有透明背景的 .png 文件类型的图像,当按钮打开时,您可以更改为具有背景的其他图片。

例如设置/更改图像:

[_yourButton setImage:_image];

如果我正确理解了你想要做什么。

于 2012-02-13T18:47:24.677 回答
0

你可以继承 NSButtonCell。并实现这些功能:

- (void)drawImage:(NSImage*)image 
        withFrame:(NSRect)frame 
           inView:(NSView*)controlView
{
     // Draw the image of the pen. 
}

- (NSRect)drawTitle:(NSAttributedString*)title 
          withFrame:(NSRect)frame 
             inView:(NSView*)controlView
{
     // Draw the text.
}

- (void)drawBezelWithFrame:(NSRect)frame 
                    inView:(NSView *)controlView
{
}

要设置子类,只需将 Interface Builder 中按钮单元的“自定义类”字段从“NSButtonCell”编辑为“YourSubClass”

于 2012-02-13T15:36:44.417 回答