Skip to content
This repository was archived by the owner on Jan 16, 2026. It is now read-only.
This repository was archived by the owner on Jan 16, 2026. It is now read-only.

Make Placeholder and editingText in centre #352

@Aman21-git

Description

@Aman21-git

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 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions