我想在点击切换按钮图像 [英] I want to switch button image on click

查看:135
本文介绍了我想在点击切换按钮图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想改变点击按钮的图像。点击一次1图像应该在他按钮进行设置,当再次点击第二个形象应该是那里,这些图片应该点击切换。

I want to change the image of button on click. click once 1 image should be set on he button and when again clicked the 2nd image should be there and these images should switch on click.

推荐答案

将按钮添加到您的视图,去掉标题并设置类型切换(在检查的属性选项卡)。这里还设置了形象和按钮的备用图像是这样的:

Add a button to your view, remove the title and set the type to toggle(in the attributes tab of the inspector). Here also set the image and alternate image of your button like this:

这应该这样做。

如果你想使用自定义图像,你将不得不做编程方式是这样的:

If you want to use a custom image you will have to do it programatically like this:

NSString* path  = [[NSBundle mainBundle] pathForResource:@"myImage" 
					          ofType:@"png"];
NSURL* url  	= [NSURL fileURLWithPath:path];
NSImage *image  = [[NSImage alloc] initWithContentsOfURL: url];

[myButton setImage: image];

和分别为备用图片:

[myButton setAlternateImage: image2];

这篇关于我想在点击切换按钮图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