Add image to lower bar - iphone

How to add image to lower bar in tab based application
I can get the
self.navigationitem
but how to access the lower toolbar anda add background image to it
best regards

What you're looking for is a UITabBarITem that you can obtain from the items property of a UITabBar, or more easily from the tabBarItem property of your UIViewController.
Then I guess you can set your image using image property...
In conclusion :
self.tabBarItem.image = [UIImage imageNamed:#"myBeautifulImage.png"];
might be what you're looking for (self being, ofc, your UIViewController)...
EDIT: but if your "lower bar in tab based application" is a UIToolbar (/me :grins:..) then what you are looking for is a standard UIBarButtonItem that can be obtained from UIToolbar.items property OR some IBOutlet property if you wired it using Interface Builder.
In any case, I guess looking at Apple sample codes might be a good idea.

Related

UISegmentedControl with badge number

Just like the tabbar, I want to show badge on UISegmentedControl. As I cant see any predefined methods for UISegmentedControl just like available for UITabBar.
I thought about adding the badge as an image just on top of it, but maybe there is some better way.
Here is a little third party library I've used to draw badges on various things. It's pretty nice. For example, changing the color of the badge to match my design was trivial.
Once you bring this class into your project and include it into your view controller, you go:
CustomBadge *customBadge1 = [CustomBadge customBadgeWithString:#"Badge 1"];
...and then add customBadge1 as a subview of whatever thing you're badging.
I had this problem today, so I've put together a UISegmentedControl subclass which allows you to easily set badge numbers on each of the segments.
Using it's as easy as:
[segmentedControl setBadgeNumber:1 forSegmentAtIndex:0];
Screenshot, documentation and source code are at https://github.com/dave-thompson/MESegmentedControl .
There is no badge property or method - unlike the tab bar. If you want to do this you will just have to put a custom image over it. You could subclass the segmented control and create a function that does this for you.

Subclassing UINavigationBar in Xcode

I want to apply a custom alpha value to the title of the UINavigationBar. The UINavigationBar is part of the UINavigationController and the UINavigationController is part of a UITabBarController.
Edit: Here is a picture of what I created using a UIToolbar and a UILabel. I want to do the same using the title in the UINavigationController: http://i.stack.imgur.com/B8YX0.png
I think the only way to accomplish this would be to subclass the UINavigationBar and override a method that allows me to set the Alpha when it's drawn.
Here are my questions:
Is this the correct way to do this?
What are the HIG ramifications of this?
I am new to subclassing in Objective-C, can you provide a guide or
tutorial that will help me grasp the steps required in subclassing a
UI Element and implementing a change?
When I get the subclass configured, I can view it in IB by changing
the class of the UINavigationBar to my custom class, correct?
Are there any "gotchas" that can come up with sublassing that an
expert like yourself can give me a head's up on?
This is something you shouldn't do. Why would you want to change that color but not the overall opacity of the bar? it decreases readability. There are multiple problems:
there is no public API, so it's not trivial
tampering with the subviews is fragile, may break and may have side-effects
it's not foreseen to be done -- the alpha value of the view is used and animated when pushing/popping a controller
If you really want to do it, there's only one clean, public way: Give each navigation item to be pushed a custom title view. You can tamper with that one as much as you want. So it's possible to set a view with a UILabel as subview and having it's alpha set to 0.5.
When a navigation bar is being managed by a navigation controller, there are only a few properties you're allowed to change (see docs). One of them is translucent which adjusts the alpha, but only to an Apple-determined value.

Three20 library - subclass of TTPhotoViewController has an opaque navigation bar

I am using a TTPhotoViewController subclass from the Three20 library for showing images from a web location. The images load up fine but the navigation bar and toolbar show up with the default tint. I am using a nav bar with a custom tint (set in the MainWindow.xib)
I tried these things to get it to show black translucent bars but none of these seem to work.
setting the navigation bar style to black translucent in MainWindow.xib
setting the navigation bar style to black opaque in MainWindow.xib
Explicitly setting the navigationbar style to black translucent in the subclass's viewWillAppear:
Can someone please tell me why this would happen and how I can solve this? Thanks.
EDIT: I'm an idiot. You're trying to set the style, not the color. The below is all valid information, but what you almost certainly want is the navigationBarStyle property defined by TTViewController. Sorry.
Three20 has a "style sheet" mechanism built into it, the intended purpose of which is to save you from having to set tint colors, fonts, etc. on all of the many UI objects in your app, over and over. However, if you don't know it's there, you end up in exactly this situation. What you need to do is:
Create a subclass of TTDefaultStyleSheet in your application, and override at least this method:
- (UIColor*)navigationBarTintColor {
return RGBCOLOR(119, 140, 168);
}
Someplace in your app (probably applicationDidFinishLaunching:), call:
[TTStyleSheet setGlobalStyleSheet:
[[[YourStyleSheetClass alloc] init] autorelease]];
(You might want to browse around in TTDefaultStyleSheet.h, because there are a whole pile of other styles defined there that are used by the framework, and that you might also want to override.)

Possible to create UITabBarController w/ Custom Images, Pressed/NotPressed?

I want to add a little flair to my application and while I have been somewhat successful, I haven't figured out a way to truly do what I want to do. I would try to subclass UITabViewController, but I don't think I would even know where to start or if that is the right approach.
Basically, what I want to do is have custom images for each tab bar button. I have both pressed and non-pressed images. Instead of using the highlight that is generated over the current icon, I want the pressed image to be shown. What I've been able to do is create a Category of the UITabBar with a custom drawRect method that basically draws all of my custom tab bar icons. I then initialize the same amount of UITabBarItems w/out specifying an image or title of any kind which I then add to the array of items. This lets me have my icons and then just overlays the highlight on them.
This is ok I guess, but I would really like to have the pressed button look.
Here is the code I use for drawing the tab bar:
#implementation UITabBar (CustomImage)
-(void)drawRect:(CGRect)rect
{
UIImage *image = [UIImage imageNamed:#"TabBar.png"];
[image drawInRect:CGRectMake(0,0,320,50)];
}
#end
And then I initialize the tab bar items like this:
UITabBarItem *homeTabBarItem = [[UITabBarItem alloc] init];
If anyone knows how I would do this, that would be greatly appreciated. Please keep in mind that I'm still relatively new to Objective-C, so I'm somewhat confused as to how I would correctly subclass anything at this point.
The functionality I'm looking for would be similar to what RougeSheep was able to accomplish with Postage: http://postage.roguesheep.com/ They did an awesome job, and this is kind of what I'd like to emulate.

iPhone: how to reduce UIBarButtonItemWidth?

I've created a UIBarButtonItem and then set self.navigationItem.rightBarButtonItem to the item.
However, setting the width property of the barButtonItem doesn't seem to have any effect on the width of the button (I'm trying to reduce the width of the barButton)
If I use a custom view for the UIBarButtonItem, I'm able to set the width of the view (and that in turn sets the width of the barButton)
However, I want to get the look and feel of the standard UIBarButtonItem.
Does anyone know how to reduce the width of the UIBarButtonItem without using a custom view ?
(alternately, does anyone know how to create a UIView or UIButton that looks like a UIBarButtonItem)
Looks like Apple really don't want it (Human Interface Guidelines). However there is a somewhat static solution if you use your own view for it:
Just use images instead... use grab to copy the images from IB at the widths you want.
Then they'll look exactly like the UIBarButtons
Apple shows you how to map two different images (and in this example functions as well) to the same button depending on the state... check out the "Add Music" sample code: http://developer.apple.com/iphone/library/samplecode/AddMusic/index.html
This is from TechGuru # http://discussions.apple.com/thread.jspa?messageID=9822548