Skip to content

Commit c8726ff

Browse files
author
Mithun
committed
Background Blur
1 parent f584467 commit c8726ff

File tree

5 files changed

+73
-15
lines changed

5 files changed

+73
-15
lines changed

DesignCode.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
/* Begin PBXBuildFile section */
1010
AB1D3B1C22D9CDEF00D0AEA6 /* HomeList.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB1D3B1B22D9CDEF00D0AEA6 /* HomeList.swift */; };
1111
AB62172722D870540039BC73 /* Home.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB62172622D870540039BC73 /* Home.swift */; };
12+
ABB215DC22DB353800424B38 /* BlurView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB215DB22DB353800424B38 /* BlurView.swift */; };
1213
ABE07CBF22D74F5700D209BE /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABE07CBE22D74F5700D209BE /* AppDelegate.swift */; };
1314
ABE07CC122D74F5700D209BE /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABE07CC022D74F5700D209BE /* SceneDelegate.swift */; };
1415
ABE07CC322D74F5700D209BE /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABE07CC222D74F5700D209BE /* ContentView.swift */; };
@@ -20,6 +21,7 @@
2021
/* Begin PBXFileReference section */
2122
AB1D3B1B22D9CDEF00D0AEA6 /* HomeList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeList.swift; sourceTree = "<group>"; };
2223
AB62172622D870540039BC73 /* Home.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Home.swift; sourceTree = "<group>"; };
24+
ABB215DB22DB353800424B38 /* BlurView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlurView.swift; sourceTree = "<group>"; };
2325
ABE07CBB22D74F5700D209BE /* DesignCode.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DesignCode.app; sourceTree = BUILT_PRODUCTS_DIR; };
2426
ABE07CBE22D74F5700D209BE /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
2527
ABE07CC022D74F5700D209BE /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
@@ -65,6 +67,7 @@
6567
ABE07CC222D74F5700D209BE /* ContentView.swift */,
6668
AB62172622D870540039BC73 /* Home.swift */,
6769
AB1D3B1B22D9CDEF00D0AEA6 /* HomeList.swift */,
70+
ABB215DB22DB353800424B38 /* BlurView.swift */,
6871
ABE07CC422D74F5900D209BE /* Assets.xcassets */,
6972
ABE07CC922D74F5900D209BE /* LaunchScreen.storyboard */,
7073
ABE07CCC22D74F5900D209BE /* Info.plist */,
@@ -157,6 +160,7 @@
157160
ABE07CC122D74F5700D209BE /* SceneDelegate.swift in Sources */,
158161
AB62172722D870540039BC73 /* Home.swift in Sources */,
159162
ABE07CC322D74F5700D209BE /* ContentView.swift in Sources */,
163+
ABB215DC22DB353800424B38 /* BlurView.swift in Sources */,
160164
);
161165
runOnlyForDeploymentPostprocessing = 0;
162166
};

DesignCode/BlurView.swift

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//
2+
// BlurView.swift
3+
// DesignCode
4+
//
5+
// Created by Mithun x on 7/14/19.
6+
// Copyright © 2019 Mithun. All rights reserved.
7+
//
8+
9+
import SwiftUI
10+
11+
struct BlurView: UIViewRepresentable {
12+
13+
let style: UIBlurEffect.Style
14+
15+
func makeUIView(context: UIViewRepresentableContext<BlurView>) -> UIView {
16+
let view = UIView(frame: .zero)
17+
view.backgroundColor = .clear
18+
let blurEffect = UIBlurEffect(style: style)
19+
let blurView = UIVisualEffectView(effect: blurEffect)
20+
blurView.translatesAutoresizingMaskIntoConstraints = false
21+
view.insertSubview(blurView, at: 0)
22+
NSLayoutConstraint.activate([
23+
blurView.heightAnchor.constraint(equalTo: view.heightAnchor),
24+
blurView.widthAnchor.constraint(equalTo: view.widthAnchor),
25+
])
26+
return view
27+
}
28+
29+
func updateUIView(_ uiView: UIView,
30+
context: UIViewRepresentableContext<BlurView>) {}
31+
}

DesignCode/ContentView.swift

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ struct ContentView: View {
1515

1616
var body: some View {
1717
ZStack {
18+
BlurView(style: .extraLight)
19+
1820
TitleView()
1921
.blur(radius: show ? 20 : 0)
2022
.animation(.default)

DesignCode/Home.swift

+5-1
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@ struct Home: View {
1515

1616
var body: some View {
1717
ZStack {
18+
HomeList()
19+
.blur(radius: show ? 20 : 0)
20+
.scaleEffect(showProfile ? 0.95 : 0)
21+
.animation(.default)
22+
1823
ContentView()
19-
.background(Color.white)
2024
.cornerRadius(30)
2125
.shadow(radius: 20)
2226
.animation(.fluidSpring())

DesignCode/HomeList.swift

+31-14
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,37 @@ struct HomeList: View {
1313
var courses = coursesData
1414

1515
var body: some View {
16-
ScrollView(.horizontal, showsIndicators: false) {
17-
HStack(spacing: 30.0) {
18-
ForEach(courses) { item in
19-
PresentationLink(destination: ContentView()) {
20-
CourseView(title: item.title,
21-
image: item.image,
22-
color: item.color,
23-
shadowColor: item.shadowColor)
16+
VStack {
17+
HStack {
18+
VStack(alignment: .leading) {
19+
Text("Courses")
20+
.font(.largeTitle)
21+
.fontWeight(.heavy)
22+
23+
Text("22 Courses")
24+
.color(.gray)
25+
}
26+
Spacer()
27+
}
28+
.padding(.leading, 70.0)
29+
.padding(.bottom, 40)
30+
31+
ScrollView(.horizontal, showsIndicators: false) {
32+
HStack(spacing: 30.0) {
33+
ForEach(courses) { item in
34+
PresentationLink(destination: ContentView()) {
35+
CourseView(title: item.title,
36+
image: item.image,
37+
color: item.color,
38+
shadowColor: item.shadowColor)
39+
}
2440
}
2541
}
42+
.padding(.leading, 40)
43+
Spacer()
2644
}
27-
.padding(.leading, 30)
28-
Spacer()
2945
}
46+
.padding(.top, 78)
3047
}
3148
}
3249

@@ -48,10 +65,10 @@ struct CourseView: View {
4865
var body: some View {
4966
return VStack(alignment: .leading) {
5067
Text(title)
51-
.font(/*@START_MENU_TOKEN@*/ .title/*@END_MENU_TOKEN@*/)
52-
.fontWeight(/*@START_MENU_TOKEN@*/ .bold/*@END_MENU_TOKEN@*/)
68+
.font(.title)
69+
.fontWeight(.bold)
5370
.color(.white)
54-
.padding(20)
71+
.padding(30)
5572
.lineLimit(4)
5673
.padding(.trailing, 50)
5774

@@ -61,7 +78,7 @@ struct CourseView: View {
6178
.resizable()
6279
.renderingMode(.original)
6380
.aspectRatio(contentMode: .fit)
64-
.frame(width: 246, height: 200)
81+
.frame(width: 246, height: 150)
6582
.padding(.bottom, 30)
6683
}
6784
.background(color)

0 commit comments

Comments
 (0)