我在一本学习 iOS 13 编程的书中看到了一个示例。我将程序片段放在视图控制器的视图中,但图像,一个在模糊背景上具有活力效果的标签,没有显示在控制器的视图中。
预期图像如下:
该程序的代码如下:
import UIKit
import CoreImage.CIFilterBuiltins
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
drawBlurAndVibrancyImage()
}
func drawBlurAndVibrancyImage () {
let blurEffect = UIBlurEffect(style: .systemThinMaterial)
let blurView = UIVisualEffectView(effect: blurEffect)
blurView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
self.view.addSubview(blurView)
let vibEffect = UIVibrancyEffect(blurEffect: blurEffect, style: .label)
let vibView = UIVisualEffectView(effect: vibEffect)
let lab = UILabel()
lab.text = "Hello, world!"
lab.sizeToFit()
vibView.bounds = lab.bounds
vibView.center = self.view.bounds.center
vibView.autoresizingMask = [.flexibleTopMargin, .flexibleBottomMargin, .flexibleLeftMargin, .flexibleRightMargin]
blurView.contentView.addSubview(vibView)
vibView.contentView.addSubview(lab)
}
}
非常感谢你!