小编nam*_*tee的帖子

自定义UIToolbar太靠近iPhone X上的主页指示器

我有一个自定义UIToolbar的选项卡栏隐藏时显示的自定义。工具栏按钮太靠近iPhone X上的主页指示器:

let toolbar = UIToolbar()
let height = tabBarController?.tabBar.frame.height
toolbar.frame = CGRect(x: 0, y: view.bounds.height - height, width: view.bounds.width, height: height)
toolbar.autoresizingMask = [.flexibleWidth, .flexibleTopMargin]
view.addSubview(toolbar)
Run Code Online (Sandbox Code Playgroud)

按钮离主页指示器太近 按钮离主页指示器太近

这就是我想要的样子(邮件应用)

这就是我想要的样子(邮件应用)^

由于这是一个自定义视图,因此我知道可以更改y位置并将其移动到安全区域的底部,但是我宁愿移动按钮。我使用的是普通UIBarButtonItem格式,中间使用灵活的空格。

ios swift iphone-x

8
推荐指数
2
解决办法
3908
查看次数

尽管实现了sizeForItemAt,UICollectionViewFlowLayout单元格的大小从未改变

我有一个UICollectionViewCell具有UICollectionViewUICollectionViewFlowLayout内。我将单元格作为集合视图的委托和数据源。我正在遵循UICollectionViewDelegateFlowLayout并实现collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize(并返回正确的大小)。

但是,当我打电话时,layout.itemSize.height我得到默认的高度50。

class MyCell: UICollectionViewCell {
  fileprivate lazy var collectionView: UICollectionView = {
    let collectionView = UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout())
    collectionView.delegate = self
    collectionView.dataSource = self
    collectionView.register(SomeOtherCell.self, forCellWithReuseIdentifier: SomeOtherCell.reuseIdentifier)
    collectionView.showsHorizontalScrollIndicator = false
    collectionView.showsVerticalScrollIndicator = false
    return collectionView
  }()

  fileprivate lazy var layout: UICollectionViewFlowLayout? = {
    let layout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout
    layout?.scrollDirection = .horizontal
    layout?.sectionInset = UIEdgeInsets.zero
    return …
Run Code Online (Sandbox Code Playgroud)

ios uicollectionview uicollectionviewlayout swift

5
推荐指数
1
解决办法
1368
查看次数

在Swift三元运算符中使用OR操作数

如何在三元运算符中使用OR?这是我正在尝试做的事情:

let surname = name == "John" || "Jack" ? "Johnson" : "Smith"

ternary-operator ios swift

2
推荐指数
1
解决办法
428
查看次数

避免在 URLComponents 中对主机进行百分比编码

使用URLComponents,有没有办法避免主机的百分比编码?

var components = URLComponents()
components.scheme = "https"
components.host = "endpoint.com/v1/api.php?"
// ends up as https://endpoint.com%2Fv1%2Fapi.php%3F? but I want it to stay as https://endpoint.com/v1/api.php?
Run Code Online (Sandbox Code Playgroud)

这个问题是关于避免编码,而不是添加编码作为作为重复状态链接的问题。

ios swift nsurlcomponents

-1
推荐指数
1
解决办法
487
查看次数