2012-05-11 8 views
5

Quindi creo un pulsante. Voglio che abbia gli angoli arrotondati senza creare file .png arrotondati Posso impostare l'immagine di sfondo ok. Posso arrotondare gli angoli ok. Tuttavia, quando imposto l'immagine di sfondo, gli angoli arrotondati scompaiono.UIButton con angoli arrotondati utilizzando il set quadratoBackgroundImage

L'ho fatto una volta tanto tempo fa, ma non riesco a farlo funzionare di nuovo. Come si può fare?

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

risposta

18

aggiungere la proprietà maskToBounds al pulsante.

button1.layer.masksToBounds = YES; 
+0

sì, grazie! – Rick

+0

Grande. Risolto il mio problema +1 –

+0

grazie mille! – mikezs