How do you add counts inside of a UITableView UITableViewCell like the iOS Mail app?
In addition to DDBadgeViewCell (mentioned by #micpringle), there's also TDBadgedCell.
I tried out both and found TDBadgedCell to suit my needs more, as it puts the badges over the cell's text rather than under it, meaning the badges are visible even for cells with long texts.
The project also seems to be (currently, at least) more active than DDBadgeViewCell. (That being said, there seems to be a bug in the non-ARC version of TDBadgedCell.)
Create a custom UITableViewCell, position the labels where you want them (title, subtitle, count, whatever you need). I highly recommend Matt Gallaghers custom UITableView code - it takes a lot of the headaches out of dealing with custom rows. You'll have to follow Matt Gallaghers steps for customizing the cell.
To get the appearance of the count label as close as possible to your example (mail.app), you'll have to set the UILabel backgroundColor to gray (or whatever color you want it to be), textColor to white, and layer.cornerRadius to something equal to half the height of the label (if label is 20 high, cornerRadius should be 10). This will result in a UILabel with white text, gray background, round corners. Note - this isn't the most efficient method of doing this, but Apple hasn't put up the WWDC session video where they explain the performant method better (I missed that session).
The easiest solution would be to set an UILabel as accessoryView or using a custom UITableViewCell subclass which could be designed using IB.
I'd recommend creating a simple rounded UIView and a UILabel as a subview in it. I'd probably create a UITableViewCell subclass to manage the content.
Definitively the most easy way would be using a ready-to-use class like TDBadgedCell
Related
I've tried adding random labels to a UITableViewCell and the accessibility voice over system reads all of them automatically.
I'm also trying to add a UIImageView as an accesibility element and would like it to be read automatically with the cell as well. It's basically a little status icon.
I set the accessibilityLabel on the image.
I also set isAccessibilityElement to YES
Right now it treats the image as a separate object. I can select the image and or swipe left and right to read it separately instead of it being read with the cell.
Returning it in a custom accessibilityLabel getter for the cell should work too, but I'd like to use the automatic solution as much as possible. Is there some property to set on the UIImageView to have it act like a UILabel and be automatically read as well?
I think you have two options, one is a bit unclean, being create a label that is hidden with the same text and read through that.
I think the cleaner option for you is to maybe subclass ImageView and just give it a text or label property and have the accessibility voice just read over that instead.
This is end end result I want:
And this is the thing I tried initially.
This does not work, the cells below/above the cell with the background will overlap or underlap the background depending on when they are added into the tableview (like via dequeue/scrolling).
I am quite OK with this not working, and I believe I can achieve it by other means. For example by adding these backgrounds as views within the tableview itself and moving them based on the content offset or similar ways, maybe adding a background image that is tall with them embedded.
But. I am curious if there are some easier way, just adding the view into the XIB and applying a rotation would be very nice.
The background should be below the text in the other cells as well - this is where the complications comes in.
Anyway. Is this possible in some super-neat way?
What you should do is setting all cell's background to clear, and to set a background to your UITableView or your UIView.
Or, as you suggest, you can add a UIView with a rotation applied, and add it as a subview of your UIView/UITableView, and send it to back with [self.view sendSubviewToBack:backgroundView].
Is there any way to add a gradient to prototyped UITableViewCell in storyboard? To be specific, I want to allow users to add custom photos to the app and that photo will be displayed in the cell as a background. But there will be some labels above the image. So I want to add a gradient to the bottom of the cell to make labels always visible (regardless of background photo).
I know that this is possible programmatically, for example I may use CAGradientLayer like in this tutorial:
http://www.cocoawithlove.com/2009/08/adding-shadow-effects-to-uitableview.html
or this:
http://www.raywenderlich.com/32283/core-graphics-tutorial-lines-rectangles-and-gradients
But I am wondering if there is any way to do that just in storyboard.
Thanks.
As far as I know, there is no way to do this from interface builder.
Some things are just too complex to put a decent UI on it.
A neat little workaround would be to create an IBDesignable IBInspectable UIView subclass that programmatically does what you desire, than use that in your storyboary scene.
I'm playing around with UICollectionView interactive transitions.
The very basic implementation is here.
Now I'm a bit stuck with Cells transitioning.
The idea is to change content of cells simultaneously with interactive layout transition.
Here is how it looks now.
The first layout
And the second layout
When transitioning is finished, I want to change content of cells on second layout.
1) Text label "Some label" should disappear from every cells
2) Text label "Another label" should appear on the right corner of each cell.
Key issue is I want this changes fade in/out according to UICollectionViewTransitionLayout.transitionProgress value during transitioning.
Something very similar implemented in Facebook Paper App.
Take look how content of cells is changing below (click on it).
Is anybody know an elegant way to replicate this effect?
This library will help you achieve what you are trying. If you are interested in custom animations I would suggest you use FB pop library
Well.
The solution is to subclass UICollectionViewCell.
Subclass should contain two UIView. One for big layout & one for small.
Initially UICollectionViewCell shows only small one.
Once we starting to update UICollectionViewTransitionLayout.transitionProgress for example from small to big we should do following steps:
Make an UIImage from big UIView
Put this image above small UIView
Set alpha of the image to 0
Continuously change alpha of UIImage to UICollectionViewTransitionLayout.transitionProgress value
Once transition is done just switch this to UIView
When you transitioning back you should switch big with small.
Done :-)
I'm sorry about I can't upload images because of my low reputation point.
(Screenshots)
http://twitter.com/hseongeon/status/410214108881907712/photo/1
http://twitter.com/hseongeon/status/410214156785029120/photo/1
In most iOS development cases, turnaround effect appears on cells by selecting themselves.
As you can see in my screenshots, however, sometimes the effect make a view's background color and text color what I don't want to be. (like badgeView in my screenshots)
I'd like not to change my badgeView's color when cells are selected.
How to do this?
Thank you in advance.
Set the property selectionStyle on your cell to UITableViewCellSelectionStyleNone. This will prevent any calls to setSelected or setHighlighted on your cell.