2012-05-11 10 views
5

Así que creo un botón. Quiero que tenga esquinas redondeadas sin hacer redondeados .png archivos Puedo establecer la imagen de fondo bien. Puedo redondear las esquinas bien. Sin embargo, cuando configuro la Imagen de fondo, las esquinas redondeadas desaparecen.UIButton con esquinas redondeadas utilizando el conjunto cuadradoBackgroundImage

Lo hice una vez antes hace mucho tiempo, pero parece que no puede volver a funcionar. ¿Cómo puede hacerse esto?

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

Respuesta

18

añadir la propiedad maskToBounds a su botón.

button1.layer.masksToBounds = YES; 
+0

yea duh gracias! – Rick

+0

Genial. Resolvió mi problema +1 –

+0

muchas gracias! – mikezs