TableView Cell Separator Line Not Extending Across the Entire Cell - swift

I am working on a new project and have used a storyboard for the UI. All of my tableViews have an issue with the line separator. The picture below shows two lines. The first is a blue one which was set in the attributes inspector. The second one is black and was added with an imageView that I placed in the cell. The line does extend to the right side of the cell but not the left. Any ideas?

first set table view
1.set separatorInset of tableview instance to UIEdgeInsetsMake(0, 0, 0, 0)
second set cell
1.set preservesSuperviewLayoutMargins of cell (instance) to NO
2.set layoutMargins of cell to UIEdgeInsetsZero
3.saet separatorInset of cell to UIEdgeInsetsZero
Hope to help you

You have to make sure your cell property called preservesSuperviewLayoutMargins is set to false (default)
cell.preservesSuperviewLayoutMargins = false
Then you just have to set your cell layoutMargins to zero
cell.layoutMargins = .zero
You need also to select you cell separator, select custom and change left value from 15 to 0

Related

How can I skip the first cell in a NSCollectionView?

How can NSCollectionView items begin at the second cell and leave the first cell empty? (View Example)
Ugly easy way:
Just disable user interaction in the first cell and hide it.
view.isHidden = true
view.isUserInteractionEnabled = false
Correct way:
Register a new invisible cell class with the NSCollectionView and return in just on the first row.

Automatic height for TextView using autolayout in cell for tableView

I want to set the height of the TextView as per content in a cell for tableview.
i pinned the top of text view to the job title UILabel and bottom to the content view (parent) but it does not working. is there any tutorial for this kind of layout positioning ?
How i add constraint to fix the automatic height issue?
Current constraints
As I can see you have some other setup as well in the cell. to support dynamic height
you can give fix height constraint to UITextView.
take outlet of that constraint.
update it before you return the cell from cellForRowAt method.
so, your cellForRowAt method will end up like
tableCell.textViewHeightConstraint = textView.contentSize.height
tableCell.setNeedsUpdateConstraints()
tableCell.setNeedsLayout()
return tableCell
Solved this way.
Change the TextView to UILabel, Then set Lines property in the attribute inspector to 0.
on viewDidLoad
tableview.rowHeight = UITableView.automaticDimension
tableview.estimatedRowHeight = 229.0
It works.
More https://www.raywenderlich.com/8549-self-sizing-table-view-cells
You can apply Self-Sizing Table View Cells by adding two lines:
tableView.estimatedRowHeight = 85.0
tableView.rowHeight = UITableViewAutomaticDimension
You should read this document from Apple:
https://developer.apple.com/library/archive/documentation/UserExperience/Conceptual/AutolayoutPG/WorkingwithSelf-SizingTableViewCells.html

Swift - Custom cell width and height for textlabel and detailTextLabel

I wanna manage the long text in textlabel and detailtextlabel for the cells in UITableview because if the textlabel has a long text the detailedtextlabel truncate with "..." and viceversa.
Here's the problem:
So I wanna know if there's a way to manage the space between textlabel and detailtextlabel so there's no truncate and give them more lines. I tried with:
...
if tableData[indexPath.row].clave.count > 6 {
cell?.detailTextLabel?.numberOfLines = 5
cell?.textLabel?.numberOfLines = 5
} else {
cell?.detailTextLabel?.numberOfLines = 1
}
cell?.textLabel?.text = nueva_cadena_string
cell?.detailTextLabel?.text = tableData[indexPath.row].clave
cell?.textLabel?.textColor = UIColor.brown
cell?.textLabel?.font = UIFont.boldSystemFont(ofSize: 15.0)
cell?.textLabel?.lineBreakMode = .byWordWrapping
return cell!;
But it doesn't work very well, it seems to give them just 2 lines, not 5 and I can't change the width for the textlabel and detailtextlabel.
Try making your cell custom as this:
Try setting the tableviews row dimension to automatic
yourTableView.rowHeight = UITableViewAutomaticDimension
yourTableView.estimatedRowHeight = 80.0
try setting both textlabels number of lines either in the storyboard or in code to 0 as then they will all have the amount of lines they need.
You can subclass UITableViewCell and override the layoutSubviews() method. You will need to change the layout of textLabel and detailTextLabel there. Remember that these elements lie inside contentView, not in the cell itself.
But better you add two custom labels on the Storyboard and configure them as you want. It's easier.

Removing undesired left indent on UITableViewCell

I have a Table View within my main UIViewController that has one non-editable prototype cell. I am trying to remove the left indent from the table view cell. No matter what method I use, the indent does not go away.
Here is what I have tried:
On the Table View: In Interface Builder > Attributes Inspector, I set Separator Inset to Custom with left inset of 0.
On the Table View Cell: In Interface Builder > Attributes Inspector, I set indentation Level and Width to 0. I also changed Separator to Custom with left 0.
I also tried the following in code:
myTable.layoutMargins = UIEdgeInsets.zero
myTable.separatorInset = UIEdgeInsets.zero
And this inside of cellForRowAt:indexPath
cell.indentationLevel = 0
cell.indentationWidth = 0
cell.layoutMargins = UIEdgeInsets.zero
return cell
Here's a screenshot of what's occurring:
I need all of the "Hello's" to left-align with the red section header text.
How can I remove the left-indent of the content?
Thanks.
Have you tried using a custom cell with a label and at the required distance from the left edge?
I'm sure that layoutMargins is the reason of indent on UITableViewCell. But I think you can't change layoutMargins. I almost don't use textLabel of UITableViewCell. You can refer to Setting layoutMargins of UIView doesn't work.
Try this -
helloLabel.textAlignment = .Left
cell.addSubview(helloLabel)

Swift table view with a cell that is transparent and shows background image

I have tried to do so:
added an orange view behind a table view.
for a certain cell hide with alpha = 0 all her elements
tried to make the cell transparent so that it shows the orange view behind the table view while it scrolls:
cell2.backgroundColor = UIColor.clearColor()
cell2.backgroundView = nil
cell2.backgroundView?.backgroundColor = UIColor.clearColor()
tried to make the table view transparent so that it allows the orange view behind to be showed
tableView.backgroundColor = UIColor.clearColor()
tableView.opaque = false
tableView.backgroundView = nil
However I can not see the orange view behind the table view when I scroll and get to my cell, it just shows a grey cell.
Can somebody give me any hint to what else I should do?
Thank you
In your viewDidLoad(), add the code immediately below to set the tableView's background color.
tableView.backgroundColor = UIColor.clearColor()
In your cellForRowAtIndexPath method, use something similar to the code below to set a given cell's backgroundColor to be transparent, where the value 2 is the row of the cell you'd like to change.
switch indexPath.row {
case 2:
cell.backgroundColor = UIColor.clearColor()
default:
print("NOT Clear")
}