var bgImage = UIImageView()
var backButton = UIButton()
var titleLabel = UILabel()
let screen_h = UIScreen.main.bounds.height
let screen_w = UIScreen.main.bounds.width
override init(frame: CGRect) {
super.init(frame: frame)
initUI()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func initUI() {
// bgImage.frame=CGRect(x:0,y:0,width:screen_w,height:64)
// bgImage.backgroundColor = UIColor(patternImage: UIImage(named:"navbar_bg")!)
// self.addSubview(bgImage)
//首先创建一个模糊效果
let blurEffect = UIBlurEffect(style: .dark)
//接着创建一个承载模糊效果的视图
let blurView = UIVisualEffectView(effect: blurEffect)
//设置模糊视图的大小(全屏)
blurView.frame.size = CGSize(width: screen_w, height: 64)
//添加模糊视图到页面view上(模糊视图下方都会有模糊效果)
blurView.alpha=0.7
self.addSubview(blurView)
backButton = UIButton(type: .custom)
backButton.frame = CGRect(x:0 , y:20, width:60, height:44)
backButton.backgroundColor = UIColor.clear
backButton.setImage(UIImage(named:"btn_Return"), for: .normal)
self.addSubview(backButton)
titleLabel.frame=CGRect(x:screen_w/2-100,y:20+44/2-8,width:200,height:18)
titleLabel.text="Old glass"
titleLabel.textColor=UIColor.white
titleLabel.textAlignment = .center
titleLabel.font = UIFont(name: "Arial", size: 16.0)
self.addSubview(titleLabel)
}
swift高斯模糊的自定义view
原创
©著作权归作者所有:来自51CTO博客作者mb62cf8bca18558的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
SpringBoot自定义starter
SpringBoot自定义starter
spring maven ci