0

最近、問題が発生しました。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を配置する方法はありますか?またはどうすればそれを行うことができますか?

どんな助けでもいただければ幸いです。

4

1 に答える 1

1
[yourButton setTitleColor:[UIColor colorWithRed:0.3 green:0.6 blue:0.9 alpha:0.5]
//                                set 'alpha' to something less than 1. -----^^^

これは、透明にするために行うことです。(アルファ値の変更)タッチダウンとタッチアップの方法でこれらの値を変更する必要があります。

于 2011-12-13T09:56:32.013 に答える