0

UIButton のサブクラスを作成し、コードにスタイルを適用しています。何らかの理由で、ボタンがカスタム グラデーションを取得できず、ボタンの高さが小さすぎます。uibutton の高さを調整してパディングを増やすにはどうすればよいですか。

ここに画像の説明を入力

コードは次のとおりです。

@implementation DefaultButton

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

-(id) initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];

    // Set the button Text Color
    [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];

    // Set default backgrond color
    [self setBackgroundColor:[UIColor blackColor]];

    // Draw a custom gradient
    CAGradientLayer *btnGradient = [CAGradientLayer layer];
    btnGradient.frame = self.bounds;
    btnGradient.colors = [NSArray arrayWithObjects:
                          (id)[[UIColor colorWithRed:102.0f / 255.0f green:102.0f / 255.0f blue:102.0f / 255.0f alpha:1.0f] CGColor],
                          (id)[[UIColor colorWithRed:51.0f / 255.0f green:51.0f / 255.0f blue:51.0f / 255.0f alpha:1.0f] CGColor],
                          nil];
    [self.layer insertSublayer:btnGradient atIndex:0];

    // Round button corners
    CALayer *btnLayer = [self layer];
    [btnLayer setMasksToBounds:YES];
    [btnLayer setCornerRadius:5.0f];

    // Apply a 1 pixel, black border around Buy Button
    [btnLayer setBorderWidth:1.0f];
    [btnLayer setBorderColor:[[UIColor blackColor] CGColor]];

    return self;
}
4

1 に答える 1

0

高さについては、 self.frame.size.height=30; を実行できます。(またはあなたの身長にしたいもの)、それをinitメソッドに入れます。

グラデーションと同じくらい、よくわかりません

于 2013-03-28T16:53:26.160 に答える