szu*_*rse 2 swift ios8 uiblureffect uivibrancyeffect
我有一个工作的ViewController与工作UIBlurEffect.这是我的代码:
@IBOutlet weak var nameLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
let blurEffect = UIBlurEffect(style: .Light)
let blurView = UIVisualEffectView(effect: blurEffect)
blurView.frame = self.view.frame
blurView.setTranslatesAutoresizingMaskIntoConstraints(false)
self.view.insertSubview(blurView, atIndex: 0)
}
Run Code Online (Sandbox Code Playgroud)
现在我想在nameLabel中添加一个UIVibranyEffect.如何以编程方式将UIVibrancyEffect添加到现有的UILabel?
您需要实例化一个UIVisualEffectView并在其中添加您想要充满活力的任何内容.例如:
// Blur Effect
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.Dark)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = view.bounds
view.addSubview(blurEffectView)
// Vibrancy Effect
let vibrancyEffect = UIVibrancyEffect(forBlurEffect: blurEffect)
let vibrancyEffectView = UIVisualEffectView(effect: vibrancyEffect)
vibrancyEffectView.frame = view.bounds
// Label for vibrant text
let vibrantLabel = UILabel()
vibrantLabel.text = "Vibrant"
// Add label to the vibrancy view
vibrancyEffectView.contentView.addSubview(vibrantLabel)
// Add the vibrancy view to the blur view
blurEffectView.contentView.addSubview(vibrancyEffectView)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5087 次 |
| 最近记录: |