Custom Toolbar With Images - iphone

I'm planning to implement a custom toolbar using my own images. Something more or less exactly like this or this. What would be required to do this. Could I just derive a control from UIView, then create another subclass to display the actual toolbar items and handle all the drawing myself in drawRect, or would it be better to make use of standard UIKit controls to handle the drawing of the images?

You can use a standard UITabBar - it is very customizable. You can set a custom backgroundImage and selectionIndicatorImage to completely change its looks. On the UITabBarItems, you can control the appearance using the finishedSelectedImage and finishedUnselectedImage properties.
Hope it helps, and good luck!

The only way to get this to work the way I wanted was to use a custom control.

Related

Change Bg Image For all UIView

I have a project and I want to provide a feature to the user that allows them to change the background settings. I would like that change to carry through on all UI screens. What is the most efficient way of accomplishing this?
Right now I am able to keep the back ground detail in NSUserDefault. When loading the view I check getBG() and apply that background in viewDidLoad(). However, I don't think this is the most efficient way.
Make a class YourView in which you implement this behavior in the way that you like. It should inherit from UIView.
Then, change all your other classes from inheriting from UIView to inheriting from YourView instead.
(At least, I believe that you should be able to do what you want that way. If not, I just don't understand you correctly...)
You can use NSNotification.
When user changes the background image to one of his choice, then
post a notification
& add observer, to change the background, where u have set the background image.

TableViewCell in IB or Programmatically, which one is better for customization?

I'm coding a custom TableViewCell and I need to set a background image for each one (actually same background image on all cells) and I'll add some labels for different type of texts (different in font, size, color, etc...) and a left image hosted on a web server. I've read a tutorial on how to make the TableViewCell using IB and add it to cellForRowAtIndePath method. It worked but the image size and texts in labels are not showing like I was seeing them in IB, not wysiwyg at all lol
So, I need your help to choose the proper way to customize these cells, should I go for the IB way or programming tips are better?
Thx in advance for helping,
Stephane
I am guessing that the size of your images is going beyond the expected size of the imageView property for the left image. That usually pushes around all the other UI elements. You can avoid that by setting imageView.layer.masksToBounds of your cell to YES.
In general, for the problem you describe, I would recommend doing everything programmatically. You will have the opportunity for abstraction and include your program logic more economically.
To keep your cellForRowAtIndexPath method reasonably short, you can call your own formatCellAtIndexPath method and keep the formatting logic neatly separated from the content.
I find it easiest to create the TableViewCell in IB to start with and then, when I have it looking the way I like it, to switch to a cell built programatically.

Approach to make a custom tabBar

What should be the best way to create a effect like this and the handling of navigation controllers and view controllers ... what to do if I don't want to re-size each subsequent view in viewcontorller and things appear as if it is a tabBar
I would recommend using an UIImageView for the blue background, then 5 UIButtons of custom type with PNG images for the actual buttons.
Subclass UIView and put all the code to set up the background and buttons in the init function. That way you can easily place your custom TabBar wherever you like.
The individual buttons also allow you to easily animate them for transitions if you want.
Update to reflect updated question:
If you want the actual UITabBar functionality, things become much more complex.
You have three basic options:
a) Implement the functionality you need from scratch in your new class
b) Subclass UITabBar and try to override the drawing code with the code above
c) Take a look at already existing alternative implementations of UITabBar and base your new class on one of them. This will probably be the easiest solution.

custom View IOS [duplicate]

It seems like more and more OS X apps these days are doing all kinds of fancy drawing stuff for custom controls. Apps like Twitterific, Things, EventBox, Versions just to name a few....
So basically I'm looking for any information on how to get started doing this kind of thing. Not sure if it is just done by subclassing controls and using custom drawing or if it is something entirely different.
Any help is greatly appreciated. THanks!
It depends entirely on what you want to do.
The "Show Raw Properties" button in Versions for instance is an NSButton subclass, because basically what we needed is standard button behavior with our own look.  One way to subclass a button is to simply implement your own -drawRect:(NSRect)rect method in the NSButton subclass, but we decided to stick with the way NSButton is implemented in Cocoa, meaning most drawing is done by the button's cell, so the implementation looks like this:
In the NSButton subclass:
+ (Class) cellClass
{
return [OurButtonCell class];
}
- (void)drawRect:(NSRect)rect
{
// first get the cell to draw inside our bounds
// then draw a focus ring if that's appropriate
}
In the NSButtonCell subclass (OurButtonCell):
- (void)drawInteriorWithFrame: (NSRect) rect inView: (NSView *) controlView
{
// a bunch of drawing code
}
The Timeline view in Versions is actually a WebView, the page that you see in it uses javascript to collapse headers you click on.
The rule of thumb I use for where to start out with a custom control is:
To customize the look of a standard Cocoa control:
subclass the appropriate control (like e.g. NSButton and NSButtonCell)
stick as close as makes sense to the way the default control is implemented (e.g. in a buttoncell, start from the existing attributedTitle instance method to draw the button title, unless you always want to draw with the same attributes regardless of what's set up in IB or if you need to draw with different attributes based on state, such as with the trial expiration button in Versions' main window)
Creating an entirely new UI element:
subclass NSView and implement pretty much all mouse and key event handling (within the view, no need to redo "hitTest:") and drawing code yourself.
To present something that's complex, of arbitrary height, but isn't a table:
See if you can do it in HTML, CSS and JS and present it in a WebView.  The web is great at laying out text, so if you can offload that responsibility to your WebView, that can be a huge savings in pain in the neck.
Recommended reading on learning how to draw stuff in your own custom view's drawing methods: Cocoa Drawing Guide
Customizing the look of for instance an NSTableView is an entirely other cup of tea, thanks to the complexity of a tableview, that can happen all over the place.  You'll be implementing your own custom cells for some things you want to do in a table, but will have to change the way rows are highlighted in a subclass of the actual NSTableView object itself.  See for instance the source code for iTableView on Matt Gemmell's site for a clear example of where to draw what.
Finally, I think Abizer's suggestion to go check out the code of BWToolkit is a great idea.  It might be a bit overwhelming at first, but if you can read and understand that code you'll have no trouble implementing your own custom views and controls.
Have a look at some excellent example code: BWToolkit

how do i fully customize a tableview

i want to customize my tableview, like the tipulator app for the iphone.
And heres my app:
Each UITableViewCell has a few subviews which you can replace with your own. They are:
UITableViewCell.imageView
UITableViewCell.contentView
UITableViewCell.backgroundView
UITableViewCell.accessoryView
As Gendolkari pointed out, Cocoa With Love has a great guide on custom UITableViews.
The theory is that you replace each of those views with an appropriate view to "skin" your UITableViewCells.
When replacing the background view, you check for the first and last cells when skinning the background view, otherwise you can use a "middle" background image. Implement it as a UIImageView. As far as the other views, use what you want.
Additionally, you can use a completely custom NIB file and load that in instead of the default styles provided by UIKit.
While the others are right in suggesting ways to subclass UITableView or its components, this screenshot doesn't look like it's showing a UITableView.
My guess is that they're just drawing custom images onto a background and checking certain areas for taps. What you should do is read up on the drawing methods as well as on intercepting taps and touches.
Here's a really good guide on custom styling for your table:
http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html
Create your own UITableViewCell, and use it, rather than a "generic" one.
You can do this directly in XCode with "File->New File" Then in "Cocoa Touch Class", choose "Objective-C Class" - and under the "Subclass" popup, select "UITableViewCell".
It well generate a XIB, which you can use in IB to customize the look.
Instantiate and pass-in there cells in your UITableView code, instead of the normal UITableViewCells.