UIViewの背景画像をフィットさせたい
UIViewは(UIImageViewとは違い)背景画像のサイズをフィットする機能がないので、image自体をビューのサイズに合わせて再描画する必要がある。
NSString *bundlePath = [[NSBundle mainBundle] bundlePath]; UIImage *image; image = [UIImage imageWithContentsOfFile:[bundlePath stringByAppendingPathComponent:@"img/common/Title_Image_Bg.png"]]; UIGraphicsBeginImageContext(self.frame.size); [image drawInRect:self.bounds]; UIImage *backgroundImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); [self setBackgroundColor:[UIColor colorWithPatternImage:backgroundImage]]; image = nil; backgroundImage = nil;
関連記事
-
-
iPhone画面サイズ
3.5inch 320 x 480px (Retina 640 x 960px) …
-
-
UILabelをコードで生成(Tips付)
Main Storyboard (IB)に用意されている Label を使わずに …
-
-
ボタンに画像(背景)を指定する
// ボタンのサイズを指定する UIButton *startBtn = [[U …
-
-
【Xcode ObjC #800】Documentsフォルダを見る
iPhone(iPad)のアプリに格納されているDocumentsフォルダを、i …
-
-
アプリの名前をつける
iPhoneのホーム画面に表示される「アプリ名」の付け方 アプリ名の変更には上 …
-
-
BGM・SE 導入方法
音楽:導入方法 1… AVFoundationフレームワークを追加 2… hファ …
-
-
テキストの文字間を詰める
UILabelなどで文字間を詰める(カーニング)したい時がちょいちょいあると思い …
-
-
NSLog まとめ
デバッグする時などに、ログを出力する方法としてNSLogを使用します。 文字列を …
-
-
負の数を絶対数へ変換 abs
負の数を自然数(マイナスを含まない数字)にしたくて、「Xcode 自然数 変換」 …
-
-
UIImageView 画像の差し替え
[UIImageView alloc] 後の画像を変換する時は下記コードを参照し …
