2012-05-11 13 views
5

Also ich eine Schaltfläche erstellen. Ich möchte, dass es abgerundete Ecken ohne abgerundete .png Dateien haben Ich kann das Hintergrundbild ok einstellen. Ich kann die Ecken gut abrunden. Wenn ich jedoch das Hintergrundbild einstelle, verschwinden die abgerundeten Ecken.UIButton mit abgerundeten Ecken mit quadratischen setBackgroundImage

Ich habe das schon einmal vor langer Zeit gemacht, aber es scheint nicht zu funktionieren. Wie kann das gemacht werden?

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

Antwort

18

Fügen Sie die maskToBounds Eigenschaft auf den Button aus.

button1.layer.masksToBounds = YES; 
+0

yea duh danke! – Rick

+0

Großartig. Löste mein Problem. +1 –

+0

vielen Dank! – mikezs

Verwandte Themen