文章出處

1. 使用一個UIImageView實例做子視圖,并且放最后面
UIImageView *customBackgournd = [UIImageView alloc] initWithImage:[UIImage imageNamed:@"background.jpg"]];
self.background = customBackground;
[customBackground release];

[self addSubview:background];
[self sendSubViewToBack:background];

如果是用ib,就在xib文件中添加UIImageView,放在最下面。

2. 

self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.jpg"]];

推薦使用這種,方便。

今天在代碼中使用

    self.view.backgroundColor = [UIColorcolorWithPatternImage:[UIImageimageNamed:@"instrument_bg@2x.png"]];

結果導致instrument_bg@2x.png這張圖片本來是640x960的,結果顯示的時候只顯示了左邊一半出來與上面一半出來。

正確的代碼應該是

 

    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"instrument_bg"]];

這樣的話,會自動去匹配圖片。

錯誤的寫法導致了圖片放大了2倍,所以看起來就只有一半了。另外圖片的后綴一般也省略為好


文章列表


不含病毒。www.avast.com
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()