UITabBar fully transparent - iphone

In XCode I am using the interface builder (StoryBoard) to lay out most of my layout. However I want some custom drawing on this. This works quite well.
There is however a problem what I am facing. I have a "bite" out of the active tab. (see http://cl.ly/Efno ) I want this bite fully transparent. (I have set an pink background color to see what part I want transparent which is not transparent.)
How I have changed the look and feel is the following.
Set the UITabBar class to my own class in the interface builder for the corresponding tabbar.
In the awakeFromNib of that class I have set the label position and image and selected image of each tabbar item. Like so
[tabBarItem setFinishedSelectedImage:selectedImage withFinishedUnselectedImage:image];
Each image fully covers the entire tabbar in height and has the width of the tab item itself.
Set the background image of the tabbar to none (a fully transparent image)
Set the background color of the tabbar to a fully transparent color (now I have a pink color set to see where it goes wrong)
In the interface builder uncheck "opaque" for the tabbar.
However, it is not transparent, the pink part is black. How can I make this transparent?
Thanks

Have a look at the appearance proxy for UITabBar, you might be able to do what you want there without having to use a custom subclass. There are tons of properties you can access and change. You could set the relevant properties in the app delegate. It is iOS5 only though, but I gather that you are using that already, since you mentioned storyboards.
E.g.
UIImage *tabBarBackground = [UIImage imageNamed:#"tabBarBackground.png"];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
[[UITabBar appearance] setSelectedImageTintColor:[UIColor colorWithRed:127.0/255.0 green:186.0/255.0 blue:235.0/255.0 alpha:1.0]];
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:#"tabBarItemSelected.png"]];

Related

iOS7 navigationBar and TabBar Color is behaving strangely

This is what I want. It loads on some of my view controllers.
Hi all,
I am going nuts trying to make the tint color of all of my viewControllers the same. Some appear to be much darker than others. All I want is the light color to be throughout...
Sometimes I get this ugly dark gray instead... I am not sure what I am doing incorrectly. I have checked the .m file and am not setting the tint color or anything... not sure why it wouldnt be consistent on every viewController...
Any help would be great. Thanks!
in iOS7 navigation bar is by default translucent=YES so just change to NO like bellow:-
self.navigationController.navigationBar.translucent=NO;
and set Navigaitonbar color or other property customize like Bellow put this code into Appdelegate class didFinishLaunchingWithOptions and use appearance for applying Globally:-
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
// Load resources for iOS 6.1 or earlier
[[UINavigationBar appearance]setTintColor:NavigationColor];
} else {
[[UINavigationBar appearance]setTintColor:[UIColor whiteColor]]; // it set color of bar button item text
[[UINavigationBar appearance]setBarTintColor:[UIColor GreenColor]]; // it set color of navigation
[[UINavigationBar appearance] setBarStyle:UIBarStyleDefault]; // it set Style of UINavigationBar
[[UINavigationBar appearance]setTitleTextAttributes:#{UITextAttributeTextColor : [UIColor whiteColor]}]; //It set title color of Navigation Bar
// Load resources for iOS 7 or later
}
For tabBar also same this is by default translucent=YES change to NO
[self.tabBarController.tabBar setTranslucent:NO];
A common mistake is setting the view.backgroundColor of the View Controller to clearColor (both programmatically or via Storyboard). This makes the view actually black instead (since there's nothing beneath the clear view), so everything that is above that view, that has translucent property set to YES, will show dark grey color (black color + default iOS blur).
To fix this, either set the translucent property to NO (as Nitin Gohel said), or set the view.backgroundColor to white, which's its actual default color.
Hope this still helps someone!
Since iOS 7.1 there's a bug, which causes UITabBar to not listen to Global Tint.
See this post: https://stackoverflow.com/a/22323786/1255674
You need to set the tint programmatically. Thanks, Ive ...

UINavigationBar handle rotation

I'm trying to handle the rotation of a UINavigationBar with UINavigationItem (i'm not using the UINavigationController), i have successfully made so that the height and width show according, but that does not seems to be correct, as the UINavigationBar still acts as being in portrait mode (big title and button), also when i set a custom background for both metrics, it seems to only show the portrait background metric, ignoring completely the landscape one.
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"modal-top-landscape"] forBarMetrics:UIBarMetricsLandscapePhone];
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"modal-top"] forBarMetrics:UIBarMetricsDefault];
Is there a way to tell the UINavigationBar that is rotated and should show the text and buttons accordingly?
I attach some screenshots:
One workaround for this is to use a UINavigationController, and use a CGRectOffset to remove the margin that leaves the status bar... add the Controller to the parent controller (also the view).

