Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
Material
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitriy Stepanets
Material
Commits
5cbae5db
Commit
5cbae5db
authored
Jun 01, 2018
by
Orkhan Alikhanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added errorLabel to ErrorTextField
parent
87ac65d4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
16 deletions
+65
-16
Sources/iOS/ErrorTextField.swift
+51
-4
Sources/iOS/TextField.swift
+14
-12
No files found.
Sources/iOS/ErrorTextField.swift
View file @
5cbae5db
...
@@ -31,18 +31,65 @@
...
@@ -31,18 +31,65 @@
import
UIKit
import
UIKit
open
class
ErrorTextField
:
TextField
{
open
class
ErrorTextField
:
TextField
{
/// Controls the visibility of detailLabel
/// The errorLabel UILabel that is displayed.
@IBInspectable
open
let
errorLabel
=
UILabel
()
/// The errorLabel text value.
@IBInspectable
open
var
error
:
String
?
{
get
{
return
errorLabel
.
text
}
set
(
value
)
{
errorLabel
.
text
=
value
layoutSubviews
()
}
}
/// Error text color
@IBInspectable
open
var
errorColor
=
Color
.
red
.
base
{
didSet
{
errorLabel
.
textColor
=
errorColor
}
}
/// Vertical distance for the errorLabel from the divider.
@IBInspectable
@IBInspectable
open
var
isErrorRevealed
=
false
{
open
var
errorVerticalOffset
:
CGFloat
=
8
{
didSet
{
didSet
{
detailLabel
.
isHidden
=
!
isErrorRevealed
layoutSubviews
()
layoutSubviews
()
}
}
}
}
open
var
isErrorRevealed
:
Bool
{
get
{
return
!
errorLabel
.
isHidden
}
set
{
errorLabel
.
isHidden
=
!
newValue
detailLabel
.
isHidden
=
newValue
}
}
open
override
func
prepare
()
{
open
override
func
prepare
()
{
super
.
prepare
()
super
.
prepare
()
isErrorRevealed
=
false
isErrorRevealed
=
false
detailColor
=
Color
.
red
.
base
prepareErrorLabel
()
}
/// Prepares the errorLabel.
func
prepareErrorLabel
()
{
errorLabel
.
font
=
RobotoFont
.
regular
(
with
:
12
)
errorLabel
.
numberOfLines
=
0
errorColor
=
{
errorColor
}()
// call didSet
addSubview
(
errorLabel
)
}
open
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
layoutBottomLabel
(
label
:
errorLabel
,
verticalOffset
:
errorVerticalOffset
)
}
}
}
}
Sources/iOS/TextField.swift
View file @
5cbae5db
...
@@ -268,7 +268,7 @@ open class TextField: UITextField {
...
@@ -268,7 +268,7 @@ open class TextField: UITextField {
@IBInspectable
@IBInspectable
open
var
detailVerticalOffset
:
CGFloat
=
8
{
open
var
detailVerticalOffset
:
CGFloat
=
8
{
didSet
{
didSet
{
layout
DetailLabel
()
layout
Subviews
()
}
}
}
}
...
@@ -412,7 +412,7 @@ open class TextField: UITextField {
...
@@ -412,7 +412,7 @@ open class TextField: UITextField {
super
.
layoutSubviews
()
super
.
layoutSubviews
()
layoutShape
()
layoutShape
()
layoutPlaceholderLabel
()
layoutPlaceholderLabel
()
layout
DetailLabel
(
)
layout
BottomLabel
(
label
:
detailLabel
,
verticalOffset
:
detailVerticalOffset
)
layoutButton
(
button
:
clearIconButton
)
layoutButton
(
button
:
clearIconButton
)
layoutButton
(
button
:
visibilityIconButton
)
layoutButton
(
button
:
visibilityIconButton
)
layoutDivider
()
layoutDivider
()
...
@@ -573,16 +573,7 @@ fileprivate extension TextField {
...
@@ -573,16 +573,7 @@ fileprivate extension TextField {
placeholderLabel
.
frame
.
origin
.
y
=
-
placeholderLabel
.
bounds
.
height
+
placeholderVerticalOffset
placeholderLabel
.
frame
.
origin
.
y
=
-
placeholderLabel
.
bounds
.
height
+
placeholderVerticalOffset
}
}
/// Layout the detailLabel.
func
layoutDetailLabel
()
{
let
c
=
dividerContentEdgeInsets
detailLabel
.
frame
.
size
.
height
=
detailLabel
.
sizeThatFits
(
CGSize
(
width
:
bounds
.
width
,
height
:
.
greatestFiniteMagnitude
))
.
height
detailLabel
.
frame
.
origin
.
x
=
c
.
left
detailLabel
.
frame
.
origin
.
y
=
bounds
.
height
+
detailVerticalOffset
detailLabel
.
frame
.
size
.
width
=
bounds
.
width
-
c
.
left
-
c
.
right
}
/// Layout the a button.
/// Layout the a button.
func
layoutButton
(
button
:
UIButton
?)
{
func
layoutButton
(
button
:
UIButton
?)
{
button
?
.
frame
=
CGRect
(
x
:
bounds
.
width
-
bounds
.
height
,
y
:
0
,
width
:
bounds
.
height
,
height
:
bounds
.
height
)
button
?
.
frame
=
CGRect
(
x
:
bounds
.
width
-
bounds
.
height
,
y
:
0
,
width
:
bounds
.
height
,
height
:
bounds
.
height
)
...
@@ -600,6 +591,17 @@ fileprivate extension TextField {
...
@@ -600,6 +591,17 @@ fileprivate extension TextField {
}
}
}
}
internal
extension
TextField
{
/// Layout given label at the bottom with the vertical offset provided.
func
layoutBottomLabel
(
label
:
UILabel
,
verticalOffset
:
CGFloat
)
{
let
c
=
dividerContentEdgeInsets
label
.
frame
.
origin
.
x
=
c
.
left
label
.
frame
.
origin
.
y
=
bounds
.
height
+
verticalOffset
label
.
frame
.
size
.
width
=
bounds
.
width
-
c
.
left
-
c
.
right
label
.
frame
.
size
.
height
=
label
.
sizeThatFits
(
CGSize
(
width
:
label
.
bounds
.
width
,
height
:
.
greatestFiniteMagnitude
))
.
height
}
}
fileprivate
extension
TextField
{
fileprivate
extension
TextField
{
/// Handles the text editing did begin state.
/// Handles the text editing did begin state.
@objc
@objc
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment