-2

How can I draw a simple BAR?

Like this:

simple bar

Thank you.

B. Altan Kocaoglu
  • 373
  • 1
  • 7
  • 19

2 Answers2

1

You'll want to make a UIToolbar, put it at the bottom of your XIB, and put some buttons on it. Now, this will by default give you a regular black bar, with that standard black gloss. If you want to have a custom image, there are two solutions.

First is simply subclass UIToolbar and override its drawRect to draw a custom image. The code for overriding drawRect would look something like this:

//in some other code somewhere, preferably on init
self.image = [UIImage imageNamed: @"image"];

- (void)drawRect:(CGRect)rect {
    [self.image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}

Now, in iOS 5.0 there is something very useful called appearance but you have to be willing to only target 5.x+ iOS versions.

The second, which is simpler but less versatile, is to simply stick a UIImageView at the bottom of the XIB, and place some buttons on top of it. This is much easier than above, but is less extensible, is harder to modify, and is frowned upon in iOS for good reason - it breaks general iOS conventions (and you lose some very useful functionality).

CrimsonDiego
  • 3,616
  • 1
  • 23
  • 26
1

Crimson has a nice idea but since his/her answer requires using UIToolbar, I'll offer an alternative:

Basically what you are showing there is some kind of progress bar, so ultimately whatever you want to display should be something subclassed from UIControl or even better, UIProgressView or maybe a UISlider.

Google around for custom progress view indicators or sliders. There are also good examples available here on Stackoverflow.

Community
  • 1
  • 1
Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
  • Actually, UIToolbars are just like any other UIView and can be placed anywhere, although iOS convention states that they should be at the bottom of the view that they are in. However, I just realized that while I assumed that Kronokrator was talking about the bottom bar, they may indeed have been speaking of the progress bars in the image. – CrimsonDiego May 26 '12 at 06:47
  • Ahhh, I see [that is true as of iOS 5](http://developer.apple.com/library/IOs/documentation/UIKit/Reference/UIToolbar_Class/Reference/Reference.html#//apple_ref/doc/c_ref/UIToolbarPosition) @CrimsonDiego. But I still think a subclassed UISlider or UIProgressView with some custom drawing elements would be more sensible. But let's see what Kronokrator thinks? – Michael Dautermann May 26 '12 at 06:50
  • Yes - if Kronokrator is requiring a progress bar, he definitely should subclass UIProgressView instead of UIToolbar. It depends on what type of bar he is asking about. – CrimsonDiego May 26 '12 at 06:51
  • I'm gettin data from sqlite. I will use it for cell.detailTextLabel. Like at picture. I don't need animation or any progress. – B. Altan Kocaoglu May 26 '12 at 11:28