杂章

给UIButton设置圆角和阴影,关键点是shadowOpacity不能为0

  private lazy var <#name#>: UIButton = {
    let button = UIButton(type: .custom)
    button.layer.cornerRadius = 20
    button.layer.shadowColor = UIColor.black.cgColor
    button.layer.shadowRadius = 2
    button.layer.shadowOffset = CGSize(width: 2, height: 2)
    button.layer.shadowOpacity = 0.1
    return button
  }()

无论是UICollectionView还是UITableView要想contentInset表现的如预期那样考虑一下设置

if #available(iOS 11.0, *) {
    collectionView.contentInsetAdjustmentBehavior = .never
} else {
    automaticallyAdjustsScrollViewInsets = false
}

记一次UITableView 样式为group 设置了sectionHeader/sectionFooder卡顿 解决方法 需要设置以下属性

tableView.estimatedSectionHeaderHeight = 0
tableView.estimatedSectionFooterHeight = 0

navigationbar设置titleview 在iOS11以下尺寸正常展示

class <#name#>: UIView {
  let contentSize: CGSize

  override var intrinsicContentSize: CGSize {
    if #available(iOS 11, *) {
      return UIView.layoutFittingExpandedSize
    } else {
      return contentSize
    }
  }

  override init(frame: CGRect) {
    contentSize = frame.size
    super.init(frame: frame)
  }
  
  required init?(coder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
  }
}

你可能感兴趣的:(杂章)