Change UIToolbar Shadow Color For UIBarButtonItem

I am styling a UIToolbar by changing the tint color of it and the tint color of its UIBarButtonItem subviews. I have it working except that I can't find how to change the the shadow color from a dark color to a light color for the individual bar button items (see example, bar button items look blurry):
How can I change the shadow on the UIBarButtonItem with style UIBarButtonItemStylePlain to be white? I've uploaded a sample project here.
The final solution was to add the buttons as UIButton contained in UIBarButtonItem and include any shadows in the PNG used for the UIButton image.
In the UIBarButtonItem Class Reference there isn't a single mention of the word "shadow"
You use an image for the shadow, not a UIColor
Some source code examples can be found # cocoaControls.com
For the UIBarButtonItem appearance only the 2 images and colors can be changed:
setBackgroundImage:forState:barMetrics:
Sets the background image for a given state and bar metrics.
- (void)setBackgroundImage:(UIImage *)backgroundImage forState:(UIControlState)state barMetrics:(UIBarMetrics)barMetrics
For the UIToolBar:
For adding your own custom shadow look at this StackOverflow
post
For using cocoa-predefined functions look at UIToolBar Class
Reference
setShadowImage:forToolbarPosition:
Sets the image to use for the toolbar shadow in a given position.
(void)setShadowImage:(UIImage *)shadowImage forToolbarPosition:(UIToolbarPosition)topOrBottom
shadowImageForToolbarPosition:
Returns the image to use for the toolbar shadow in a given position.
(UIImage *)shadowImageForToolbarPosition:(UIToolbarPosition)topOrBottom
I don't know what else to say, there isn't a shadow method for the UIBarButtonItem.
I hope this is self explanatory.

Alter a UIBarButtonItem view to be transparent programmatically

