Button's background on ios7 is squeezed, ios6 ok - iphone

I just updated to XCode 5. Buttons in my app look OK in IB and on iOS 6 device, but on iOS 7 device they look like this (they should cover the whole black space):
I have images for both non-retina/retina.
I have no idea what to do, because I didn't change anything in code or IB.
EDIT:
Now I found out, if I change type of button from custom to system and set its background instead of its image, I get the correct size but I get some strange shadow over it.
EDIT2:
Now I set button's tint color to "clear color" and everything seems ok (shadow disappeared). Still not sure what has changed in iOS 7 related to this.

The Human Interface Guidelines specifically outline how system-style UIButtons work by default. It explains that a system button:
Has no border or background appearance by default ...
Supports custom decoration, such as a border or background image (to
add a custom appearance, use a button of type UIButtonTypeCustom and
supply a custom background image).
However the UIButton HIG page provides a little more information, specifically:
If you do not explicitly set a tint color, the button will inherit its superview’s tint color.
This explains why, after changing your button to UIButtonTypeSystem, you suddenly have to reset (remove) the tint colour. In iOS7, (almost) everything has a tint colour. A UIButtonTypeSystem is more appropriate for your needs now in iOS7 (a bit of a pain if there's a lot to manually change though...)
As to why the buttons shrink in iOS7... I agree with #Joseph's comment regarding UIViewController view frames in iOS7. Likely you have some set relation for the size of the buttons that does not play nicely when the ViewController's frame changes in iOS7 (see this SO question for discussion). As advised there, check out the iOS7 transition guide to see if anything you're doing in IB is going against the new iOS7-grain.

[button setBackgroundColor:[UIColor colorWithRed:(255.0/255.0) green:(180.0/255.0)];.
This is the right code for background, and if you are use image then use
[UIImage imageNamed:#".png"];

Related

MKMapview Affecting UINavigationBar and TabBar Appearance

I have a MKMapView in a UIView. Never any issues until iOS7. My colors for UITabbar and UINavigationBars are set by UIAppearance Protocol.
For some reason whenever the MKMapView is initiated, all my tabbars and navbars reset, ignoring the barTintColor setting of my appearance class. All other settings from UIAppearance seem to remain such as title attributes and barItem attributes. Only barTintColor goes out.
One more thing. This only happens on iPhone 4 and iPhone4S, not on iPhone 5. It does not happen on the simulator either. Was not an issue in iOS6 at all.
I can find no other cause for the reset. I went through and commented out just about all the goings on and it had no effect either way.
If I delete the MKMapView control, no reset of colors. If I then go on to present another, altogether different view with an MKMapView, again the colors reset.
I am looking for ideas of what else to check, what kind of settings or methods could possibly cause this behavior. Give me some stuff to eliminate, I am stuck.
Additional Info:
Now thinking this may be a bug. I put a line to hard code the color of the navbar to an arbitrary color in ViewDidLoad just to see what is going on.
UINavigationBar *bar = self.navigationController.navigationBar;
[bar setBarTintColor = [UIColor GreenColor];
I put a break on the next line. Inspecting bar, the color seems to be set.
On iPhone4 or 4S, bar does not turn green. On iPhone5 and simulator, bar turns green.
Some more items I have discovered. The color is not changing. It appears the visibility is. Yet, reading the alpha of the color and of the bar returns 1.0 both.
So color is correct.
Translucency is yes.
Alpha is 1.0.
And yet the bar is completely clear, no color, no tint.
I think I will file this officially as a bug. I made a test viewController with only a MKMapview. No code, no delegate, no annotations. Presented that in place of my proper controller. The same thing happened.
What I need right now is a workaround. I just cannot tell what is changing. When I inspect the properties of the navigation bar, everything is correct. Tint color, translucency, bar Tint Color, alpha value. So far as I can tell, the thing should be displaying as intended.
Can anyone tell me other properties or methods that could make the background of the navigation bar completely transparent?
After some more searching I see that there are some related threads in the developer forums and this issue has been noted for some time. I expect I will receive response that my bug report is a dupe. In the meantime, I believe I have come up with a workaround.
What I came up with is a sequence of setting
self.navigationController.navigationBar.translucent = NO;
self.tabBarController.tabBar.translucent = NO;
when the view containing a MKMapView is loaded and then setting it YES in viewDidAppear. I set to NO again on viewWillDisappear. Then the returning viewController must reset to translucent again in its viewDidAppear.
I used a series of NSNotification posts in the View Controllers with the maps. I subclassed my navigation controllers and tab bar to make them listen for the notification and respond by toggling their own bar translucency property.
Managed to get it done. With a small amount of code, but it is an awful lot of activity for no good reason. Would more like to see this fixed ASAP.

UISearchBar background fading in and out when segue push animates

I created two views that has its transition controlled by a navigation view controller. I have a UIView which contain a UISearchBar. The UIView is then set as the navigation bar's titleView in the first view.
Now, the problem is, whenever I go from the first view to the second view, I can see a light background behind the UISearchBar fading in and out.
I have did a bit of troubleshooting of my own and found that the background belongs to the UISearchBar and not the UIView that contains it. I have also tried many codes to make the UISearchBar background transparent, but none of the codes actually makes it transparent.
Edit: I did a bit more fiddling and found that the colour fading in and out is the colour from the style/tint of the UISearchBar. So if I change the tint to black, it'll darken instead. The only way I see I can fix this is to turn the background of the UISearchBar's alpha to 0, but I can't find any code that can change the alpha of a UISearchBar in a UINavigationBar.
Edit: I really can't find any code to turn the background tint of the UISearchBar to be alpha 0. Does anyone have a workaround or an alternative solution to this?
I realised that the bar is actually the scope bar's background. I'm not sure why it still showed up even though I disabled it. My solution was to set the background image as a transparent image.
[self.searchBar setScopeBarBackgroundImage:[UIImage imageNamed:#"transpixel.png"]];

Black Opaque UIToolbar and UISearchBar look too much different

I need to show different "titlebar" for application, depending on situation. The problem with iOS4 is that black opaque UIToolbar looks so much different that black opaque UISearchBar. Have I messed up some settings or is there some work-arounds to make UIToolbar and UISearchBar use more similar coloring?
These are overlapping in real application, just wanted to show both at the same time. Usually UISearchBar covers left half of UIToolbar, so that only UISegmentedControl is visible...
You could try changing the barStyle to UIBarStyleDefault and changing the tintColor property on both; though it doesn't look like a color issue from the picture. iOS3 introduced a UIBarStyleBlack along with the UIBarStyleOpaque - might look to see if that is being set anywhere in code instead of IB.
Just for the records, this is the solution I used:
How to Control UISearchBar Background Color
http://jomnius.blogspot.com/2010/10/how-to-control-uisearchbar-background.html
It's a bit fragile code, but worked just fine in one released application.

Annoying white border when rotating a view in iPad

When rotating a View from UIInterfaceOrientationPortrait to UIInterfaceOrientationPortraitUpsideDown on the iPad simulator, there is a white border along one side of the view (see diagram, lower left of the image). The white border shows only on one side, but not the opposite side. How can I prevent (hide) it? Thanks!
This is a guess:
It's possible that one of your views has a backgroundColor set to white, and it is completely covered by another view. During a rotation, perhaps floating point errors cause one border to show slightly through that edge.
To investigate this case, you can use the undocumented method [UIView recursiveDescription] to get a quick look at your view hierarchy (no need to submit code with that method, it's just for debugging). Once you know which views are near the bottom, you can print out their backgroundColors, or just set them all to [UIColor clearColor].
Also, I'm guessing you already know this one, but it can be useful to set window.backgroundColor = [UIColor clearColor] at the start of your code!
I had the same issue. I saw that in Interface builder autosizing for the view could not be enabled. I deleted the .xib and re-created it making sure product was set to "ipad" when creating the file (add new file in xcode).
You can also set the background color to nil. From the UIView documentation for backgroundColor:
The default value is nil, which results in a transparent background
color.
UIWindow inherits from UIView, so this works as well. Probably a good idea to use nil, in case [UIColor clearColor] isn't always the best way to do it.
The funny thing is, I have a project with no nibs, so I create the UIWindow in code, but the background color was white before I set it to nil. is the default background color of a programmatically created UIWindow white?

UIButton Background Images appear lighter in Simulator than in IB

Just put a background image on a button. The looks fine in IB but when I build and run the project in Simulator the bg is noticeably lighter. Anyone know why could be?
Thanks!
It might be the case that the alpha value for your view or one of its superviews in less than 100% (value 1.0). I've seen cases where a superview had low alpha, but the subviews appeared solid in Interface Builder, while of course they were transparent or translucent when I actually ran the app.