Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add customizable corner radius #23

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions DTTextField/Classes/DTTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ public class DTTextField: UITextField {
}
}

public var cornerRadius:CGFloat = 4.5{
didSet{
let borderStyle = dtborderStyle;
dtborderStyle = borderStyle
}
}

public var dtborderStyle:DTBorderStyle = .rounded{
didSet{
borderLayer.removeFromSuperlayer()
Expand All @@ -61,7 +68,7 @@ public class DTTextField: UITextField {
dtLayer.cornerRadius = 0.0
dtLayer.borderWidth = 0.0
case .rounded:
dtLayer.cornerRadius = 4.5
dtLayer.cornerRadius = cornerRadius
dtLayer.borderWidth = borderWidth
dtLayer.borderColor = borderColor.cgColor
case .sqare:
Expand Down Expand Up @@ -99,6 +106,11 @@ public class DTTextField: UITextField {
invalidateIntrinsicContentSize()
}
}
public var errorColor = UIColor.red {
didSet{
lblError.textColor = errorColor
}
}

public var floatPlaceholderFont = UIFont.systemFont(ofSize: 10.0){
didSet{
Expand Down Expand Up @@ -266,7 +278,7 @@ public class DTTextField: UITextField {

lblError.frame = CGRect.zero
lblError.font = errorFont
lblError.textColor = UIColor.red
lblError.textColor = errorColor
lblError.numberOfLines = 0
lblError.isHidden = true

Expand Down Expand Up @@ -387,7 +399,8 @@ public class DTTextField: UITextField {
guard showErrorLabel else { return CGRect(x: newX, y: 0, width: rect.width - newX - paddingX, height: rect.height) }

let topInset = (rect.size.height - lblError.bounds.size.height - paddingYErrorLabel - fontHeight) / 2.0
let textY = topInset - ((rect.height - fontHeight) / 2.0)
let textOriginalY = (rect.height - fontHeight) / 2.0
let textY = floor(topInset - textOriginalY)

return CGRect(x: newX, y: floor(textY), width: rect.size.width - newX - paddingX, height: rect.size.height)
}
Expand All @@ -407,9 +420,9 @@ public class DTTextField: UITextField {
}else{
let topInset = paddingYFloatLabel + lblFloatPlaceholder.bounds.size.height + (paddingHeight / 2.0)
let textOriginalY = (rect.height - fontHeight) / 2.0
var textY = topInset - textOriginalY
var textY = ceil(topInset - textOriginalY)

if textY < 0 && !showErrorLabel { textY = topInset }
if textY < 0 && !showErrorLabel { textY = abs(topInset - textOriginalY) }
let newX = x
return CGRect(x: newX, y: ceil(textY), width: rect.size.width - newX - paddingX, height: rect.height)
}
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pod 'DTTextField'
| ------------- |------------- | ----- |
| errorMessage | String | Add your error message to this property|
| errorFont | UIFont | Change font of error text |
| errorColor | UIColor | Change color of error text |
| paddingYErrorLabel | CGFloat | Error text top padding |
| floatPlaceholderColor | UIColor | To change float placeholder color |
| floatPlaceholderActiveColor | UIColor | To change float placeholder color while TextField is active(First responder)|
Expand All @@ -61,6 +62,7 @@ pod 'DTTextField'
| ------------- |------------- | ----- |
| dtLayer | CALayer | If you want to formate DTTextField than use dtLayer property instead of layer (e.g. background color) |
| borderColor | UIColor | Change border color of DTTextField |
| cornerRadius | CGFloat | Change radius border of DTTextField - Used only with Style "rounded" |
| canShowBorder | Bool | Toggle border of DTTextField |
| dtborderStyle | enum | none, rounded , sqare , top , bottom , left , right |

Expand Down