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;
関連記事
-
UILabelをコードで生成(Tips付)
Main Storyboard (IB)に用意されている Label を使わずに …
-
LaunchImage 関連の設定
▼アプリ起動時のスプラッシュ画面 通常はチラっと一瞬だけ表示されるスプラッシュ画 …
-
よく使うショートカット
Ctrl+6 : 表示中のクラスのメソッド一覧 さらにテキスト入力してインクリメ …
-
ボタンに画像(背景)を指定する
// ボタンのサイズを指定する UIButton *startBtn = [[U …
-
SubViewの重ね順を変更する
SubViewの重ね順を最前面に移動する場合 bringSubviewToFro …
-
乱数のこと
乱数(ランダムな数)を取り出す際 rand や arc4random を使用しま …
-
SNS連携
Twitter・Facebookとの連携は #import <Social …
-
CheatSheet
Xcodeの便利なショートカットキー 良く使ってるなと感じたら追記 Cmd+Al …
-
UIButton 同時押し制御
UIButton *myBtn = [UIButton alloc] init] …
-
UIImageViewにボタンを貼りたい場合
タイトル画面などを作りたい場合、UIImageViewを使用して背景などを作るこ …