{"id":1959,"date":"2014-09-28T07:19:44","date_gmt":"2014-09-28T14:19:44","guid":{"rendered":"http:\/\/www.wellgolly.com\/?p=1959"},"modified":"2014-09-28T07:20:07","modified_gmt":"2014-09-28T14:20:07","slug":"1959","status":"publish","type":"post","link":"https:\/\/www.wellgolly.com\/?p=1959","title":{"rendered":"Background images for iOS"},"content":{"rendered":"<p>I have 27 apps in the store and did not want to create and manage new backgrounds for each of them. And I suspect that there will be more sizes in the future. So what I did was create an 1800&#215;1800 image for each app. They are mostly around 300-400KB. Then in viewWillAppear I call this method.<br \/>\n<pre><code class=\"\u2019smaller\u2019 preserve-code-formatting\">\n- (void)pickBackgroundImage {\n\n&nbsp;&nbsp;&nbsp;&nbsp;UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];\n&nbsp;&nbsp;&nbsp;&nbsp;CGFloat scale = [UIScreen mainScreen].scale;\n&nbsp;&nbsp;&nbsp;&nbsp;CGPoint midPoint = [Utilities findMidpoint:self.view];\n\n&nbsp;&nbsp;&nbsp;&nbsp;NSString *pictFile = [[NSBundle mainBundle] pathForResource:@&quot;Background&quot; ofType:@&quot;png&quot;];\n&nbsp;&nbsp;&nbsp;&nbsp;UIImage *imageToDisplay = [UIImage imageWithContentsOfFile:pictFile];\n&nbsp;&nbsp;&nbsp;&nbsp;imageToDisplay&nbsp;&nbsp;= [UIImage imageWithCGImage:imageToDisplay.CGImage scale:scale orientation:imageToDisplay.imageOrientation];\n\n&nbsp;&nbsp;&nbsp;&nbsp;CGRect pictFrame;\n&nbsp;&nbsp;&nbsp;&nbsp;if(orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CGFloat imageWidth = (unsigned int)(.9f * self.view.frame.size.width);\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pictFrame = CGRectMake(midPoint.x - imageWidth\/2, midPoint.y - imageWidth\/2, imageWidth, imageWidth);\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pictFrame.origin.y = self.view.frame.origin.y + .3f * pictFrame.origin.y;\n&nbsp;&nbsp;&nbsp;&nbsp;} else {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CGFloat imageWidth = (unsigned int)(self.view.frame.size.height - 20 - 44);\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pictFrame = CGRectMake(midPoint.x - imageWidth\/2, midPoint.y - imageWidth\/2, imageWidth, imageWidth);\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pictFrame.origin.y = 10;\n&nbsp;&nbsp;&nbsp;&nbsp;}\n&nbsp;&nbsp;&nbsp;&nbsp;self.BGView = [[UIImageView alloc] initWithImage:imageToDisplay];\n&nbsp;&nbsp;&nbsp;&nbsp;self.BGView.frame = pictFrame;\n&nbsp;&nbsp;&nbsp;&nbsp;self.BGView.contentMode = UIViewContentModeScaleAspectFit;\n\n&nbsp;&nbsp;&nbsp;&nbsp;[self.view insertSubview:self.BGView atIndex:0];\n}<\/code><\/pre><br \/>\nThe arithmetic is a little tricky, but basically I figure out how big the screen is, then subtract the menubar and bottom bar. Then fill 90% of whats left with the image. I use the scale factor, CGFloat scale = [UIScreen mainScreen].scale;, to make the device think that the image was created just for it, e.g. @2x or @3x.<\/p>\n<p>Works in the simulator for all devices. I don\u2019t have a new phone so I haven\u2019t been able to test it on one yet.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have 27 apps in the store and did not want to create and manage new backgrounds for each of them. And I suspect that there will be more sizes in the future. So what I did was create an 1800&#215;1800 image for each app. They are mostly around 300-400KB. Then in viewWillAppear I call &hellip; <a href=\"https:\/\/www.wellgolly.com\/?p=1959\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Background images for iOS<\/span><\/a><\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[],"class_list":["post-1959","post","type-post","status-publish","format-standard","hentry","category-ios"],"_links":{"self":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts\/1959","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1959"}],"version-history":[{"count":0,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts\/1959\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1959"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1959"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1959"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}