最近、問題が発生しました。UIButtonとそのための2つの画像があります。通常状態の場合は1、強調表示の場合は1。問題は、通常の状態の画像が透明であるため、グラデーションを使用して塗りつぶす必要があることです。しかし、そうすると、強調表示された画像が表示されなくなります。コードの一部は次のとおりです。
UIImage *balloonImage = [[UIImage imageNamed:@"balloon.png"]resizableImageWithCapInsets:UIEdgeInsetsMake(3, 3, 3, 3)];
UIImage *balloonImageDown = [[UIImage imageNamed:@"balloon-down.png"]resizableImageWithCapInsets:UIEdgeInsetsMake(3, 3, 3, 3)];
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = CGRectMake(0, 0, 320 - 45 - 10, 100);
gradient.cornerRadius = 3.0f;
gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor colorWithRed:221.0f/255.0f green:231.0f/255.0f blue:246.0f/255.0f alpha:1.0f]CGColor], (id)[[UIColor colorWithRed:191.0f/255.0f green:207.0f/255.0f blue:234.0f/255.0f alpha:1.0f] CGColor], nil];
self.balloonButton = [UIButton buttonWithType:UIButtonTypeCustom];
[self.balloonButton.layer insertSublayer:gradient atIndex:0];
[self.balloonButton setBackgroundImage:balloonImage forState:UIControlStateNormal];
[self.balloonButton setBackgroundImage:balloonImageDown forState:UIControlStateHighlighted];
self.theImageView = [[[UIImageView alloc]init]autorelease];
[self.balloonButton addSubview:theImageView];
[self.contentView addSubview:balloonButton];
グラデーションは正常に見え、すべてが機能しています。ボタンをタップした場合の画像の変更を除きます。
グラデーションの前にballoonImageDownを配置する方法はありますか?またはどうすればそれを行うことができますか?
どんな助けでもいただければ幸いです。