Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 13    Views: 47

Alex@TM
Apple Fan
Profile
Posts: 956
Reg: Dec 20, 2011
London, UK
10,560
06/14/14 06:30 AM (10 years ago)

Xib button question...

How do i make the xib button menu rescale please? So, for iPhone 5 screens I have the buttons located at the base of the screen. when loaded on iphone for the buttons are chopped off of the bottom. Is there a way to make these scale so they load in the equivalent space, ie at the base of the screen but not literally so they are not chopped off the bottom? Does this make sense? Many thanks.
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
06/14/14 07:33 AM (10 years ago)
It makes lots of sense, but I'm not sure how you're going to approach it. What's happening is, the iPhone 5 xib file is loading for both iPhone 4 and 5, subsequently, the iPhone 4's 'shorter' screen won't display the lower pixels of the iPhone 5 sized xib. There are a few different approachs to consider: 1) create a new xib, sized for the iPhone 4, and 'tie' it in with the header/implementation file to be used for iPhone 4 2) Move the buttons up so that they'll fit on both screens. Sometimes people put artwork or something that looks nice on the 5, and doesn't show up on the 4. 3) code the buttons to reposition if on an iPhone 4 screen. Thats about as much as you can do without contacting the developer for custom changes... Cheers! -- Smug
 
Niraj
buzztouch Evangelist
Profile
Posts: 2943
Reg: Jul 11, 2012
Cerritos
37,930
like
06/14/14 08:14 AM (10 years ago)
I would opt for Smug option 1. Ideally, we would learn how to use the Auto Layout feature of iOS and Xcode. -- Niraj
 
Alex@TM
Apple Fan
Profile
Posts: 956
Reg: Dec 20, 2011
London, UK
10,560
like
06/14/14 08:22 AM (10 years ago)
Thanks Smug and Niraj. I'm comfortable liking a view controller to a xib but have never tried to link a view controller to two, any ideas? I'll check google for answers to that - would be a great solution. Many thanks both. Alex
 
Niraj
buzztouch Evangelist
Profile
Posts: 2943
Reg: Jul 11, 2012
Cerritos
37,930
like
06/14/14 08:35 AM (10 years ago)
Remember how one can make a XIB for iPhone and iPad? myClassName.xib myClassName~ipad.xib Perhaps there is a similar differentiation between 3.5" and 4" iPhone sizes for XIB filenames. -- Niraj
 
Niraj
buzztouch Evangelist
Profile
Posts: 2943
Reg: Jul 11, 2012
Cerritos
37,930
like
06/14/14 08:43 AM (10 years ago)
A quick search led to this Stack Overflow answer by Ed Trujillo: If you go with the solution of using 2 xib files; in your initWithNibName() method simply make a call to super with the different nib name. I would test on the original 480 height dimension rather than on the 568 height so that the larger xib file is selected when Apple releases a larger screen. In the future, at least the larger xib won't be letter-boxed as much as the smaller one. // From MainView.m - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { CGSize result = [[UIScreen mainScreen] bounds].size; if(result.height == 480) { // iPhone Classic self = [super initWithNibName:@"MainView" bundle:nibBundleOrNil]; } else { // iPhone 5 or maybe a larger iPhone ?? self = [super initWithNibName:@"MainView5" bundle:nibBundleOrNil]; } return self; } http://stackoverflow.com/questions/13275144/how-to-make-xib-compatible-with-both-iphone-5-and-iphone-4-devices -- Niraj
 
Alex@TM
Apple Fan
Profile
Posts: 956
Reg: Dec 20, 2011
London, UK
10,560
like
06/14/14 08:47 AM (10 years ago)
Thanks Niraj, just spotted this - be interesting to see if it works, i'll report back :)
 
Alex@TM
Apple Fan
Profile
Posts: 956
Reg: Dec 20, 2011
London, UK
10,560
like
06/14/14 08:51 AM (10 years ago)
Actually this is more complicated through BT than making a native app as you have to take in to consideration the button functionality here: //initWithScreenData -(id)initWithScreenData:(BT_item *)theScreenData{ NSString *xibName = [BT_strings getJsonPropertyValue:theScreenData.jsonVars nameOfProperty:@"xibName" defaultValue:@""]; if (xibName.length<1) xibName = @"JM_Xib_button_menu"; //make sure user didn't include ".xib" at end of filename. If they did, remove it. NSRange positionOfExtension = [xibName rangeOfString:@".xib" options:NSCaseInsensitiveSearch]; if(positionOfExtension.location != NSNotFound) { //found .xib at end of filename - remove. xibName = [xibName substringToIndex:xibName.length-4]; [BT_debugger showIt:self message:[NSString stringWithFormat:@"new xib filename:%@", xibName]]; } if((self = [super initWithNibName:xibName bundle:nil])){ [BT_debugger showIt:self message:@"INIT"]; //set screen data [self setScreenData:theScreenData]; } return self; } Not entirely sure how you would also reference the 2nd nib?
 
Alex@TM
Apple Fan
Profile
Posts: 956
Reg: Dec 20, 2011
London, UK
10,560
like
06/14/14 08:52 AM (10 years ago)
I think for now it might just make sense to lose the functionality on the 4 and think about it for the future.
 
Niraj
buzztouch Evangelist
Profile
Posts: 2943
Reg: Jul 11, 2012
Cerritos
37,930
like
06/14/14 08:59 AM (10 years ago)
Dude -- just merge those two code blocks, yours and mine. You are so close! Don't give up on this ... Finish line in easy reach. I'm off to breakfast ... Will check on your victory lap afterwards. -- Niraj
 
Alex@TM
Apple Fan
Profile
Posts: 956
Reg: Dec 20, 2011
London, UK
10,560
like
06/14/14 11:07 AM (10 years ago)
Created the nib, added the code and the 3,5 screen is still reading the 4 screen. I'm going to give up I think!
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
06/14/14 07:05 PM (10 years ago)
Don't give up... - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil; { yourApp_appDelegate *appDelegate = (yourApp_appDelegate *)[[UIApplication sharedApplication] delegate]; if (appDelegate.rootDevice.isIPad) { self = [super initWithNibName:@"JM_xib~iPad" bundle:nil]; } else { if ([UIScreen mainScreen].bounds.size.height == 568) { self = [super initWithNibName:@"JM_xib5" bundle:nil]; } else { self = [super initWithNibName:@"JM_xib4" bundle:nil]; } } return self; } Cheers! -- Smug
 
Alex@TM
Apple Fan
Profile
Posts: 956
Reg: Dec 20, 2011
London, UK
10,560
like
06/14/14 11:15 PM (10 years ago)
Cant get it to work! Thanks for trying!
 
nadthevlad
Code is Art
Profile
Posts: 1025
Reg: Jun 07, 2012
Denver
21,850
like
09/17/14 10:48 PM (10 years ago)
Smugs code works just fine.
 

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.