Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 4    Views: 106

DougJoseph
Aspiring developer
Profile
Posts: 161
Reg: Jan 30, 2016
Stonewood
2,210
02/21/16 12:01 AM (8 years ago)

_appDelegate.m - iOS Xcode - help scaling background image to fit screen size (aspectFill)

I found (here in the forums) the following method to change the white loading screen to a desired loading image: 1. BT_Config 2. --APP_NAME--_appDelegate.m 3. Change: [tmpWindow setBackgroundColor:[UIColor whiteColor]]; To: [tmpWindow setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"___ASSET_NAME_OR_IMAGE_NAME____"]]]; EXAMPLE: [tmpWindow setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"Default"]]]; 4. BT_Layout 5. loadConfigDataViewController.m 6. Change: [self.view setBackgroundColor:[UIColor whiteColor]]; To: [self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"___ASSET_NAME_OR_IMAGE_NAME____"]]]; EXAMPLE: [self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"Default"]]]; [NOTE: previously I mistakenly posted with reference to _appDelegate.m. This post is now EDITED TO SAY... ] However, in addition to the above, I am also using a "themed" background image on all my screens, and that image is not being scaled to fit. Elsewhere I found the following method, which is supposed to scale an image to fit. UIImage *backgroundImage = [UIImage imageNamed:@"Default"]; UIImageView *backgroundImageView=[[UIImageView alloc]initWithFrame:self.view.frame]; backgroundImageView.image=backgroundImage; [self.view insertSubview:backgroundImageView atIndex:0]; The above code may or may work with the "themed" background image, which is (seemingly) being controlled by the following code in the BT_Core > BT_background_view.m file: self.backgroundImage = [UIImage imageNamed:self.imageName]; [self setImage:self.backgroundImage]; Can anyone help me know how to use a "themed" background image that gets scaled to fit — specifically I'm looking for "aspectFill" instead of "aspectFit."
 
Dusko
Veteran developer
Profile
Posts: 998
Reg: Oct 13, 2012
Beograd
22,680
like
02/21/16 12:44 AM (8 years ago)
>it throws major errors when I try to use it in _appDelegate.m You can but you are not really supposed to change anything in _appDelegate.m. It is way too deep. If you make custom changes to a plugin, best to do it within the plugin itself. Or, you can create your own plugin and use it all over the code in other plugins. To create a new plugin, the best way is to snoop around the existing plugin code base. For instance, I remember that in Susan's excellent plugin called Menu with Image, there is an option to expand the image and I'd first look in that plugin's source code to see how it's done. The alternative is to go to StackOverflow and take code from there; it is not always easy and / or pleasant and can be very frustrating if you have deadlines to match. To help you solve your concrete problem, here is a method from one of my plugins, to scale the image: + (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize { if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) { if ([[UIScreen mainScreen] scale] == 2.0) { UIGraphicsBeginImageContextWithOptions(newSize, YES, 2.0); } else { UIGraphicsBeginImageContext(newSize); } } else { UIGraphicsBeginImageContext(newSize); } [image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)]; UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return newImage; } The plugin that this is taken from, by the way, lets the user choose an image from the device and put it into the header image for a menu. Can be used as a passcard, for example. Hope this helps!
 
DougJoseph
Aspiring developer
Profile
Posts: 161
Reg: Jan 30, 2016
Stonewood
2,210
like
02/21/16 02:17 AM (8 years ago)
Thanks! In my "newbie confusion" I was rather mixed up. I failed to realize that I was actually aiming to get the background images of the tab screens to be scaled to fit, while I was seemingly trying to do so by editing code that does not affect the tab screens BG images at all. I eventually found BT_background_view.m -- which has code ( "//get the image" ) starting at about line 168, which does genuinely affect the backgrounds of the tab screens. I don't know if that is a proper place to effect the auto-resizing I seek, but if so, the code there that needs tinkered with is this: [self.backgroundImage = [UIImage imageNamed:self.imageName]; [self setImage:self.backgroundImage];
 
DougJoseph
Aspiring developer
Profile
Posts: 161
Reg: Jan 30, 2016
Stonewood
2,210
like
02/21/16 02:21 AM (8 years ago)
I had been tinkering with trying to change it to something like this: self.backgroundImage = [UIImage imageNamed:self.imageName]; self.backgroundImageView =[[UIImageView alloc]initWithFrame:self.frame]; self.backgroundImageView.image=backgroundImage; ...However, even if the above is on the right track, there seems to be at least one more step that eludes me.
 
DougJoseph
Aspiring developer
Profile
Posts: 161
Reg: Jan 30, 2016
Stonewood
2,210
like
02/25/16 07:10 AM (8 years ago)
NOTE: previously I mistakenly posted with reference to _appDelegate.m. I now realize that does not seem to control the image size of a "themed" BG image on a regular screen... I am using a "themed" background image on all my screens, and that image is not being scaled to fit. Elsewhere I found the following method, which is supposed to scale an image to fit. UIImage *backgroundImage = [UIImage imageNamed:@"Default"]; UIImageView *backgroundImageView=[[UIImageView alloc]initWithFrame:self.view.frame]; backgroundImageView.image=backgroundImage; [self.view insertSubview:backgroundImageView atIndex:0]; The above code may or may work with the "themed" background image, which is (seemingly) being controlled by the following code in the BT_Core > BT_background_view.m file: self.backgroundImage = [UIImage imageNamed:self.imageName]; [self setImage:self.backgroundImage]; Can anyone help me know how to use a "themed" background image that gets scaled to fit — specifically I'm looking for "aspectFill" instead of "aspectFit."
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.