i created a custom UIButton inside a scrollview.
But the picture does not show, any idea what i am doing wrong ?
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setBackgroundImage:[UIImage imageNamed:@"anzahl.png"] forState:UIControlStateNormal];
[button setTitle:@"-" forState:UIControlStateNormal];
button.frame = CGRectMake(x, y, viewWidth, viewHeight);//width and height should be same value
button.clipsToBounds = YES;
button.layer.cornerRadius = 20;//half of the width
button.layer.borderColor=[UIColor blueColor].CGColor;
button.layer.borderWidth=1.0f;
[button setAlpha:1.0];
[scroller1 addSubview:button];
[button release];
You don’t need to release the button, as it’s not been allocated. You’ve called a class method on UIButton, so no release is needed.
I’d also suggest you first verify that the image is loading correctly so test
Or you could have your frame co-ordinates set incorrectly so that the button is drawing outside of the visible screen area, so the next step is ensure that your viewWidth & viewHeight are the correct size and not 0. Also make sure that your x & y co-ordiantes are in the currently visible area of the screen and not outside the visible screen bounds (remember that the x,y position will be relative to the super view they are placed in (in this case scroller1)).