views:

59

answers:

1

Hi. I'm setting up a custom button with an oval background image in UIView.

In iPhone OS 3, [UIImage:stretchableImageWithLeftCapWidth:topCapHeight:] works fine.

But, in iOS 4 with iPhone 4 (means Hi-Resolution), the background image doesn't stretch out.

Here's the code in question:

UIButton* btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setFrame:CGRectMake(0, 0 , 200 , 35)];
btn.titleLabel.font = [UIFont boldSystemFontOfSize:12];
[btn setTitle:@"Custom Button" forState:UIControlStateNormal];

UIImage* bgImg = [[UIImage imageNamed: @"buttonBg"] stretchableImageWithLeftCapWidth:6 topCapHeight: 6];
    // butonBg.png : 46 x 35px
    // [email protected] : 92 x 70px
[btn setBackgroundImage:bgImg forState:UIControlStateNormal];

[self.view addSubview:btn];

What am I missing? Is it a scaling problem?

Thanks in advance.

A: 

Looks like you could use setBackgroundImage of the UIButton instead of image.

pdbitheads