Many apps have a sort of visual indicator showing when you have "new activity" or "new messages". I am 'not' talking about push notifications (though they appear similar). To better illustrate this, if you use the FB app, the globe icon (notifications) display a red circle with a number which represents how many new messages you may have since you last visited.
I'm wondering how that might be done because the only thing I can think of is to place an image view or text field over the icon that will display a number representing the number of new messages a user may have.
You have to use a bit of hacking to achieve this because badges in iOS natively can only be added to the tabbar items. There is a custom class called MKNumberBadgeView, which allows you to add it to the Nav Bar.
You would do it in the following way:
MKNumberBadgeView *badge=[[MKNumberBadgeView alloc]initWithFrame:CGRectMake(92, 0, 40, 40)];
badge.value=6;
[self.navigationController.navigationBar addSubview:badge];
a few points: you will have to play around with placement of the badge on the nav bar, so adjust your cgrectmake.
I would suggest making the badge a property because eventually you will want to remove it from the view. In that case, you would call self.badge removeFromSuperview.
This class uses core graphics to draw the badge, looks really nice.
You can find more about it here:
https://www.cocoacontrols.com/controls/mknumberbadgeview
Related
I have quite a few labels and buttons on my view controller and I have an image and I have set it to the back in the layers part on the left. How ever when I make it bigger it seems to go to the front and block the images. I have tried multiple codes from other people who have the same problem, but it still doesn't work. I am using Xcode 8, Swift, iOS.
In interface builder you can change the order of what is in front or behind by changing the order of the views as they appear in the Document Outline...
The higher up the list they appear, the further towards the back they are.
I would like to add "more info" collapsible accordion into my error alert view. So it will expand with additional information about the err after user presses it. And of course it will animate the size of error alert too. How it can be done? Maybe there is already existing solution for what I need?
Thanks a lot!
The standard UIAlertView does not allow this. You'll have to make your own view that mimicks the appearance of an alert view (using a UIVisualEffectView and possibly even a UIInterpolatingMotionEffect if you really want it to look like the real thing). Takes a fair but of work, especially if you want to support older iOS versions. And of course with every new iOS version that changes the appearance of alerts, you'll have to update the code. You might be better off just going with a completely different appearance unique to your app.
Once you have made that custom view, you can add the extra field as a hidden text field. When the triangle button is pressed, you set the height of that hidden field to 0, unhide it, then animate the height of the text field and the height of the containing view to their new values.
Try this custom alert view
https://github.com/wimagguc/ios-custom-alertview
You can add whatever animation you want.
Sorry, the question isn't really clear, but basically I want a button or a label or something like that that says "notifications" and a small red square (like Facebook) that displays the number of notifications that user has (if they have any). How would I go about doing that? I'm not too advanced with UI design in iOS yet. I'm coming from an Android background so feel free to use any comparisons if there are any.
What you are referring to is called a badge. Some native controls have them (tab bar buttons come to mind), but most do not.
If you are using a tab bar controller, you can set the badge value from the UIViewController. Something like this:
[[self tabBarItem] setBadgeValue:#"1"];
If you are looking to implement a custom one, it could be easily accomplished with a UIView and a UILabel. Add a badge view to what ever view based control you are creating, then add a label to that badge view and set its text. There are probably lots of third party ones floating around the web already though.
I'm creating prototype apps and need to have a custom carrier instead of showing AT&T/Verizon or whatever actual carrier is on the phone.
I have a fake home screen which the app launches from, but want to have the custom status bar appear for it and the screens after. These are all black statusbars.
Any suggestions for the best way to do this? I created a UIViewController subclass that simply adds an image of the status bar with a label set to the current time, but this won't work if I use a nav bar.
Ideally this is done in a way where I can use the real status bar, but I can put a uiview over the carrier area with the text I'd like. This way I don't have to code in a time and battery icon.
Note that since these are prototypes, I don't need to worry about app store approval.
hide the real status bar and make one with UIView or make a image that looks like it in a UIImageView
After trying a few different ways, I stumbled upon this code that works: https://gist.github.com/guidosabatini/4066796
Haven't been able to test on a live device.
This is what I was using previously (with some modifications): http://www.cocoaintheshell.com/2010/11/custom-status-bar-ios/
i'm working on my first app and the problem a have is that the application interface design is quite customised, (even though it is a tab bar based app). now in one of the view controllers i need to present the user with the print interaction controller to print images. the thing is i don't use a navigation bar or a toolbar system or otherwise. i have managed to attach a target action method to a custom button. however, apple states that the printing interface should be presented by a system button (the one that looks like an arrow, kind of). question is: is there any way of putting a system icon inside a button that is not inside a (bar)?, or would it be ok to somehow tell the user (with an overlay or something) that tapping the button i'm using (the button is a red ribbon coming down from a picture frame) they will get the printing options?
Apple says:
Although the print button can be any
custom button, it is recommended that
you use the system item-action button
shown in Figure 6-1.
I'd interpret that to mean that you can use your own button if you want to.
You might want to consider having a toolbar at the top of the view for this particular tab. Just appearing on this tab. This would make the issue moot.
You could also, have the tool bar "slide in" and "slide out" from the top to provide access to this (and other?) actions. A single or double tap could instigate such an action.
Unfortunately, Apple doesn't expose the images for the custom bar button items in any reasonable manner. If you'd like access to them, I suggest using the bug reporter system at Apple's developer site to request that.