Uitextview Style Is Being Reset After Setting Text Property

UITextView style is being reset after setting text property

Sitting with this for hours, I found the bug.
If the property "Selectable" = NO it will reset the font and fontcolor when setText is used.

So turn Selectable ON and the bug is gone.

UITextView style is reset when I change kerning

The font property only changes the font for the text property. The attributedText is a different property, so you need to define the font for it too:

let attrs: [NSAttributedString.Key : Any] = [.kern: kernText.value,
.font: UIFont.systemFont(ofSize: CGFloat(sizeText.value * 1))]
textOne?.attributedText = NSAttributedString(string: textString!, attributes: attrs)

On a side note, if you want to do a thing like this it's better to stick to one property, in this case attributedText, otherwise you have to keep them in sync.

UITextView text color doesn't reset after setting attributed text

Fixed the issue by setting typing attributes to textView

- (BOOL)growingTextView:(HPGrowingTextView *)growingTextView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {

NSString* fullText = [growingTextView.text stringByReplacingCharactersInRange:range withString:text];
growingTextView.internalTextView.typingAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:15],NSForegroundColorAttributeName:[UIColor whiteColor]};

return YES;
}

Redrawing UITextView selection after changing paragraph style

It is a bit late, but maybe it helps you or others....

You can change the selection through the UITextInput-Protocol by setting the selectedTextRange .

let beginning: UITextPosition = textView.beginningOfDocument
let start: UITextPosition = textView.positionFromPosition(beginning, offset: textView.selectedRange.location)
let end: UITextPosition = textView.positionFromPosition(start!, offset: textView.selectedRange.length)

textView.selectedRange = NSMakeRange(0, 0)
textView.selectedTextRange = textView.textRangeFromPosition(start!, toPosition: end!)

P.S. My code is written in Swift, but I think it is no problem to convert that to objective c, or?

How does one prevent existing text in uitextview from being overwritten

Implement the following UITextViewDelegate method

func textViewDidBeginEditing(_ textView: UITextView) {
textView.selectedRange = NSRange(location: textView.text.characters.count-1, length: 0)
}


Related Topics



Leave a reply



Submit