2010-08-05 60 views
0

我在UIView中設置了一個橢圓形背景圖像的自定義按鈕。如何在UIButton中顯示高分辨率可伸縮的背景圖像?

在iPhone OS 3中,[UIImage:stretchableImageWithLeftCapWidth:topCapHeight:]工作正常。

但是,在iOS 4與iPhone 4(意味着高分辨率),背景圖像不伸展。

這裏是有問題的代碼:

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]; 

我缺少什麼?這是一個縮放問題嗎?

在此先感謝。

回答

0

看起來像你可以使用UIButton的setBackgroundImage而不是圖像。

相關問題