2012-08-17 78 views
0

我正在研究一個應用程序,在UIAlertView中顯示一些圖標以解釋它們的用法。 我這樣做,使用:UIAlertView中的圖像:CGRectMake在視網膜和非視網膜中iPhone

UIAlertView *helpAlert = [[UIAlertView alloc] initWithTitle:@"The button:\n\n is used to do... \n\n " message:@"" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil]; 

    UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(20, 55, 40, 40)]; 
    NSString *path1 = [[NSString alloc] initWithString:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"bottle_w_40.png"]]; 
    UIImage *bkgImg1 = [[UIImage alloc] initWithContentsOfFile:path1]; 
    [imageView1 setImage:bkgImg1]; 
    [bkgImg1 release]; 
    [path1 release]; 

    [helpAlert addSubview:imageView1]; 
    [imageView1 release]; 
    [helpAlert show]; 
    [helpAlert release]; 

它運作良好,在模擬器和我的iPhone 3GS(無視網膜顯示)。我的傢伙是關於視網膜的行爲。圖像位置會不同?我是否需要使用CGRectMake的某個scaleFactor或UIAlertview中的位置是絕對的?

回答

1

在應用程序資源中,提供名爲「bottle_w_40 @ 2x」的圖像,並且在涉及視網膜顯示時,這將是主要問題。矩形不需要調整大小。

+0

只需添加與該名稱或不同大小的圖標相同的圖標? – doxsi 2012-08-17 18:06:25

+0

對不起,我忘了指定,圖標圖片需要是第一張圖片尺寸的兩倍......所以如果bottle_w_40.pg是100x100,那麼[email protected]會是200x200。 – CBredlow 2012-08-17 18:10:03

1

據我所知,該代碼可以在視網膜顯示器上工作。

你可以在模擬器中測試這個。轉到模擬器的硬件>設備菜單,然後選擇「iPhone(視網膜)」或「iPad(視網膜)」。

+0

在模擬器上切換到iPhone(視網膜),是的它的工作原理。這是否意味着它也可以在真實設備上運行? – doxsi 2012-08-17 18:05:33

+0

它可能會工作,但你需要找到一個真正的視網膜設備來測試。 – 2012-08-17 18:07:22