Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Demo/RootViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ final class RootViewController: UIViewController {
appearance.textColor = .black
appearance.font = .boldSystemFont(ofSize: 16)
appearance.textInsets = UIEdgeInsets(top: 15, left: 20, bottom: 15, right: 20)
appearance.bottomOffsetPortrait = 100
appearance.offsetPortrait = 10
appearance.toastOrientation = .top
appearance.cornerRadius = 20
appearance.maxWidthRatio = 0.7
appearance.useSafeAreaForOffset = true
}

func configureAccessibility() {
Expand Down
2 changes: 1 addition & 1 deletion DemoObjC/RootViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ - (void)configureAppearance {
appearance.textColor = UIColor.blackColor;
appearance.font = [UIFont boldSystemFontOfSize: 16];
appearance.textInsets = UIEdgeInsetsMake(15, 20, 15, 20);
appearance.bottomOffsetPortrait = 100;
appearance.offsetPortrait = 100;
appearance.cornerRadius = 20;
appearance.maxWidthRatio = 0.7;
}
Expand Down
13 changes: 13 additions & 0 deletions Sources/ToastOrientation.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// ToastOrientation.swift
// Toaster
//
// Created by Yongjun Lee on 2023/03/29.
// Copyright © 2023 Suyeol Jeon. All rights reserved.
//

import Foundation
@objc public enum ToastOrientation: Int {
case top
case bottom
}
26 changes: 18 additions & 8 deletions Sources/ToastView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ open class ToastView: UIView {
get { return self.textLabel.font }
set { self.textLabel.font = newValue }
}

@objc open dynamic var toastOrientation: ToastOrientation = .bottom

/// The bottom offset from the screen's bottom in portrait mode.
@objc open dynamic var bottomOffsetPortrait: CGFloat = {
@objc open dynamic var offsetPortrait: CGFloat = {
switch UIDevice.current.userInterfaceIdiom {
// specific values
case .phone: return 30
Expand All @@ -62,7 +64,7 @@ open class ToastView: UIView {
}()

/// The bottom offset from the screen's bottom in landscape mode.
@objc open dynamic var bottomOffsetLandscape: CGFloat = {
@objc open dynamic var offsetLandscape: CGFloat = {
switch UIDevice.current.userInterfaceIdiom {
// specific values
case .phone: return 20
Expand All @@ -81,7 +83,7 @@ open class ToastView: UIView {
/// If this value is `true` and SafeArea is available,
/// `safeAreaInsets.bottom` will be added to the `bottomOffsetPortrait` and `bottomOffsetLandscape`.
/// Default value: false
@objc open dynamic var useSafeAreaForBottomOffset: Bool = false
@objc open dynamic var useSafeAreaForOffset: Bool = false

/// The width ratio of toast view in window, specified as a value from 0.0 to 1.0.
/// Default value: 0.875
Expand Down Expand Up @@ -198,19 +200,27 @@ open class ToastView: UIView {
if orientation.isPortrait || !ToastWindow.shared.shouldRotateManually {
width = containerSize.width
height = containerSize.height
y = self.bottomOffsetPortrait
y = self.offsetPortrait
} else {
width = containerSize.height
height = containerSize.width
y = self.bottomOffsetLandscape
y = self.offsetLandscape
}
if #available(iOS 11.0, *), useSafeAreaForBottomOffset {
y += ToastWindow.shared.safeAreaInsets.bottom
if #available(iOS 11.0, *), useSafeAreaForOffset {
switch self.toastOrientation {
case .bottom:
y += ToastWindow.shared.safeAreaInsets.bottom
case .top:
y += ToastWindow.shared.safeAreaInsets.top
}
}

let backgroundViewSize = self.backgroundView.frame.size
x = (width - backgroundViewSize.width) * 0.5
y = height - (backgroundViewSize.height + y)
if self.toastOrientation == .bottom {
y = height - (backgroundViewSize.height + y)
}

self.frame = CGRect(
x: x,
y: y,
Expand Down
4 changes: 4 additions & 0 deletions Toaster.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
0397CD2D1D85D6920077D82F /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0306DB991D85D626007AE314 /* AppDelegate.swift */; };
0397CD2E1D85D6930077D82F /* RootViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0306DB9E1D85D626007AE314 /* RootViewController.swift */; };
03C23F3C1D8823AA00EE8424 /* Toaster.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 03A75E2B1BCF2066002E46C4 /* Toaster.framework */; };
18C31E1E29D416C300E663E3 /* ToastOrientation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 18C31E1D29D416C300E663E3 /* ToastOrientation.swift */; };
3706852A20D6A68800F09B36 /* Toaster.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 03A75E2B1BCF2066002E46C4 /* Toaster.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
3719A72C225598E4009EAFCD /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 3719A72B225598E4009EAFCD /* AppDelegate.m */; };
3719A72F225598E4009EAFCD /* RootViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3719A72E225598E4009EAFCD /* RootViewController.m */; };
Expand Down Expand Up @@ -94,6 +95,7 @@
0306DBB01D85D62E007AE314 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
03A75E2B1BCF2066002E46C4 /* Toaster.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Toaster.framework; sourceTree = BUILT_PRODUCTS_DIR; };
03A75E4F1BCF20D4002E46C4 /* ToasterDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ToasterDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
18C31E1D29D416C300E663E3 /* ToastOrientation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToastOrientation.swift; sourceTree = "<group>"; };
3719A728225598E4009EAFCD /* ToasterDemoObjC.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ToasterDemoObjC.app; sourceTree = BUILT_PRODUCTS_DIR; };
3719A72A225598E4009EAFCD /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
3719A72B225598E4009EAFCD /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -167,6 +169,7 @@
0306DBA91D85D62A007AE314 /* ToastWindow.swift */,
C1C0178C23163F4F00446CED /* KeyboardObserver.swift */,
C1C017912316419900446CED /* UIApplication+Load.swift */,
18C31E1D29D416C300E663E3 /* ToastOrientation.swift */,
);
path = Sources;
sourceTree = "<group>";
Expand Down Expand Up @@ -404,6 +407,7 @@
buildActionMask = 2147483647;
files = (
0306DBAC1D85D62A007AE314 /* ToastCenter.swift in Sources */,
18C31E1E29D416C300E663E3 /* ToastOrientation.swift in Sources */,
0306DBAE1D85D62A007AE314 /* ToastWindow.swift in Sources */,
C1C017922316419900446CED /* UIApplication+Load.swift in Sources */,
0306DBAB1D85D62A007AE314 /* Toast.swift in Sources */,
Expand Down