I'm trying to design an app with the width of the separatorInset being short. I can achieve that but the label in the cell gets short also.
tableView.separatorInset = UIEdgeInsets(top: 0, left: 205, bottom: 0, right: 10)
Is it possble to target the actual separatorInset only and not to width of the row? The label should not be affected. I only need to shorten the separator.
Result expected:
Your best bet is to use custom cells and to have a UIView with 1px height as separator.
Related
What's the proper way to set left an right margins for a tableviewcell within a tableview?
Here's an image of what Im going for:
And here's what I actually have:
I can get the spacing on the left, but not on the right. I've set the contentInsent to this:
self.tableView.contentInset = UIEdgeInsets(top: 0, left: 16, bottom: 0, right: 16)
but it's not working either. Instead it's allowing a horizontal scroll on the tableview.
If I wanted to achieve the interface you're showing, this would have nothing to do with the table view insets. I would draw the cells to have that appearance. This would be a matter of the cell's background view. Each cell would fill the space, as intended, but the cell would draw an inner rounded rect within itself.
I have a UITableView where the last cell is cut off behind the UITabBarController. I set the bottom constraint of the tableView to the top of my bottomLayoutGuide. I also tried this approach without success.
The only solution that worked was adding insets to the content (one point was enough):
tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 1, right: 0)
Therefore I wonder if that's a normal behaviour or a scroll view bug.
I need to have a button that looks like this:
Right now I went for a view with two buttons inside it. But the problem with that is that I can either hook up the two individual buttons to the same outlet, or add a UITapGestureRecognizer to the container view.
I went with the second option because I thought it would be cleaner, but that only works when I disable the buttons (and therefore disable the press-down animation).
Am I on the right track, and should I just find a way to trigger the button's animation when the UITapGestureRecognizer calls my method? Or is there a better way to do this?
You want to use a single UIButton and adjust the imageEdgeInsets & titleEdgeInsets.
For a Swift example:
extension UIButton {
func centerTextAndImage(spacing: CGFloat) {
let insetAmount = spacing / 2
imageEdgeInsets = UIEdgeInsets(top: 0, left: -insetAmount, bottom: 0, right: insetAmount)
titleEdgeInsets = UIEdgeInsets(top: 0, left: insetAmount, bottom: 0, right: -insetAmount)
contentEdgeInsets = UIEdgeInsets(top: 0, left: insetAmount, bottom: 0, right: insetAmount)
}
}
The size inspector tab for UIButton has an Insets section at the top. Play around with the insets values of title insets and image insets to achieve the desired result.
And you don't need to use multiple buttons in a view or tap gesture to achieve this. Just 1 single button would suffice.
I want to set offset offset for the first element of collectionView, so the first cell will apear in the center of the collectionView.
Put this in your ViewDidLoad:
yourCollectionView.contentInset = UIEdgeInsets(top: 0, left: yourCollectionView.frame.width/2, bottom: 0, right: 0)
I hope this helps
I did it with UIEdgeInsets. It can be set either in interface builder or in code by setting sectionInsets property of UICollectionViewFlowLayout
How to change spacing between the navigation bar and the first collectionViewCell?
I want to be aligned in the middle. In this case, the only way to calculate the screen size?
If you want to add space at the top of your collection view you can use contentInset. There are probably other ways to meet your requirement but this is the easiest way I can think of.
collectionView.contentInset = UIEdgeInsets(top: 100, left: 0, bottom: 0, right: 0)
I don't understand what you are trying to do. Can you explain more?