{"action":"created","issue":{"url":"https://api.github.com/repos/startupthekid/VerticalTextView/issues/3","labels_url":"https://api.github.com/repos/startupthekid/VerticalTextView/issues/3/labels{/name}","comments_url":"https://api.github.com/repos/startupthekid/VerticalTextView/issues/3/comments","events_url":"https://api.github.com/repos/startupthekid/VerticalTextView/issues/3/events","html_url":"https://github.com/startupthekid/VerticalTextView/issues/3","id":105474917,"number":3,"title":"VerticalTextView hangs when text contains a newline character","user":{"login":"izkrivera","id":477592,"avatar_url":"https://avatars.githubusercontent.com/u/477592?v=3","gravatar_id":"","url":"https://api.github.com/users/izkrivera","html_url":"https://github.com/izkrivera","followers_url":"https://api.github.com/users/izkrivera/followers","following_url":"https://api.github.com/users/izkrivera/following{/other_user}","gists_url":"https://api.github.com/users/izkrivera/gists{/gist_id}","starred_url":"https://api.github.com/users/izkrivera/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/izkrivera/subscriptions","organizations_url":"https://api.github.com/users/izkrivera/orgs","repos_url":"https://api.github.com/users/izkrivera/repos","events_url":"https://api.github.com/users/izkrivera/events{/privacy}","received_events_url":"https://api.github.com/users/izkrivera/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-09-08T21:39:19Z","updated_at":"2015-09-09T14:45:39Z","closed_at":null,"body":"Came across this bug when trying to use this class in a project. If you set the text programmatically and it contains a newline character in the middle of the string, the textview will hang the application. If the newline is at the last character of the string, it will work fine.\r\n\r\nExample:\r\n\r\n    @IBOutlet weak var textView: VerticalAlignTextView! {\r\n\t\tdidSet {\r\n\t\t\ttextView.text = \"One, Two, Three\\n\" // This works fine\r\n\t\t\ttextView.text = \"One, Two, Three,\\nFour, Five\" // This hangs the application!\r\n\t\t}\r\n\t}\r\n\r\nPlacing printlns in your code like this:\r\n\r\n    //override contentSize property and observe using didSet\r\n\toverride var contentSize: CGSize {\r\n\t\tdidSet {\r\n\t\t\tprintln(\"1 text: \\\"\\(self.text)\\\"\")\r\n\t\t\tlet textView = self\r\n\t\t\tlet height = textView.bounds.size.height\r\n\t\t\tlet contentHeight = textView.sizeThatFits(CGSize(width: textView.frame.size.width, height: CGFloat(FLT_MAX))).height\r\n\t\t\tvar topCorrect: CGFloat = 0.0\r\n\t\t\t\r\n\t\t\tprintln(\"2\")\r\n\t\t\tswitch(self.verticalAlignment){\r\n\t\t\tcase .Top:\r\n\t\t\t\t\r\n\t\t\t\tprintln(\"3 TOP\")\r\n\t\t\t\ttextView.contentOffset = CGPointZero //set content offset to top\r\n\t\t\tcase .Middle:\r\n\t\t\t\tprintln(\"3 MIDDLE\")\r\n\t\t\t\ttopCorrect = (height - contentHeight * textView.zoomScale)/2.0\r\n\t\t\t\ttopCorrect = topCorrect < 0 ? 0 : topCorrect\r\n\t\t\t\ttextView.contentOffset = CGPoint(x: 0, y: -topCorrect)\r\n\t\t\tcase .Bottom:\r\n\t\t\t\tprintln(\"3 BOTTOM\")\r\n\t\t\t\ttopCorrect = textView.bounds.size.height - contentHeight\r\n\t\t\t\ttopCorrect = topCorrect < 0 ? 0 : topCorrect\r\n\t\t\t\ttextView.contentOffset = CGPoint(x: 0, y: -topCorrect)\r\n\t\t\t}\r\n\t\t\tif contentHeight >= height { //if the contentSize is greater than the height\r\n\t\t\t\ttopCorrect = contentHeight - height //set the contentOffset to be the\r\n\t\t\t\ttopCorrect = topCorrect < 0 ? 0 : topCorrect //contentHeight - height of textView\r\n\t\t\t\ttextView.contentOffset = CGPoint(x: 0, y: topCorrect)\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\nFor a TOP aligned view I get the console trace:\r\n\r\n    1 text: \"\"\r\n    2\r\n    3 TOP\r\n    1 text: \"One, Two, Three,\r\n    Four, Five\"\r\n    2\r\n    3 TOP\r\n    1 text: \"One, Two, Three,\r\n    Four, Five\"\r\n    2\r\n    3 TOP\r\n    1 text: \"One, Two, Three,\r\n    Four, Five\"\r\n    2\r\n    3 TOP\r\n    1 text: \"One, Two, Three,\r\n    Four, Five\"\r\n    2\r\n    3 TOP\r\n    1 text: \"One, Two, Three,\r\n    Four, Five\"\r\n    2\r\n    3 TOP\r\n    .... infinitum..."},"comment":{"url":"https://api.github.com/repos/startupthekid/VerticalTextView/issues/comments/138933655","html_url":"https://github.com/startupthekid/VerticalTextView/issues/3#issuecomment-138933655","issue_url":"https://api.github.com/repos/startupthekid/VerticalTextView/issues/3","id":138933655,"user":{"login":"izkrivera","id":477592,"avatar_url":"https://avatars.githubusercontent.com/u/477592?v=3","gravatar_id":"","url":"https://api.github.com/users/izkrivera","html_url":"https://github.com/izkrivera","followers_url":"https://api.github.com/users/izkrivera/followers","following_url":"https://api.github.com/users/izkrivera/following{/other_user}","gists_url":"https://api.github.com/users/izkrivera/gists{/gist_id}","starred_url":"https://api.github.com/users/izkrivera/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/izkrivera/subscriptions","organizations_url":"https://api.github.com/users/izkrivera/orgs","repos_url":"https://api.github.com/users/izkrivera/repos","events_url":"https://api.github.com/users/izkrivera/events{/privacy}","received_events_url":"https://api.github.com/users/izkrivera/received_events","type":"User","site_admin":false},"created_at":"2015-09-09T14:45:39Z","updated_at":"2015-09-09T14:45:39Z","body":"Thanks! I will test today and let you know..."}}