Skip to content

Commit

Permalink
Made styled public, added image support
Browse files Browse the repository at this point in the history
  • Loading branch information
blsage committed Dec 1, 2020
1 parent 29c677b commit 4446d5e
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions Sources/iTextField/iTextField+ViewModifiers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,24 @@ extension iTextField {
return view
}

func style(height: CGFloat = 58,
/// Gives the text field a default style.
/// - Parameters:
/// - height: How tall the text field should be, in points. Defaults to 58.
/// - backgroundColor: The background color of the text field. Defaults to clear.
/// - accentColor: The cursor and highlighting color of the text field. Defaults to light blue.
/// - inputFont: The font of the text field
/// - paddingLeading: Leading-edge padding size, in points. Defaults to 25.
/// - cornerRadius: Text field corner radius. Defaults to 6.
/// - hasShadow: Whether or not the text field has a shadow when selected. Defaults to true.
/// - Returns: A stylized view containing a text field.
public func style(height: CGFloat = 58,
backgroundColor: Color? = nil,
accentColor: Color = Color(red: 0.30, green: 0.76, blue: 0.85),
font inputFont: UIFont? = nil,
paddingLeading: CGFloat = 25,
cornerRadius: CGFloat = 6,
hasShadow: Bool = true) -> some View
hasShadow: Bool = true,
image: Image? = nil) -> some View
{
var darkMode: Bool { colorScheme == .dark }

Expand All @@ -299,8 +310,8 @@ extension iTextField {
}

var font: UIFont {
if inputFont != nil {
return inputFont!
if let inputFont = inputFont {
return inputFont
} else {
let fontSize: CGFloat = 20
let systemFont = UIFont.systemFont(ofSize: fontSize, weight: .regular)
Expand All @@ -310,14 +321,18 @@ extension iTextField {
return systemFont
}
}

}

return ZStack {
self
.accentColor(cursorColor)
.fontFromUIFont(font)
.padding(.horizontal, leadingPadding)
HStack {
if let image = image {
image
}
self
.accentColor(cursorColor)
.fontFromUIFont(font)
}
.padding(.horizontal, leadingPadding)
}
.frame(height: height)
.background(backgroundColor)
Expand Down

0 comments on commit 4446d5e

Please sign in to comment.