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

Make Placeholder and editingText in centre #352

Open
Aman21-git opened this issue Dec 27, 2024 · 0 comments
Open

Make Placeholder and editingText in centre #352

Aman21-git opened this issue Dec 27, 2024 · 0 comments

Comments

@Aman21-git
Copy link

I notice one thing in this code when I use this textfield in my app PLACEHOLDER ans textfield TEXT are not in centre I want that in centre so I change in this code little bit and change are below

// MARK: Properties

/**
The formatter used before displaying content in the title label. 
This can be the `title`, `selectedTitle` or the `errorMessage`.
The default implementation converts the text to uppercase.
*/
open var titleFormatter: ((String) -> String) = { (text: String) -> String in
    if #available(iOS 9.0, *) {
        return text
    } else {
        return text
    }
}

this one is for not get title lable text in capital 

/**
 Calculate the rectangle for the textfield when it is being edited
 - parameter bounds: The current bounds of the field
 - returns: The rectangle that the textfield should render in
 */
override open func editingRect(forBounds bounds: CGRect) -> CGRect {
    let superRect = super.editingRect(forBounds: bounds)
    let titleHeight = self.titleHeight()
    let centerHeight = ((bounds.size.height / 2) / 2) / 2
    var height = superRect.size.height - titleHeight - selectedLineHeight
    if errorMessagePlacement == .bottom {
        height -= errorHeight()
    }

    let rect = CGRect(
        x: superRect.origin.x,
        y: centerHeight,
        width: superRect.size.width,
        height: height
    )
    return rect
}

/**
 Calculate the rectangle for the placeholder
 - parameter bounds: The current bounds of the placeholder
 - returns: The rectangle that the placeholder should render in
 */
override open func placeholderRect(forBounds bounds: CGRect) -> CGRect {
    var height = bounds.size.height - titleHeight() - selectedLineHeight
    let centerHeight = ((bounds.size.height / 2) / 2) / 2
    if errorMessagePlacement == .bottom {
        height -= errorHeight()
    }
    let rect = CGRect(
        x: 0,
        y: centerHeight,
        width: bounds.size.width,
        height: height
    )
    return rect
}

this code is for make text in centre "centerHeight" this make text and **placeholder** in centre 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant