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;
}