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
f172f0fc
Commit
f172f0fc
authored
Aug 07, 2018
by
Orkhan Alikhanov
Committed by
OrkhanAlikhanov
Aug 07, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added TextField.textInsets and fixed placeholder layout issues
parent
8a9d0902
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
14 deletions
+19
-14
Sources/iOS/TextField.swift
+19
-14
No files found.
Sources/iOS/TextField.swift
View file @
f172f0fc
...
...
@@ -420,13 +420,17 @@ open class TextField: UITextField {
/// EdgeInsets for text.
@objc
open
var
textInset
:
CGFloat
=
0
open
var
textInsets
:
EdgeInsets
=
.
zero
/// EdgeInsets preset property for text.
open
var
textInsetsPreset
=
EdgeInsetsPreset
.
none
{
didSet
{
textInsets
=
EdgeInsetsPresetToValue
(
preset
:
textInsetsPreset
)
}
}
open
override
func
textRect
(
forBounds
bounds
:
CGRect
)
->
CGRect
{
var
b
=
super
.
textRect
(
forBounds
:
bounds
)
b
.
origin
.
x
+=
textInset
b
.
size
.
width
-=
textInset
return
b
return
super
.
textRect
(
forBounds
:
bounds
)
.
inset
(
by
:
textInsets
)
}
open
override
func
editingRect
(
forBounds
bounds
:
CGRect
)
->
CGRect
{
...
...
@@ -573,26 +577,27 @@ fileprivate extension TextField {
fileprivate
extension
TextField
{
/// Layout the placeholderLabel.
func
layoutPlaceholderLabel
()
{
let
x
=
leftViewWidth
+
textInse
t
let
h
=
0
==
bounds
.
height
?
intrinsicContentSize
.
height
:
bounds
.
he
ight
let
w
=
bounds
.
width
-
leftViewWidth
-
2
*
textInse
t
placeholderLabel
.
frame
.
size
=
CGSize
(
width
:
w
,
height
:
h
)
let
leftPadding
=
leftViewWidth
+
textInsets
.
lef
t
let
w
=
bounds
.
width
-
leftPadding
-
textInsets
.
r
ight
var
h
=
placeholderLabel
.
sizeThatFits
(
CGSize
(
width
:
w
,
height
:
.
greatestFiniteMagnitude
))
.
heigh
t
h
=
min
(
h
,
bounds
.
height
-
textInsets
.
top
-
textInsets
.
bottom
)
guard
isEditing
||
!
isEmpty
||
!
isPlaceholderAnimated
else
{
placeholderLabel
.
transform
=
CGAffineTransform
.
identity
placeholderLabel
.
frame
.
origin
=
CGPoint
(
x
:
x
,
y
:
0
)
placeholderLabel
.
frame
=
CGRect
(
x
:
leftPadding
,
y
:
textInsets
.
top
,
width
:
w
,
height
:
h
)
return
}
placeholderLabel
.
transform
=
CGAffineTransform
(
scaleX
:
placeholderActiveScale
,
y
:
placeholderActiveScale
)
placeholderLabel
.
frame
.
size
=
CGSize
(
width
:
w
*
placeholderActiveScale
,
height
:
h
*
placeholderActiveScale
)
placeholderLabel
.
frame
.
origin
.
y
=
-
placeholderLabel
.
frame
.
height
+
placeholderVerticalOffset
switch
textAlignment
{
switch
placeholderLabel
.
textAlignment
{
case
.
left
,
.
natural
:
placeholderLabel
.
frame
.
origin
.
x
=
x
+
placeholderHorizontalOffset
placeholderLabel
.
frame
.
origin
.
x
=
leftPadding
+
placeholderHorizontalOffset
case
.
right
:
placeholderLabel
.
frame
.
origin
.
x
=
(
bounds
.
width
*
(
1.0
-
placeholderActiveScale
))
-
textInset
+
placeholderHorizontalOffset
let
scaledWidth
=
w
*
placeholderActiveScale
placeholderLabel
.
frame
.
origin
.
x
=
bounds
.
width
-
scaledWidth
-
textInsets
.
right
+
placeholderHorizontalOffset
default
:
break
}
}
...
...
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