【iOS】UIViewに背景画像を設定する方法

UIColorにcolorWithPatternImageというメソッドがあるので、背景画像を渡して対象となるviewのbackgroundColorにセットするだけ。

UIImage *backgroundImage  = [UIImage imageNamed:@"bg.png"];
self.view.backgroundColor = [UIColor colorWithPatternImage:backgroundImage];

試してみると、こんな感じです。

f:id:w6500:20140106215442p:plain

背景画像なのに、UIColorっていうところが若干気持ち悪いです。