2012-01-05 54 views
0

对于UIButton在视图之一,我创建了一个图像用于正常状态,但我想继续使用默认的蓝色/图像的突出显示/选择状态, 有没有办法做到这一点?或者我是否真的必须为突出显示/选择准备定制图像?UIButton定制使用标准的图像/颜色为突出显示的状态

下面是我每@mashios要求和意见有如下的代码 -

UIButton *shareButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
[shareButton setFrame:CGRectMake(1.0, 0.0, 99.0, 43.0)]; 
[shareButton setBackgroundImage:[[UIImage imageNamed:@"share_normal"] 
           stretchableImageWithLeftCapWidth:0.0 
           topCapHeight:0.0] forState:UIControlStateNormal]; 
[shareButton setBackgroundImage:[[UIImage imageNamed:@"share_normal"] // bottom_up_left_3_selected 
           stretchableImageWithLeftCapWidth:0.0 
           topCapHeight:0.0] forState:UIControlStateHighlighted]; 
[shareButton addTarget:self action:@selector(share:) forControlEvents:UIControlEventTouchUpInside]; 

回答

-1

可以相同的图像设置为两种状态。

+0

我刚刚试验过,通过将相同的图像(用于正常状态)设置为突出显示的状态。结果不是我想要的,而是点击按钮时根本没有颜色变化。 – tom 2012-01-09 18:24:49

+0

你可以只提供一些代码。 – mashios 2012-01-10 04:48:16

+0

请查看我的帖子,上面有我使用的代码 – tom 2012-01-10 09:29:06

-1

首先,你需要相同的图像为正常,突出显示和选择状态。在另一个评论中,你想改变按钮的颜色。虽然我想建议你几件事。 1.将图像设置为按钮pls时。传递完整的字符串像(something.jpg)。 2.仅在需要时才使用stretchableImageWithLeftCapWidth & topCapHeight。 3.设置图像像这样[[shareButton setBackgroundImage:[[UIImage imageNamed:@“share_normal.jpg/png”] forcontrolstate:UIControlStateNormal]; 4.我只是改变这些东西,它为我工作。