Skip to content

Commit

Permalink
-Font Size Enhancement Impl
Browse files Browse the repository at this point in the history
  • Loading branch information
KhubaibKhan4 committed Dec 16, 2024
1 parent 8450aa1 commit 04fbfc3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
35 changes: 35 additions & 0 deletions Notes/setting/FontSizeKey.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// FontSizeKey.swift
// Notes
//
// Created by Muhammad Khubaib Imtiaz on 16/12/2024.
//

import SwiftUICore

struct FontSizeKey: EnvironmentKey {
static let defaultValue: CGFloat = 12
}

extension EnvironmentValues {
var fontSize: CGFloat {
get { self[FontSizeKey.self] }
set { self[FontSizeKey.self] = newValue}
}
}


struct DynamicFontModifier: ViewModifier {

@Environment(\.fontSize) var fontSize

func body(content: Content) -> some View {
content.font(.system(size: fontSize))
}
}

extension View {
func dynamicFont() -> some View {
self.modifier(DynamicFontModifier())
}
}
7 changes: 3 additions & 4 deletions Notes/setting/SettingScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import StoreKit

struct SettingScreen: View {

@State private var fontSize = 12
@AppStorage("FontSize") private var fontSize = 12
@State private var showLineNo = false
@State private var showPreview: Bool = true

Expand Down Expand Up @@ -47,9 +47,8 @@ struct SettingScreen: View {

Section("Font Size") {
HStack {
Stepper(value: $fontSize) {
Label("Font", systemImage: "textformat.size")
}
Stepper("Font #\(fontSize) ", value: $fontSize, in: 12...40, step: 1)

}
}

Expand Down

0 comments on commit 04fbfc3

Please sign in to comment.