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.
Related
I want to add more than 8 buttons in UIAlertView but when I am adding buttons, they are covering each other and not scrolling. The title is also hiding.
How can I resolve this and add some scrolling in the alertview ??
Seems like this kind of question comes up at least once a day on StackOverflow, but if you want to mess around with the various components within a UIAlertView, the short answer is: DON'T.
If you look at Apple's documentation for UIAlertView, within the first screenful of text it states:
Subclassing Notes
The UIAlertView class is intended to be used as-is and does not
support subclassing. The view hierarchy for this class is private and
must not be modified.
This means that there's a decent chance that any mucking around within UIAlertView hierarchy could catastrophically break your app in future iOS release.
So if you want to add scroll bars or bells & whistles, you really should create your own custom UIView (which looks like a UIAlertView, but is wholly of your own creation)
If you have more buttons then UIActionSheet is the best option than using UIAlertView. If you dont want to use UIActionSheet there is always a custom View to your rescue!
You should really rethink your UI if you need more that 8 button in a UIAlertView. 8 button is the maximum the standard alert view can handle.
Either build your own alert view or use a normal view controller with a table view.
Not sure if it's necessary but as an alternative, you can present another ViewController/ModalVC that will have all the attributes that you may require....
Just move ahead with CustomView, Otherwise not possible with UIAlertView to meet up with your requirement :
Reference links :
http://iphonedevelopment.blogspot.in/2010/05/custom-alert-views.html
http://iosdevtricks.blogspot.in/2013/04/creating-custom-alert-view-for-iphone.html
https://stackoverflow.com/a/6965828/434898
If you want to add many buttons you can use a custom implementation for the alertView.
A nice example is FUIAlertView
Or you could use WEpopover and add to it a table view.
It seems like I can't add any buttons that contain colors in a UIToolbar, they always get replaced with a white mask. How can I add a colored image to a custom button in a UIToolbar?
Yes you can, but its not really a uibarbuttonitem.
here is the link.
http://fredandrandall.com/blog/2011/03/31/how-to-change-the-color-of-a-uibarbuttonitem/
PS.
If you want to have an IBAction for that button, then call it on valuechanged event.
No, I dont think you can directly. It looks like it has to be as you said.
You might be able to hack things though by putting your image over the toolbar's image and letting the touch events pass through it by tweaking the hit testing.
Without using private API's, you can't. Apple will block your app if you use the private API's, so you might as well construct your own control and use that.
You can also look at the UIApperance protocol this is very useful for customising the look and feel of many of the UI elements. You can change a specific item or every instance of that item using the static method.
[[UIToolBar appearance] setTintColor:[UIColor blueColor]]
This would change every instance of a UIToolBar in your app blue.
You can use custom toolbar, where you can use any toolbar background and colored images: http://github.com/marichka/Custom-UIToolbar
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.
Occasionally I want to highlight one of segments of a UISegmentedControl, i.e. the third title is "News" and I want to draw user's attention to it. Ideally with a red badge with a number as on the UITabBar - any idea how to achieve this? Feel free to share other ideas as well. I thought about adding the badge as an image just on top of it, but maybe there is some better way.
I wouldn't have thought there is a better way to be honest.
The easiest way will be (probably) to subclass uisegmentedcontrol and add a badge label to it. Or something similar. (subclass uiview add a uisegmentedcontrol to it and add a badge label to it).
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