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
Disabling Nslog for Production in Swift Project
Googlemaps Basic iOS Demo App Crash - Unrecognized Selector Sent to Instance
Specifying One Dimension of Cells in Uicollectionview Using Auto Layout
Didreceiveremotenotification: Fetchcompletionhandler: Open from Icon VS Push Notification
Enterprise App Deployment Doesn't Install on iOS 8.1.3
iOS 6 - Viewdidunload Migrate to Didreceivememorywarning
The Maximum Number of Apps for Free Development Profiles Has Been Reached. Xcode 11.5
Referring to Weak Self Inside a Nested Block
Swift Performseguewithidentifier Not Working
Auto Adjust Custom Uitableviewcell and Label in It to the Text
Maskstobounds VS. Clipstobounds
Ccavenue iOS Kit Integration Kit
Implementing Fast and Efficient Core Data Import on iOS 5
Is There a Public Way to Force Mpnowplayinginfocenter to Show Podcast Controls
Uitextview Style Is Being Reset After Setting Text Property