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.
Related
I want to make the horizontal swipeable page like YouTube. Is there an object in XCode for this? How do I have to do it? I did not find a tutorial about it. Sorry for my English.
Like this
There are tons of components already made for this in the internet, you can try looking at the cocoacontrols site.
If you still want to write your own code for this, one way is writing a custom UIView subclass. The YouTube feature looks very simple and as far as I can guess, they can use two separate UIView subclasses: one for the menu and one for the pages, just as a container.
For the menu you can use UIStackViews or a single UIViews with UIButtons for the page's titles and another view for the selection effect that moves with the UIButton's touch event. This view should provide a delegate or any notification system that fits better to you in order to notify the container that needs to load the right UIViewController's view inside the container.
The container can be a UIView that loads the view property from the UIViewController subclass on demand. Make sure to add the loaded view controller as a child of the parent view controller, otherwise you will loose some important features.
I hope it can help you to start.
i often do not split view and controller related things correctly.
should i always subclass a uiview if i want custom uibuttons and backgrounds in my app and add style related stuff in my view or should i handle this in my controller? or probably subclass a uibutton?
what about alignings? when should i subclass a uiview, add buttons to it and align then or handle this in my controller?
thanks for your hints!
please leave some comments if something is unclear.
Should i always subclass a uiview if I want custom uibuttons and
backgrounds in my app and add style related stuff in my view
If your need are basic, you coan just insert wanted elements as subviews of your view without having to subclass anything. Buttons and views have enough properties to handle those simple needs. But everything depends on what are those needs.
Should i handle this in my controller? or probably subclass a
uibutton?
Subclassing UIButton for UIButton behaviour is not a bad idea :-) But as said before, what do you need as special behaviour ? A special image : there is a property for that. A special reaction on events, manage it into the controller on IBActions. A UIButton with UFO behaviours, ok, let's subclass it.
What about alignings? when should i subclass a uiview, add buttons to
it and align then or handle this in my controller?
Hmmm... I guess never. This can (should) be done in the controller. The controller controls the whole UIItems. So if you want to align one item regarding another, do it into the controller. If you want to align special graphics or text that is displayed into the button, sublass it and manage that in the drawRect method.
I want to make a small area to present some information in the middle of a UIToolbar and was wondering what the best way to do this is.
I need to show some text and a graphic, both of which need to be updated (around every 3 seconds) as new information arrives. The graphic is similar to the iPhone signal strength indicator, so it can be either custom drawn or selected from one of 3 graphics (low, medium, high strength).
I'll probably use initWithCustomView: to create a UIBarButtonItem, although I would like the view to be clickable (to allow the user to change the information shown).
What's the best way to make that view? Can I use a NIB, or do I need to do custom drawing in the view? What's the best way to update the buttons? I'm assuming that I'll have to remake the toolbarItems array each time and set it when the information changes. Is there a cleaner way to do this? Thanks.
Using initWithCustomView: sounds like a good way to go. You can create your custom view any way you want: with a NIB, by drawing it, even using images. It can also have its own subviews. It can be any object that inherits from UIView. (So, if you wanted, you could even make it actionable by using a UIButton, a custom UIControl, or a custom UIView with a gesture recognizer attached.)
You shouldn't have to remake toolbarItems (or, for that matter, do anything with it after you've added all your button items) if you just keep a pointer to your custom view UIBarButtonItem. It could be an instance variable. Then, to update the custom view, you could access it as you would any other view. I've never actually tried this, but I can't see any problem with doing it.
You sound like you had it mostly figured out. Hope this is helpful.
I needed the same solution and was hoping for some code examples from you. So I ended up doing it all in IB and the steps are here as follows:
Create UItoolbar in IB with no Items. (A Bar Button Item will be added again once you add the UIView)
Add UIView as subview of UIToolbar
Add UILabels to subview of UIView that is already a subview of the UIToolbar.
Create IBOutlets from UIToolbar, UIView and each UILabel and then you can reference the labels in your app.
I did set the backgrounds to clearColor so the text appears on top of UIToolbar without any box or borders.
And the text updates dynamically which was the desired outcome.
Hope this helps someone as this has been eluding me for a while.
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.
I want to add some custom buttons and realize the same effect like the iPhone's home screen. What I can think of is to calculate the position of each button and add them to the view. Are there any other ways to do this? e.g. add buttons to the tableview
Check TTLauncherView from Three20,
I realized the same view of the thumbnails in the photo app (which in principle differs only because of the background color and the rounded effect of the buttons) using a custom cell (with 4 UIButtons inside) in a normal tableview.
In my case, this is because I need to scroll up and down, in your specific case there should be a way to "lock" the table from scrolling. By the way, for this reason, it could be simpler to design the custom view in the interface builder, it is very quick to design such a view, and then create a custom controller to provide simple methods to assign icons and actions to the UIButtons dynamically.
You could also look at the Three20 libraries as already suggested, it is already implemented, but you app will easily be rejected by Apple if you do so.