Better way to display dot (5*5) in UICollectionViewCell - Swift - ios

I just want to know that which is the best and better way to draw/display dot in UICollectionViewCell.
I want to display dots for image/video either that image/video is shared on Social media or not. In above image, dark blue dot indicates that the image/video is shared in Facebook and light blue dot for Twitter shared.
So my question is, which is better way to achieve that?
Add UIView on cell and fill color and cornerRadius.
Make 1x,2x,3x images and display in cell with UIImageView.
Using CAShapeLayer() and UIBezierPath().
or any other way?
Which is best and how related to memory and performance?

Subclass a UICollectionViewCell and add a UIView to it with layer.cornerRadius set as well as background colour. This approach could be implemented completely programmatically or with a xib.
Actually if you want to dynamically set the dot size you can add constraints separately for each size class.
CAShapeLayer is quite memory intensive in comparison. The image view approach also unnecessary increases file size.

Related

UIcollectionView Custom Shape Objective C

I have a UIView then I put small UIImageViews with an image but I would like to replace this with a UICollectionView. I am not sure how to make the cells go in a upside down U shape like this.
Any help would be appreciated.
This is what UICollectionView is for, however, this is an advanced subclass of UICollectionViewFlowLayout
and really not something to "ask" for a solution here on SO, however, Google and you will find some tutorials regarding custom layouts, for example.
If you have no dynamic updates or movement of the UIImageViews, and they will always be visible on the UI (not move out of the screen) you really don't need a UICollectionView for this, but rather a customized UIView with your custom UIImageViews on it.
You could do this in a XIB subclassed UIView and with AutoLayout for example. (You can still customize it to dynamically update and move of course if needed)
Sidenote:
If the UIImages loaded into the UIImageViews are big sized, they will soak your memory and you will probably run into memory problems, make sure your UIImage are thumbnails and according to the displayed UIView size.

How to add gradient background color to prototyped UITableViewCell in storyboard?

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.

iOS: Setting multiple colors of table row

Is it possible to set two colors or transparency of the portion of the cell? something like this image where you can see both dark green and light green?
I am looking for both native and Titanium Appcelerator based solution.
Thanks
It may be best to add and position a CALayer (as a sublayer) onto the existing UITableViewCell's layer and set the colours of the cell's layer and your new sublayer to your requirements.
Coding properties on your UITableViewCell.m file for convenience could also be helpful.
A useful link if you are unfamiliar with CALayers http://www.raywenderlich.com/2502/introduction-to-calayers-tutorial

iOS UITableView cell layout questions

I have a chat on a web site that looks like this.
I am now building an iPhone app for this and have some problems creating the same layout. I hope you can point me in the right direction. Is subviews or webviews the best choice?
If using UIView, UILabel and UIImage, what is the best way to make rounded corners and the little arrow. The gradient background should not scroll with the table view. What's the easiest way to calculate the hight of each message? What is the best way to async load the images over http?
If using a webview, what is the best way to populate it with data? Building string? Having a template and populate the image, username, time and message thru JavaScript? How can I resize the UITableCell and UIWebView to fit the contests?
Will a table full of UIWebView be much slower than using labels? Will I need to create it twice to return the height of the cell in heightForCellAtIndexPath and add it in cellForRowAtIndexPath?
Thanks for your help!
If you wish to see it live, visit www.aktieguiden.com
This is really a lot more than two questions, and I'll answer several of them.
I would use a table view with a resizable UIImage and a UITextView for each bubble. Use an image of the bubble in png with a transparent background, and make it resizable. Import it with UIImage's -(UIImage*)resizableImageWithCapInsets:(UIEdgeInsets)capInsets. To determine a height, UITextView has a contentSize property which will tell you the size of the view that can be scrolled. For asynchronous loading, use one of the many tutorials or frameworks for that purpose. Here is one:
http://developers.enormego.com/view/what_if_images_on_the_iphone_were_as_easy_as_html

UITableView row count like iOS Mail app

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

Resources