PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, September 29, 2022

[FIXED] How to set UITableViewCell to the full width of screen?

 September 29, 2022     swift, swift3, tvos, uitableview     No comments   

Issue

Description:

As can be seen in the picture below, here is a custom UITableViewCell that is focused.

width not full

When focused I set its contentView's background color to black, like so:

//Where next is the next cell being focused.
next.contentView.backgroundColor = UIColor.black

Additionally, when I check the contentView's width via the StoryBoard it clearly says "1904" instead of the expected "1920". It's grayed out and I can not modify it.

It's clear at this point that the contentView does not take up the full width of the screen.

What I've tried:

I went through multiple different possibilities.

I first thought it was something to do with the tableView's contentInset:

//Inside my tableView controller
self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0)

Then I thought it was the tableCell's layout margin:

//Inside my custom UITableCell
self.layoutMargins = UIEdgeInsetsMake(0, 0, 0, 0)

Then I tried changing the UITableCell's contentView frame:

//Inside my custom UITableCell
self.contentView.frame = UIEdgeInsetsInsetRect(self.bounds, UIEdgeInsetsMake(0, 0, 0, 0))

I finally tried some form of self.frame and self.contentView.frame:

//In my UITableCell
self.contentView.frame = CGRect.init(x: self.bounds.maxX, y: self.bounds.maxY, width: self.bounds.width + 100, height: self.bounds.height)

Question:

How to set UITableViewCell to the full width of screen?

Screenshots:

https://i.stack.imgur.com/mAoUh.png

Image showing my tableviewcell's contentView's margins (they are the same as the tableviewcells)

https://i.stack.imgur.com/20X74.png

Image showing how I can add align constraints for my tableView.

(too big for post, reason for link)


Solution

Given you are working with a UITableViewController, you have very little control about its behavior and none about the constraints of the tableView within the controller. I suggest you switch a tableView within a UIViewController minding setting your constraints to the leading and trailing of the superview, not its margins.



Answered By - Ocunidee
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing