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
4309c160
Commit
4309c160
authored
Apr 04, 2017
by
Daniel Dahan
Committed by
GitHub
Apr 04, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #662 from slxl/master
TextField inset added
parents
0bac0578
58eca684
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
7 deletions
+18
-7
Sources/iOS/TextField.swift
+18
-7
No files found.
Sources/iOS/TextField.swift
View file @
4309c160
...
...
@@ -387,6 +387,17 @@ open class TextField: UITextField {
return
super
.
becomeFirstResponder
()
}
open
var
textInset
:
CGFloat
=
0
open
override
func
textRect
(
forBounds
bounds
:
CGRect
)
->
CGRect
{
return
bounds
.
insetBy
(
dx
:
textInset
,
dy
:
0
)
}
open
override
func
editingRect
(
forBounds
bounds
:
CGRect
)
->
CGRect
{
return
textRect
(
forBounds
:
bounds
)
}
/**
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepare method
...
...
@@ -482,24 +493,24 @@ extension TextField {
extension
TextField
{
/// Layout the placeholderLabel.
fileprivate
func
layoutPlaceholderLabel
()
{
let
w
=
leftViewWidth
let
w
=
leftViewWidth
+
textInset
let
h
=
0
==
height
?
intrinsicContentSize
.
height
:
height
placeholderLabel
.
transform
=
CGAffineTransform
.
identity
guard
isEditing
||
!
isEmpty
||
!
isPlaceholderAnimated
else
{
placeholderLabel
.
frame
=
CGRect
(
x
:
w
,
y
:
0
,
width
:
width
-
w
,
height
:
h
)
placeholderLabel
.
frame
=
CGRect
(
x
:
w
,
y
:
0
,
width
:
width
-
leftViewWidth
-
2
*
textInset
,
height
:
h
)
return
}
placeholderLabel
.
frame
=
CGRect
(
x
:
w
,
y
:
0
,
width
:
width
-
w
,
height
:
h
)
placeholderLabel
.
frame
=
CGRect
(
x
:
w
,
y
:
0
,
width
:
width
-
leftViewWidth
-
2
*
textInset
,
height
:
h
)
placeholderLabel
.
transform
=
CGAffineTransform
(
scaleX
:
0.75
,
y
:
0.75
)
switch
textAlignment
{
case
.
left
,
.
natural
:
placeholderLabel
.
x
=
w
case
.
right
:
placeholderLabel
.
x
=
width
-
placeholderLabel
.
width
placeholderLabel
.
x
=
width
-
placeholderLabel
.
width
-
textInset
default
:
break
}
...
...
@@ -640,9 +651,9 @@ extension TextField {
switch
s
.
textAlignment
{
case
.
left
,
.
natural
:
s
.
placeholderLabel
.
x
=
s
.
leftViewWidth
s
.
placeholderLabel
.
x
=
s
.
leftViewWidth
+
s
.
textInset
case
.
right
:
s
.
placeholderLabel
.
x
=
s
.
width
-
s
.
placeholderLabel
.
width
s
.
placeholderLabel
.
x
=
s
.
width
-
s
.
placeholderLabel
.
width
-
s
.
textInset
default
:
break
}
...
...
@@ -673,7 +684,7 @@ extension TextField {
}
s
.
placeholderLabel
.
transform
=
CGAffineTransform
.
identity
s
.
placeholderLabel
.
x
=
s
.
leftViewWidth
s
.
placeholderLabel
.
x
=
s
.
leftViewWidth
+
s
.
textInset
s
.
placeholderLabel
.
y
=
0
})
}
...
...
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