TableView Row with a badge number - iphone

How can I add a badge icon to a row in a table view?
An example of this would be the mail app in iOS where the inbox row has a badge icon showing you the number of unread messages?
Thanks!

TDBadgedCell is a good solution for this requirement.

You will have to create it yourself as there are no template cells for this. Luckily its very simple, create a custom cell with a styled label for the number and update it in cellForRowAtIndexPath: based on the information in your model object.

Either create a custom tableViewCell with a UILabel as a subview in it, or add the UILabel to a cell's contentView.
I would recommend creating your own (custom) tableViewCell though.
To get the badge shape for your label, you can play with 'cornerRadius' to get a round shape, and set the backgroundColor, textColor and borderWidth, and borderColor.
Once you get the unreadCount, just assign it to your customCell's badgeLabel's text property.
Simple as that !

Related

How can I change the width of the uiview depending on the length of label (string) in tableview cell?

I am trying to create a chat app like Messenger and Line.
In chat app, the length of colored background views behind messages changes depending on that of messages.
How can I achieve this?
This is xib file to display in tableview cell.
https://imgur.com/a/nYodX
intrinsicContentSize property of UILabel will have its preferred size based on its content.
Use the UIView method sizeToFit(). For UILabel, this sizes the label to fit it's text.

UITableView create a badge on the right of every cell

I want to create a table view like this one with a badge on the right. Can someone suggest me how can I do to get this result?
thanks
I'm using greate open source project TDBadgedCell from Tim Davies for that purposes. It is very simple to use and configure.
Get it here: https://github.com/tmdvs/TDBadgedCell
AFAIK, this is not available by default. You have to customize your cell.
Create a UILabel.
Set textAlignment as UITextAlignmentCenter.
Change its cornerRadius.
Add a drop shadow using shadowColor, shadowOffset(a positive offest) ,etc.,
Set label's text.
Resize label's width to fit the text.
Set it as cell's accessoryView.

editable cell in tableview

I am trying to implement editable cell in tableview, just like what is available in new contact screen in iphone and ipod
Right now I have two labels in a cell, one of which will remain same all the time and the other one will be editable. Do I need to change this label to textfield.
one more thing I also want that when i click one such cell it should pop a picker view and and set the picerview value.
#Umang in order to make your UITableView cells editable I suggest you to give UITextField to your cell....for more help how to do it take help from already asked How to make tableviewcell text editable on touch in iPhone SDK?
Yes you should add a UITextField to the cell if you want to editable. but
from your question i understand that you want to set a piker value to the cell label.
in this case you don't need to change the cell.
you should add the pop the picker in the didSelectRow method, and change the cell label to its result.
if you dont know how just ask and i will try to help.
Yeah, you will need to change it to a textfield. UILabel is non-editable by design.

How do I hide the UITableViewCell border for a custom cell in a group tableview?

What I am trying to do: I want three buttons side-by-side in a tableviewcell just like in Contacts app.
What I've done: I have a custom tableviewcell with three uibuttons in it. I've set the background color of the tableviewcell to be transparent.
What I can't figure out: The tableviewcell border is still there! Everything looks great except for the border floating around the 3 buttons.
Am I doing this completely wrong? Or is there a simple way to remove/hide the border?
Thanks!!!
Don't put these in a cell. Simply create a custom UIView that contains the three buttons, and use that view as your Table's footer:
[myTableView setTableFooterView:customUIViewWithButtons];
Good luck!
What about if I want my transparent cell in the middle?

Creating UITableViewCell with add photo button like in Contacts app

When you add a new contact, the first row contains the add photo button and the x co-ordinate of start of the cell is set to some value which is greater than the rest of the cells. How can this photo button be added and the cell frame can be changed?
Thanks!
They use a custom cell to achieve this. This custom cell has the picture-like control on the left and mimics a table cell next to it. It's not something that comes out of the box.
You can't set the x co-ordinate of a cell either, you can set the indentation on the other hand.
Edit: come to think about it, they probably use a custom table header instead of a custom cell. You certainly will find the headerfooter sample on developer.apple.com helpful.
Link: https://developer.apple.com/library/archive/samplecode/HeaderFooter/Introduction/Intro.html
I am more inclined to believe that they use tableHeaderView property.
Sure you can achieve the effect with custom cell.
But with header its pretty simple! I have done the same in few places!