I noticed that in iOS 7, UITableViewCells have a line break in the separator of the cell that iOS 6 does not have. Is there a way to get rid of this line break? Changing the separator to none and then making UIViews with the color of the separator still causes the white separator to occur regardless.
相关问题
- Custom UITableview cell accessibility not working
- UITableViewCell layout not updating until cell is
- Showing a checkmark accessory view move the table
- Setting the inputAccessoryView of a UITextField to
- How to put ActivityIndicator inside UIImage inside
相关文章
- UITableView dragging distance with UIRefreshContro
- Popover segue to static cell UITableView causes co
- didBeginContact:(SKPhysicsContact *)contact not in
- TransitionFromView removes previous view
- ios7 new pan gesture to go back in navigation stac
- Navigation bar disappears when typing in UISearchC
- IOS UICollectionview Dynamically change Cell's
- Inserting row and deleting row simultaneously. UIT
The selected answer did not work for me. But this yes and it works from ios 2.0:
Swift version
iOS introduces the layoutMargins property on cells AND table views.
This property isn't available in iOS 7.0 so you need to make sure you check before assigning it!
However, Apple has added a **property to your cell that will prevent it from inheriting your Table View's margin settings. This way, your cells can configure their own margins independently of the table view. Think of it as an override.
This property is called preservesSuperviewLayoutMargins, and setting it to NO can allow you to override your Table View's layoutMargin settings with your own cell's layoutMargin setting. It both saves time (you don't have to modify the Table View's settings), and is more concise. Please refer to Mike Abdullah's answer for a detailed explanation.
NOTE: this is the proper, less messy implementation, as expressed in Mike Abdullah's answer; setting your cell's preservesSuperviewLayoutMargins=NO will ensure that your Table View does not override the cell settings.
First step - Setup your cell margins:
Setting the preservesSuperviewLayoutMargins property on your cell to NO should prevent your table view from overriding your cell margins. In some cases, it seems to not function properly.
Second step - Only if all fails, you may brute-force your Table View margins:
...and there you go! This should work on iOS 8 as well as iOS 7.
Note: tested using iOS 8.1 and 7.1, in my case I only needed to use The First Step of this explanation.
The Second Step is only required if you have unpopulated cell beneath the rendered cells, ie. if the table is larger than the number of rows in the table model. Not doing the second step would result in different separator offsets.
The solution:
For iOS7:
For iOS8:
First configure your table view as follows:
Then in your cellForRowAtIndexPath: method, configure the cell as follows:
Note: Include both layoutMargins and separatorInset, to support both iOS versions
You can also set the 'Separator Inset' from the storyboard: