我有一个自定义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格式,中间使用灵活的空格。
我有一个UICollectionViewCell具有UICollectionView带UICollectionViewFlowLayout内。我将单元格作为集合视图的委托和数据源。我正在遵循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) 如何在三元运算符中使用OR?这是我正在尝试做的事情:
let surname = name == "John" || "Jack" ? "Johnson" : "Smith"
使用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)
这个问题是关于避免编码,而不是添加编码作为作为重复状态链接的问题。