Swift UIVisualEffectViewにViewを追加する

個人開発したアプリの宣伝
目的地が設定できる手帳のような使い心地のTODOアプリを公開しています。
Todo with Location

Todo with Location

  • Yoshiko Ichikawa
  • Productivity
  • Free

スポンサードリンク

EffectViewに直接addSubviewしようとすると以下のようなエラーが出る。

let visualEffectView = UIVisualEffectView(effect:  UIBlurEffect(style: .dark))
visualEffectView.addSubview( UILabel() )
Do not add subviews directly to the visual effect view itself, instead add them to the -contentView.'

エラーの通りで直接effect viewにadd subviewしちゃダメなようで、contentViewに対してaddSubviewしてね。ということらしい。

let visualEffectView = UIVisualEffectView(effect:  UIBlurEffect(style: .dark))
visualEffectView.contentView.addSubview( UILabel() )