| | |
| | | } |
| | | } |
| | | |
| | | @objc override weak open var delegate: UITextViewDelegate? { |
| | | @objc override weak open var delegate: (any UITextViewDelegate)? { |
| | | |
| | | get { |
| | | refreshPlaceholder() |
| | |
| | | |
| | | return newSize |
| | | } |
| | | |
| | | |
| | | @objc override open func caretRect(for position: UITextPosition) -> CGRect { |
| | | var originalRect = super.caretRect(for: position) |
| | | |
| | | // When placeholder is visible and text alignment is centered |
| | | if placeholderLabel.alpha == 1 && self.textAlignment == .center { |
| | | // Calculate the width of the placeholder text |
| | | let textSize = placeholderLabel.text?.size(withAttributes: [.font: placeholderLabel.font ?? UIFont.systemFont(ofSize: UIFont.systemFontSize)]) ?? .zero |
| | | let font = placeholderLabel.font ?? UIFont.systemFont(ofSize: UIFont.systemFontSize) |
| | | let textSize = placeholderLabel.text?.size(withAttributes: [.font: font]) ?? .zero |
| | | // Calculate the starting x position of the centered placeholder text |
| | | let centeredTextX = (self.bounds.size.width - textSize.width) / 2 |
| | | // Update the caret position to match the starting x position of the centered text |
| | |
| | | } |
| | | |
| | | return originalRect |
| | | } |
| | | |
| | | } |
| | | } |