mirror of
https://github.com/devxoul/Toaster.git
synced 2026-01-18 21:21:19 +01:00
Add property to adjust width ratio in window (#165)
* Add `maxWidthRatio`
This commit is contained in:
@@ -41,6 +41,7 @@ final class RootViewController: UIViewController {
|
||||
appearance.textInsets = UIEdgeInsets(top: 15, left: 20, bottom: 15, right: 20)
|
||||
appearance.bottomOffsetPortrait = 100
|
||||
appearance.cornerRadius = 20
|
||||
appearance.maxWidthRatio = 0.7
|
||||
}
|
||||
|
||||
func configureAccessibility() {
|
||||
|
||||
@@ -52,6 +52,7 @@
|
||||
appearance.textInsets = UIEdgeInsetsMake(15, 20, 15, 20);
|
||||
appearance.bottomOffsetPortrait = 100;
|
||||
appearance.cornerRadius = 20;
|
||||
appearance.maxWidthRatio = 0.7;
|
||||
}
|
||||
|
||||
- (void)configureAccessibility {
|
||||
|
||||
@@ -72,6 +72,9 @@ open class ToastView: UIView {
|
||||
}
|
||||
}()
|
||||
|
||||
/// The width ratio of toast view in window, specified as a value from 0.0 to 1.0.
|
||||
/// Default value: 0.875
|
||||
@objc open dynamic var maxWidthRatio: CGFloat = (280.0 / 320.0)
|
||||
|
||||
// MARK: UI
|
||||
|
||||
@@ -124,7 +127,7 @@ open class ToastView: UIView {
|
||||
super.layoutSubviews()
|
||||
let containerSize = ToastWindow.shared.frame.size
|
||||
let constraintSize = CGSize(
|
||||
width: containerSize.width * (280.0 / 320.0) - self.textInsets.left - self.textInsets.right,
|
||||
width: containerSize.width * maxWidthRatio - self.textInsets.left - self.textInsets.right,
|
||||
height: CGFloat.greatestFiniteMagnitude
|
||||
)
|
||||
let textLabelSize = self.textLabel.sizeThatFits(constraintSize)
|
||||
|
||||
Reference in New Issue
Block a user