My whole app freezes up when line breaks are added to the string I want to fill up a UITextView with.
This freezes up the app:
let testStringLineBreaks = "foooooo \n \n barrrrrr"
self.biographyTextView.text = testStringLineBreaks
This doesn't freeze up the app:
let testStringNoLineBreaks = "foooooobarrrrrr"
self.biographyTextView.text = testStringNoLineBreaks
Why? And how do I fix it? I need to be able to use linebreaks on my UITextView as well because this is where users fill in their profile description.
The app uses about 60 MB. However when it gets stuck on the line:
self.biographyTextView.text = testStringLineBreaks
It keeps going up with about 2 mb per second. I killed the app at 183 mb.
It only happens on iOS 8 and not on iOS 9.
import UIKit
class GFTextView: UITextView {
let bottomBorder = CALayer()
@IBInspectable var haveBottomBar:Bool?
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.textContainer.lineFragmentPadding = 0
}
func addBottomBar(){
bottomBorder.frame = CGRectMake(0.0, self.frame.size.height - 1, self.frame.size.width, 1.0);
bottomBorder.backgroundColor = UIColor.grayColor().CGColor
self.layer.addSublayer(bottomBorder)
}
override func becomeFirstResponder() -> Bool {
let shouldBecomeFirstResponder = super.becomeFirstResponder()
bottomBorder.backgroundColor = shouldBecomeFirstResponder ? Constant.ui_applicationMainColor.CGColor : Constant.ui_applicationMainColor.CGColor
return shouldBecomeFirstResponder
}
override func resignFirstResponder() -> Bool {
let shouldResignFirstResponder = super.resignFirstResponder()
bottomBorder.backgroundColor = shouldResignFirstResponder ? UIColor.grayColor().CGColor : Constant.ui_applicationMainColor.CGColor
return shouldResignFirstResponder
}
override func layoutSubviews() {
super.layoutSubviews()
if let font = self.font {
self.font = GFFont.fontForDefaultFontName(font.fontName, size: font.pointSize)
} else {
self.font = UIFont.systemFontOfSize(12)
}
bottomBorder.backgroundColor = UIColor.grayColor().CGColor
}
}