ios - 如何制作褪色的导航栏

标签 ios swift xcode

如何制作一个淡出的导航栏?顶部的 alpha 为 0.5,下半部分为 0。随着从上到下,alpha 减小并且变得更加透明。

是这样的:enter image description here

如您所见,随着导航栏的向下移动,它变得更加透明。

最佳答案

为此尝试使用 CAGradientLayer。我已经测试过并且可以工作。 对于Swift 3.0

let gradient: CAGradientLayer = CAGradientLayer()

// put colors into an array, from top to bottom
gradient.colors = [UIColor.black.withAlphaComponent(0.5).cgColor, UIColor.clear.cgColor]
gradient.frame = view.frame

// setting direction and stop points - from top to bottom
gradient.startPoint = CGPoint(x: 0, y: 0)
gradient.endPoint = CGPoint(x: 0, y: 0.5)

yourView.layer.insertSublayer(gradient, at: 0)

关于ios - 如何制作褪色的导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39930846/

相关文章:

ios - 在实例化之前从 XIB 文件中读取属性

swift - NSNumber 不是 UInt8 的子类型

ios - 在 ObservableObject 中导入变量

ios - 删除 UICollectionView 中的最后一个单元格会导致崩溃

ios - 为现有 sqlite 上的持久存储管理器更改 NSPersistentStoreFileProtectionKey

swift usesPreciseCollisionDetection 不起作用?

ios - 如何使用 faSTLane 将详细的测试结果发布到 slack?

iphone - iOS 上的当前系统时间

ios - 如何更改状态栏背景的颜色?

ios - 如何在 Swift 中返回带有 inout 参数且返回类型为 Void 的函数?