簡體   English   中英

如何根據屏幕尺寸設置背景圖像?

[英]How to set the background image according to screen size?

我想根據屏幕尺寸設置圖像。 我已經遍歷了很多代碼,但是還沒有找到可行的解決方案。 我正在使用Xcode 5.1.1和Iphone Retina 4inch。 每當我添加背景圖片時,它就會變得很大並且超出屏幕大小。 請幫助我。

使用Anbu答案中的代碼獲取屏幕高度,並將圖像設置為AspectFit,以免屏幕過大和超出范圍:

yourImageview.contentMode = UIViewContentModeScaleAspectFit;
yourImageview.clipsToBounds = YES;

如果將視圖直接添加到UIViewController ,則應使用viewWillLayoutSubviewsdoc )方法進行調整大小。 像這樣:

- (void)viewWillLayoutSubviews
{
    [super viewWillLayoutSubviews];
    self.imageView.frame = self.bounds;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM