How to add border to UICollectionView content? - ios

I would like to add a border to UICollectionView content so it can move with scroll and fit collection conent. Anyone has any idea how to achieve it? So far I am able to add a border to the whole collection but it is not what I'm looking for (pic).

Here, you have put a border to your collectionView.
If you wanna add a border to your cells, try this:
cell.layer.borderWidth = 1.0;
cell.layer.borderColor = UIColor.grayColor().CGColor;
Before this, make sure your cells are configured.

Related

How to wrap UICollectionView section and items with a border (shadow)?

I want to make a border/shadow around each pair of section and items of my uicollectionview.
Further I want to round the top corners of the section view and the bottom corners of the items in the last row.
Do you know how to do this? - Is it necessary to write a custom UICollectionViewLayout?
If you want to add borders & rounded corners
cellName.layer.cornerRadius = cellName.frame.width / 2
cellName.layer.borderWidth = 5
cellName.layer.borderColor = UIColor.black
and I guess
add Shadow on UIView using swift 3
will help you with the shadows also add shadows to the contentView of the cell

How to create space between 2 table view cell?

I have a TableViewCell which have the border at the surrounding.So what some space at the bottom of each cell.
Here is what I want :
I see a lot of question is work for cell which doesnt have any border.What I want is the space is outside the border at the bottom of every cell.
Now my cell is look like this
So how can I achieve the output that I stated in first picture?
It's easily accomplished with static/dynamic tableView cells & don't give the border to the cell itself but to the subview named TopView
tableViewCell
->ContentView
->TopView ---- with border height(static/dynamic)
->DownView transparent ---- height(10)
with
tableView.separatorStyle = .none

Add border to custom CollectionView

How can I add border to UICollectionView's cells which uses a custom UICollectionViewFlowLayout? When I override UICollectionView's flow layout, cell borders are "removed". how can I set borders properly?
Thank you!
I'm not sure how you want your border to look like, but whenever I need a quick border around a view, I usually use the following:
var view = UIView(frame: frame)
view.layer.borderWidth = 1
view.layer.borderColor = UIColor.blackColor().CGColor
Update Swift 3
view.layer.borderColor = UIColor.black.cgColor
You can either probably apply this to your collection view cell or create a custom class that sets these values after initialization.
Either that, or you can set the cell size so that spaces between cells serve as borders and set minimumLineSpacing and minimumInteritemSpacing in your custom flow layout implementation.

UICollectionView draw lines between the cells

Is there a way to draw lines between the cells in a UICollectionView? I'm not looking to add a border to each cell, that will result in drawing the lines only if there are any cells in the collection. What I'm looking for is something like UITableView's lines: they are there even if the table view has 0 cells.
I solved this by adding views to the collectionView.
I used the cell frames coordinates to determine where I wanted to draw.
However, there is probably a better way of doing this?
You can create a proper background for UITableView if your cells are of the same height. Draw the pattern image and apply it as a backgroundColor property:
UIImage *patternImage = [UIImage imageNamed:#"pattern.png"];
tableView.backgroundColor = [UIColor colorWithPatternImage:patternImage];
UPD:
Comment to this answer in incorrect. Background will scroll with tableView (or scrollView) content.

Changing corner radius of the cells insie a grouped UITableView

After hours of googling I am wondering if it is possible to change the corner radius of a grouped UITableView.
I tried
hoursTable.layer.cornerRadius = 5.0;
but nothing seems to change.
Make sure clip sub views of table view alon with ur code
hoursTable.layer.cornerRadius = 5.0;
by code [hoursTable setClipsToBounds:YES];
hoursTable.layer.cornerRadius = 5.0;
[hoursTable setClipsToBounds:YES];
Are you sure use <QuartzCore/QuartzCore.h> framework in your app
your method (hoursTable.layer.cornerRadius = 5.0; ) only give you rounded corners without having to add your tableview to a superView or clipping it.
also use
[hoursTable setClipsToBounds:YES];
this is work only ios 3....if you work ios 4 or ios 5x then see SO answer
I would recommend to
1) make a subclass of UITableViewCell and set the background color clear
2) make a subclass of UITableView and set the separator color clear
3) use this cells in the tableview
now here is an important method t be implemented in UITableViewCell subclass
in
- (void)drawRect:(CGRect)rect method try to make a bezier path accordingly to fill and stroke path as far your corner radius and background color...
the content rect you can get by self.contentView.frame in what you have to draw your new bezier path.

Resources