Setting UIButton stretched background images in Interface Builder (XCode 4) - iphone

I'm trying to set up an UIButton background using a stretchable image in Interface Builder. Button is configured as "custom" and I have assigned a background image to it. The view mode is set to "Scale to Fill", but when I set any value in "Stretching" area it doesn't seems to do anything.
I have tried doing it programmatically and it works using the UIImage's stretchableImageWithLeftCapWidth:topCapHeight: message, but its use is not recommended by Apple.
Is there any way to make it work from Interface Builder?

Unfortunately, you can't use stretchable/resizable images in the current version of Xcode 4. You have to do it programmatically.
Assuming that you are talking about iOS 5: the SDK is still under NDA for a few days, so I can't be more specific. But just as a hint:
Apple doesn't discourage the use of stretchableImageWithLeftCapWidth:topCapHeight:. If you look at the documentation (iOS 5 version) of this method again, you will find an answer there.

Related

scalable ios splash image in xamarin forms

I am working with xamarin forms and now I am seting the IOS splash image in the splash.storyboard... I followed some tutorials and I setted "W any x H any" and "generic" in the configurations required...The image appears, it is a background image. The problems is: If I select the GENERIC option, the image is too large and in the iphone it doesnt seem good...I need a Scalable Splah image, how can I do that?
I am using windows for it...but I can use a mac too.
You can add an ImageView into the ViewController instead of setting the BackgroundImage of the root view. With this, you can have the flexibility to set constraint according to your needs. You can learn more about auto layout HERE.
In addition, you can also set image with different resolution in iPhone and iPad inside your asset catalog.

How to change the background color of keypad in iOS 7

I am using Xcode 5 for developing applications. I want to change the color of keyboard in iOS 7. I want a color like black or blue.
How can I change the color of keyboard in iOS 7?
You can only set the keyboard appearance to any of three listed below using the UIKeyboardAppearance.
UIKeyboardAppearanceDefault // Corresponds to the UIKeyboardAppearanceLight
UIKeyboardAppearanceDark // Available in iOS 7.0 and later.
UIKeyboardAppearanceLight // Available in iOS 7.0 and later.
There is one more constant named UIKeyboardAppearanceAlert but, that is now deprecated. You should use UIKeyboardAppearanceDark instead.
You can't use any custom or undefined color.
So, Use ...
myTextfield.keyboardAppearance = UIKeyboardAppearanceDark;
In iOS 7, since the keyboard is translucent, I was able to accomplish this effect by adding a colored subview behind the keyboard that shows and hides with keyboard notifications.
I created a GitHub project to demonstrate this technique. Keep in mind it only works in portrait orientation right now and obviously only in iOS 7.
https://github.com/meekapps/TintedKeyboard
You can change the color with the keyboardAppearance method.
_textField.keyboardAppearance = UIKeyboardAppearanceDark;
Have a look at the Apple API docs
Per your comment of wanting a custom color:
You could do this... Just use the normal keyboard, then observe UIKeyboardWillShowNotification and UIKeyboardWillHideNotification so that you can show a color UIView behind the keyboard.
It would be hacky, but it would work because the default keyboard is transparent to a degree on iOS 7.
Good luck.

Make a iphone 3 app fit the iphone 5 4-inch screen

I have a Xcode project for a iphone app that has been designed to be universal and has a deployment target of 4.3. The project uses a .xib file for constructing the user interface and I am only familiar with storyboards. My goal is to make the app that only works on the 3.5 screen fit the iphone 5 4-inch screen. Do you guys have any tutorials online or tips on how I can do this? Thanks in advance!
The process is pretty simple:
Make sure you have a Default-568h#2x.png default image. See App Launch (Default) Images in the iOS App Programming Guide for information about these default images, sizes, etc. But by adding this default image, that informs iOS that your app supports the 4" screen.
When designing your NIBs, you can toggle the simulated metrics between 4" and 3.5" to see how the view is rendered for both:
You can then adjust your autosizing masks for your various controls so they resize correctly. This is an example where the margins are all fixed and it should grow as you go to 4" screen:
"All" you have to do is properly set the struts-and-springs "autoresizing masks" in Interface Builder. The same as you'd do for Storyboards.
A friendly tip while at it: don't do storyboards except for the simplest of apps, and don't use auto layout before you're familiar with struts-and-springs and are absolutely sure you can't use struts-and-springs to do your work.
Turn off auto layout in new .xibs here:
Of course, if you have device-specific artwork (such as a background that's exactly 960x640), you'll have to do more work than that, but you're prepared for that piece of the puzzle, right?
Next, add a Default-568h#2x.png file to your project. Make it 1136x640, or if you're not covering the status bar area, make it 1096x640.

Adjust iPhone 5 Screen Size Without Using Autolayout

Enabling Autolayout in .xib or .storyboard and adding a splash screen of 640px by 1136px enables iPhone 5 resolution support for the taller screen.
However, doing so, my app started to display some funny things where I assume autolayout is not a great idea.
I am wondering if there is a way to enable iPhone 5 device support, i.e. fix app's resolution without using Autolayout? Maybe I can set in the code?
If yes, then I will have no need to create 2 storyboards or nibs to support iOS5- and iOS6.
If you weren't using Autolayout before, you won't need to use it for iPhone 5 support.
When you're putting your interface together, you just need to check your bindings, and toggle between the taller phone size, and the regular phone size, as described here:
Xcode Storyboard displaying the new iPhone 5 screen size?
If your screens look fine in both screen sizes then you're done.
If you are doing a lot of coding to show your UI, then you'll have more work to do.
I found a great answer a couple weeks ago (link below). You will copy and paste your older iPhone Storyboard, rename it to reflect the iPhone 5, and press the button that expands the screen size, found on the bottom of the layout grid. Some minor coding adjustments might be needed, but this sample code is used in the AppDelegate to detect which device is running, and hence, which Storyboard to use. You'll just have to duplicate your interfaces, but these GUI changes can be made without code and without AutoLayout (also good to note that AutoLayout removes iOS 5--and lower--compatibility)
xcode 4.5 how to pick storyboards at launch

How does a UIStoryBoard change on iphone 5

I have an already shipped app on App Store that made use of Storyboard.
I see from the keynote, comparing to previous model that iPhone 5 has a taller screen.
I wonder how this will impact on my esisting storyboard, because from my 'app point of view' there's only one difference which is the background.png. All the rest is just plain UITableView that can just fit more rows.
I cannot find any document for this on Apple site (I have always been so noob in finding things on Apple developer site).
Has anyone made adjustment to his already developed and published app to match with new layout ?
If yes, do I have to develop a brand new storyboard, or is there an adjustment to be done with code ?
[UPDATE]
I am reporting my experience, now that Xcode 4.5 is long shipped for development.
Xcode itself, as some suggested, asked me if I would like to enable tallest screen support by creating a default png. After saying yes, I had to enter each segue in storyboard for some adjustment, change png background (which was unstrechable by design) with a tallest one, change stretching settings and redeploy.
It has been an annoying work because I have quite some segues, and Xcode doesn't allow to reuse templates within Interface Builder.
Old apps without 1136x640 resolution support will run letterboxed, with black areas on top and bottom.
You can enable new layout support for existing project simply by supplying new Default-568h#2x.png loading screen. Take heed though, you'll have to test your old interface on both old and new resolution (via iOS Simulator) to make sure everything looks good and works as designed.
Its been said when iphone 5 is launched that your app view will be filled with black color on top and bottom if it is not taking account for the increase size ( not designed for iphone5 screen)
so your app will just work fine but will have black border on both and top to filled the extra space..