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
233c49bf
Unverified
Commit
233c49bf
authored
Sep 29, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated TextField for fix 517 and added new API
parent
eb94bb7e
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
48 deletions
+56
-48
Examples/Programmatic/TextField/TextField.xcodeproj/project.pbxproj
+2
-0
Examples/Programmatic/TextField/TextField/ViewController.swift
+6
-9
Sources/iOS/TextField.swift
+48
-39
No files found.
Examples/Programmatic/TextField/TextField.xcodeproj/project.pbxproj
View file @
233c49bf
...
...
@@ -262,6 +262,7 @@
isa
=
XCBuildConfiguration
;
buildSettings
=
{
ASSETCATALOG_COMPILER_APPICON_NAME
=
AppIcon
;
DEVELOPMENT_TEAM
=
""
;
INFOPLIST_FILE
=
TextField/Info.plist
;
LD_RUNPATH_SEARCH_PATHS
=
"$(inherited) @executable_path/Frameworks"
;
PRODUCT_BUNDLE_IDENTIFIER
=
io.cosmicmind.TextField
;
...
...
@@ -274,6 +275,7 @@
isa
=
XCBuildConfiguration
;
buildSettings
=
{
ASSETCATALOG_COMPILER_APPICON_NAME
=
AppIcon
;
DEVELOPMENT_TEAM
=
""
;
INFOPLIST_FILE
=
TextField/Info.plist
;
LD_RUNPATH_SEARCH_PATHS
=
"$(inherited) @executable_path/Frameworks"
;
PRODUCT_BUNDLE_IDENTIFIER
=
io.cosmicmind.TextField
;
...
...
Examples/Programmatic/TextField/TextField/ViewController.swift
View file @
233c49bf
...
...
@@ -54,20 +54,19 @@ class ViewController: UIViewController {
/// Prepares the resign responder button.
private
func
prepareResignResponderButton
()
{
let
btn
=
RaisedButton
(
title
:
"Resign"
,
titleColor
:
Color
.
blue
.
base
)
btn
.
addTarget
(
self
,
action
:
#selector(
handleResignResponderButton
)
,
for
:
.
touchUpInside
)
btn
.
addTarget
(
self
,
action
:
#selector(
handleResignResponderButton
(button:)
)
,
for
:
.
touchUpInside
)
view
.
layout
(
btn
)
.
width
(
100
)
.
height
(
50
)
.
bottom
(
24
)
.
right
(
24
)
}
/// Handle the resign responder button.
internal
func
handleResignResponderButton
()
{
@objc
internal
func
handleResignResponderButton
(
button
:
UIButton
)
{
nameField
?
.
resignFirstResponder
()
emailField
?
.
resignFirstResponder
()
passwordField
?
.
resignFirstResponder
()
}
/// Prepares the name TextField.
private
func
prepareNameField
()
{
nameField
=
TextField
()
nameField
.
text
=
"Daniel Dahan"
...
...
@@ -81,7 +80,6 @@ class ViewController: UIViewController {
view
.
layout
(
nameField
)
.
top
(
40
)
.
horizontally
(
left
:
40
,
right
:
40
)
}
/// Prepares the email TextField.
private
func
prepareEmailField
()
{
emailField
=
ErrorTextField
(
frame
:
CGRect
(
x
:
40
,
y
:
120
,
width
:
view
.
width
-
80
,
height
:
32
))
emailField
.
placeholder
=
"Email"
...
...
@@ -89,14 +87,13 @@ class ViewController: UIViewController {
emailField
.
isClearIconButtonEnabled
=
true
emailField
.
delegate
=
self
emailField
.
placeholderColor
=
Color
.
amber
.
darken4
emailField
.
placeholder
Normal
Color
=
Color
.
amber
.
darken4
emailField
.
placeholderActiveColor
=
Color
.
pink
.
base
emailField
.
dividerColor
=
Color
.
cyan
.
base
emailField
.
divider
Normal
Color
=
Color
.
cyan
.
base
view
.
addSubview
(
emailField
)
}
/// Prepares the password TextField.
private
func
preparePasswordField
()
{
passwordField
=
TextField
()
passwordField
.
placeholder
=
"Password"
...
...
@@ -104,7 +101,7 @@ class ViewController: UIViewController {
passwordField
.
clearButtonMode
=
.
whileEditing
passwordField
.
isVisibilityIconButtonEnabled
=
true
// Setting the visibility
Flat
Button color.
// Setting the visibility
Icon
Button color.
passwordField
.
visibilityIconButton
?
.
tintColor
=
Color
.
green
.
base
.
withAlphaComponent
(
passwordField
.
isSecureTextEntry
?
0.38
:
0.54
)
// Size the TextField to the maximum width, less 40 pixels on either side
...
...
Sources/iOS/TextField.swift
View file @
233c49bf
...
...
@@ -30,6 +30,8 @@
import
UIKit
private
var
TextFieldContext
:
UInt8
=
0
public
protocol
TextFieldDelegate
:
UITextFieldDelegate
{}
open
class
TextField
:
UITextField
{
...
...
@@ -41,45 +43,35 @@ open class TextField: UITextField {
/// A Boolean that indicates if the TextField is in an animating state.
open
internal(set)
var
isAnimating
=
false
/// A property that accesses the backing layer's backgroundColor
.
/// Divider normal height
.
@IBInspectable
open
override
var
backgroundColor
:
UIColor
?
{
didSet
{
layer
.
backgroundColor
=
backgroundColor
?
.
cgColor
}
}
open
var
dividerNormalHeight
:
CGFloat
=
1
/// Divider active state height.
/// Divider active height.
@IBInspectable
open
var
dividerActiveHeight
:
CGFloat
=
2
///
Sets the divide
r.
///
Divider normal colo
r.
@IBInspectable
open
override
var
dividerColor
:
UIColor
?
{
get
{
return
super
.
dividerColor
}
set
(
value
)
{
open
var
dividerNormalColor
=
Color
.
darkText
.
dividers
{
didSet
{
guard
!
isEditing
else
{
return
}
super
.
dividerColor
=
value
dividerColor
=
dividerNormalColor
}
}
///
Sets the divide
r.
///
Divider active colo
r.
@IBInspectable
open
var
dividerActiveColor
:
UIColor
?
{
open
var
dividerActiveColor
=
Color
.
blue
.
base
{
didSet
{
guard
isEditing
else
{
return
}
guard
let
v
=
dividerActiveColor
else
{
return
}
dividerColor
=
v
dividerColor
=
dividerActiveColor
}
}
...
...
@@ -110,7 +102,7 @@ open class TextField: UITextField {
set
(
value
)
{
placeholderLabel
.
text
=
value
if
let
v
:
String
=
value
{
placeholderLabel
.
attributedText
=
NSAttributedString
(
string
:
v
,
attributes
:
[
NSForegroundColorAttributeName
:
placeholderColor
])
placeholderLabel
.
attributedText
=
NSAttributedString
(
string
:
v
,
attributes
:
[
NSForegroundColorAttributeName
:
placeholder
Normal
Color
])
}
}
}
...
...
@@ -119,13 +111,13 @@ open class TextField: UITextField {
@IBInspectable
open
private(set)
var
placeholderLabel
:
UILabel
!
/// Placeholder textColor.
/// Placeholder
normal
textColor.
@IBInspectable
open
var
placeholderColor
=
Color
.
darkText
.
others
{
open
var
placeholder
Normal
Color
=
Color
.
darkText
.
others
{
didSet
{
if
!
isEditing
{
if
let
v
:
String
=
placeholder
{
placeholderLabel
.
attributedText
=
NSAttributedString
(
string
:
v
,
attributes
:
[
NSForegroundColorAttributeName
:
placeholderColor
])
placeholderLabel
.
attributedText
=
NSAttributedString
(
string
:
v
,
attributes
:
[
NSForegroundColorAttributeName
:
placeholder
Normal
Color
])
}
}
}
...
...
@@ -145,13 +137,13 @@ open class TextField: UITextField {
}
/// This property adds a padding to placeholder y position animation
@IBInspectable
open
var
placeholderVerticalOffset
:
CGFloat
=
0
/// The detailLabel UILabel that is displayed.
@IBInspectable
open
private(set)
lazy
var
detailLabel
=
UILabel
(
frame
:
.
zero
)
/// The detailLabel text value.
@IBInspectable
open
var
detail
:
String
?
{
...
...
@@ -160,10 +152,6 @@ open class TextField: UITextField {
}
set
(
value
)
{
detailLabel
.
text
=
value
if
let
v
:
String
=
value
{
detailLabel
.
attributedText
=
NSAttributedString
(
string
:
v
,
attributes
:
[
NSForegroundColorAttributeName
:
detailColor
])
}
layoutDetailLabel
()
}
}
...
...
@@ -171,7 +159,7 @@ open class TextField: UITextField {
@IBInspectable
open
var
detailColor
=
Color
.
darkText
.
others
{
didSet
{
if
let
v
:
String
=
detailLabel
.
text
{
if
let
v
=
detailLabel
.
text
{
detailLabel
.
attributedText
=
NSAttributedString
(
string
:
v
,
attributes
:
[
NSForegroundColorAttributeName
:
detailColor
])
}
}
...
...
@@ -206,7 +194,7 @@ open class TextField: UITextField {
set
(
value
)
{
if
value
{
if
nil
==
clearIconButton
{
clearIconButton
=
IconButton
(
image
:
Icon
.
cm
.
clear
,
tintColor
:
placeholderColor
)
clearIconButton
=
IconButton
(
image
:
Icon
.
cm
.
clear
,
tintColor
:
placeholder
Normal
Color
)
clearIconButton
!.
contentEdgeInsets
=
.
zero
clearIconButton
!.
pulseAnimation
=
.
center
clearButtonMode
=
.
never
...
...
@@ -241,7 +229,7 @@ open class TextField: UITextField {
set
(
value
)
{
if
value
{
if
nil
==
visibilityIconButton
{
visibilityIconButton
=
IconButton
(
image
:
Icon
.
visibility
,
tintColor
:
placeholderColor
.
withAlphaComponent
(
isSecureTextEntry
?
0.38
:
0.54
))
visibilityIconButton
=
IconButton
(
image
:
Icon
.
visibility
,
tintColor
:
placeholder
Normal
Color
.
withAlphaComponent
(
isSecureTextEntry
?
0.38
:
0.54
))
visibilityIconButton
!.
contentEdgeInsets
=
.
zero
visibilityIconButton
!.
pulseAnimation
=
.
center
isSecureTextEntry
=
true
...
...
@@ -285,6 +273,19 @@ open class TextField: UITextField {
return
super
.
becomeFirstResponder
()
}
open
override
func
observeValue
(
forKeyPath
keyPath
:
String
?,
of
object
:
Any
?,
change
:
[
NSKeyValueChangeKey
:
Any
]?,
context
:
UnsafeMutableRawPointer
?)
{
guard
"detailLabel.text"
==
keyPath
else
{
super
.
observeValue
(
forKeyPath
:
keyPath
,
of
:
object
,
change
:
change
,
context
:
context
)
return
}
updateDetailLabelAttributedText
()
layoutDetailLabel
()
}
deinit
{
removeObserver
(
self
,
forKeyPath
:
"titleLabel.text"
)
}
/**
An initializer that initializes the object with a NSCoder object.
- Parameter aDecoder: A NSCoder instance.
...
...
@@ -407,7 +408,7 @@ open class TextField: UITextField {
default
:
break
}
placeholderLabel
.
y
=
-
placeholderLabel
.
height
+
placeholderVerticalOffset
placeholderLabel
.
textColor
=
placeholderColor
placeholderLabel
.
textColor
=
placeholder
Normal
Color
}
else
{
switch
textAlignment
{
case
.
left
,
.
natural
:
...
...
@@ -457,8 +458,8 @@ open class TextField: UITextField {
/// The animation for the divider when editing ends.
open
func
dividerEditingDidEndAnimation
()
{
// divider.frame.size.height = divider
Height
// divider.color = divider
Color
dividerHeight
=
dividerNormal
Height
dividerColor
=
dividerNormal
Color
}
/// The animation for the placeholder when editing begins.
...
...
@@ -495,13 +496,13 @@ open class TextField: UITextField {
s
.
placeholderLabel
.
transform
=
CGAffineTransform
.
identity
s
.
placeholderLabel
.
x
=
0
s
.
placeholderLabel
.
y
=
0
s
.
placeholderLabel
.
textColor
=
s
.
placeholderColor
s
.
placeholderLabel
.
textColor
=
s
.
placeholder
Normal
Color
}
})
{
[
weak
self
]
_
in
self
?
.
isAnimating
=
false
}
}
else
if
!
isEditing
{
placeholderLabel
.
textColor
=
placeholderColor
placeholderLabel
.
textColor
=
placeholder
Normal
Color
}
}
...
...
@@ -513,7 +514,7 @@ open class TextField: UITextField {
/// Prepares the placeholderLabel.
private
func
preparePlaceholderLabel
()
{
placeholderLabel
=
UILabel
(
frame
:
.
zero
)
placeholderColor
=
Color
.
darkText
.
others
placeholder
Normal
Color
=
Color
.
darkText
.
others
font
=
RobotoFont
.
regular
(
with
:
16
)
addSubview
(
placeholderLabel
)
}
...
...
@@ -524,6 +525,7 @@ open class TextField: UITextField {
detailLabel
.
numberOfLines
=
0
detailColor
=
Color
.
darkText
.
others
addSubview
(
detailLabel
)
addObserver
(
self
,
forKeyPath
:
"detailLabel.text"
,
options
:
[],
context
:
&
TextFieldContext
)
}
/// Prepares the target handlers.
...
...
@@ -536,4 +538,11 @@ open class TextField: UITextField {
private
func
prepareTextAlignment
()
{
textAlignment
=
.
rightToLeft
==
UIApplication
.
shared
.
userInterfaceLayoutDirection
?
.
right
:
.
left
}
/// Updates the detailLabel attributedText.
private
func
updateDetailLabelAttributedText
()
{
if
let
v
=
detail
{
detailLabel
.
attributedText
=
NSAttributedString
(
string
:
v
,
attributes
:
[
NSForegroundColorAttributeName
:
detailColor
])
}
}
}
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