I've had trouble getting this to work, nowhere have I seen a working example on the web. Now offering bounty on this as its making me crazy. It should be easy, but that doesn't seem to be the case.
I'd like my buttons on my UINavigationBar to be semi-transparent such that they allow the background of whatever is on the UINavigationBar to show through. This effect is seen in many applications, image examples below. You can do this by setting a custom background on the item, which i think is an unacceptable solution because it requires that you prepare images beforehand, and they won't be adaptable for variable buttons etc. They will not look like Apple UI and I don't believe there is a reason to do this either, UIKit is already drawing the background for these buttons, we just need to change it. The correct solution uses the bar items and views generated by Apple's apis.
UIBarButtonItem is not a UIView subclass. When you create one and add it to a UINavigationBar, some code somewhere in the framework draws a view for it. The framework methods seem to resist anything related to allowing transparency of the bar items, such as the tintColor property.
For example, this does NOT work:
UINavigationItem *item = [[UINavigationItem alloc] init];
UIBarButtonItem *editButton = [[UIBarButtonItem alloc] initWithTitle:#"SUCKS" style:UIBarButtonItemStyleBordered target:self action:#selector(whatever:)];
editButton.tintColor = [UIColor colorWithWhite:0.4 alpha:0.3];
item.leftBarButtonItem = editButton;
Nothing I do will make UINavigationBar allow semi-transparency for its bar items. I believe at runtime we need to:
Get the image for the bar item
Mask it for transparency
Set the new image on the bar item
But I haven't been able to get the image at runtime or mask it properly. How do you do this?
Create a custom uiview and draw a semi-transparent black rectangle in it and use that view with initWithCustomView.
see
and
Failing that, you may have to use an image (png). e.g. a 1x1 black pixel png with 30% opacity.You could then initWithImage.
EDIT: I have had this second approach working using:
buttonThree = [[UIBarButtonItem alloc] initWithTitle:#" sort button " style:UIBarButtonItemStyleBordered target:self action:#selector(sortMethod)];
UIImage *thebgUIimage = [UIImage imageNamed:#"semi.png"];
[buttonThree setBackgroundImage:thebgUIimage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
This results in a button that has a transparent background image that the navbar background image shows through. However, you would need to create an image with the rounded corners on and so need an image for each button width. Also I found this thread after trying the above
A brilliant hack is to use the UISegmentedControl with a single segment (as a button) and set its tint color. Have a look at http://charles.lescampeurs.org/2011/02/10/tint-color-uibutton-and-uibarbuttonitem. I have personally implemented this. Feel free to ask any questions.
Instead of searching for code and breaking your head, my suggestion is just to have transparent image which has just border similar to button (add shadow if necessary), create a button of custom type, add the transparent background image to it and you can text as you want. From this custom button, create your bar button item accordingly.
If you're targeting for iOS 5, you can set the background image of the button.
[_button setBackgroundImage:#"image" forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
Note that you'll need to set background images for state UIControlSateSelected and again for both control states for barMetrics: UIBarMetricsLandscape, if your application allows landscape orientation.
Note again this is an iOS 5 feature.
I believe your answer is here: http://sebastiancelis.com/2009/12/21/adding-background-image-uinavigationbar/

Black corners on UITableView Group Style

I have a problem where my UITableView (group style) has a black "tip" above it's rounded corner.
I'm setting up the background of the tableview like so:
[meetingTableView setBackgroundColor:[[UIColor alloc] initWithPatternImage:[[UIImage alloc] initWithContentsOfFile:#"background.png"]]];
And my table view ends up looking like this:
black pointy edge on rounded corner http://papernapkin.org/pastebin/resource/images/imageEntryId/6487
Any ideas how I can get rid of those black points?
I have got the same problem.
When I set clear color by xib, I have the back corner
The solution is to set it by code !
(The same problem with interface builder exist for webviews)
Try this in your controller's viewDidLoad method:
meetingTableView.backgroundColor = [UIColor clearColor];
You'll get Black corners on UITableView Group Style if you set background color to clear color in XIB.
Instead try this code for removing Black corners on UITableView Group Style
tableViewObject.backgroundColor=[UIColor clearColor];
Just in case you weren't already aware, there's another neat technique you can use to make customized backgrounds for UITableViews:
Not quite as simple as setting the background as you're doing, but it gives you a lot more flexibility and can scale to any table size.
Maybe if you put yourTableViewOutlet.backgroundView=nil;
To avoid the black corners you have to make sure that the UITableViewCells are not opaque. It looks like you're using custom styles table cells and the default value for opaque is YES. Either go to Interface Builder and uncheck the opaque checkbox if the table cell was set up in a XIB file. Or use the setOpaque:NO setter to change value.
Because the table cell view still has a rectangular frame even with the rounded corners the cell view and not the actual table view is causing those black corners.
My guess is that it's related to something that you're doing in your custom table view cells. You might want to experiment with setting the cell background color to [UIColor clearColor].
I think you should set the background color of your table as clearColor and initialsie your view with the background image.
Then it will definitely not show the black corners. But also don't forget to set the background color of your cell as white color
The up-voted answer above (set the tableView's background to [UIColor clearColor]) may not work for you if you are like me and never use the UITableViewController, instead putting a UITableView inside a UIViewController.
In this case it's not the tableView that needs to have a clear background, but the view that holds the tableview.
This is not intuitive, but it works for me. In interface builder you can just set the parent view's background color to clear color, or you could do the same in code in viewDidLoad with:
self.view.backgroundColor = [UIColor clearColor];
I'm guessing the reason for the black corners is something about the internal graphics optimization, and setting the background clear fixes it.