Created
May 20, 2017 22:52
-
-
Save illescasDaniel/c1a97d0fae8e6cd1ff127bd399671ecd to your computer and use it in GitHub Desktop.
UITextView Center text Vertically
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // UITextView+Extension.swift | |
| // | |
| // Created by Daniel Illescas Romero on 21/05/2017. | |
| // | |
| import UIKit | |
| extension UITextView { | |
| /// Modifies the top content inset to center the text vertically. | |
| /// | |
| /// Use KVO on the UITextView contentSize and call this method inside observeValue(forKeyPath:of:change:context:) | |
| func alignTextVerticallyInContainer() { | |
| var topCorrect = (self.bounds.size.height - self.contentSize.height * self.zoomScale) / 2 | |
| topCorrect = topCorrect < 0.0 ? 0.0 : topCorrect; | |
| self.contentInset.top = topCorrect | |
| } | |
| } |
Author
I am sorry. I just saw this code, copied, pasted it to give it a try and
didn't read that. I thought, if the snippet works, I will read all about
tools which were used inside the snippet, but if it doesn't work, what's
the deal to read that text, if the snippet doesn't work?! I am sorry, man.
You make me realize, that I need to read all about new code snippet as a
piece of technology if I want to use it. Sorry again and thank you for this
lesson :) Have a great day!
@illescasDaniel
…On Thu, Oct 10, 2019, 21:44 Daniel Illescas Romero ***@***.***> wrote:
Did you “use KVO on the UITextView contentSize and call this method inside
observeValue(forKeyPath:of:change:context:)”?
@kyzominskiy <https://github.com/kyzominskiy>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<https://gist.github.com/c1a97d0fae8e6cd1ff127bd399671ecd?email_source=notifications&email_token=ANGHI3FUWVUIALXQAKERT3DQN5ZXVA5CNFSM4I7QU4D2YY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAF2IX6#gistcomment-3051903>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ANGHI3FKQ23RGDBNZRGGSSLQN5ZXVANCNFSM4I7QU4DQ>
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Did you “use KVO on the UITextView contentSize and call this method inside observeValue(forKeyPath:of:change:context:)”?
@kyzominskiy