2012-05-11 16 views
5

ボタンを作成します。丸い.pngファイルを作ることなく角を丸くしてほしい 私は背景画像をOKに設定できます。私は角を丸めることができます。しかし、背景画像を設定すると、丸い角が消えてしまいます。角を丸くしたUIButton setBackgroundImage

私はずっと前にこれをやっていましたが、もう一度やり直すことはできませんでした。これはどうすればできますか?

UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom]; 
[button1 addTarget:self action:@selector(goSpecials) 
    forControlEvents:UIControlEventTouchUpInside]; 
[button1 setTitle:@"Specials" forState:UIControlStateNormal]; 
button1.titleLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:(15.0)]; 
[button1 setTitleColor:[self colorWithHexString:buttonColor] forState:UIControlStateNormal]; 
button1.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed: @"button.png"]]; 
//[button1 setBackgroundImage:[UIImage imageNamed:@"button.png"] forState:UIControlStateNormal]; 
button1.frame = CGRectMake(20.0, 232.0, 135.0, 32.0); 
button1.layer.borderColor = [UIColor blackColor].CGColor; 
button1.layer.borderWidth = 0.5f; 
button1.layer.cornerRadius = 8.0f; 
[self.view addSubview:button1]; 

button.png: enter image description here

答えて

18

は、あなたのボタンにmaskToBoundsプロパティを追加します。

button1.layer.masksToBounds = YES; 
+0

ありがとうございました! – Rick

+0

私の問題を解決しました。 +1 –

+0

ありがとうございました! – mikezs

関連する問題