I want to center the text vertically inside a big UITextView
that fills the whole screen - so that when there's little of text, say a couple of words, it is centered by height.
It's not a question about centering the text (a property that can be found in IB) but about putting the text vertically right in the middle of UITextView
if the text is short, so there are no blank areas in the UITextView
.
Can this be done? Thanks in advance!
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- Could I create “Call” button in HTML 5 IPhone appl
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- Xcode: Is there a way to change line spacing (UI L
- Unable to process app at this time due to a genera
I have also this problem and I solved it with a
UITableViewCell
withUITextView
. I created method in a customUITableViewCell
subclass, propertystatusTextView
:And call this method in methods:
This solution worked for me with no issues, you can try it.
Swift 3:
Because UIKit is not KVO compliant, I decided to implement this as a subclass of
UITextView
which updates whenever thecontentSize
changes.It's a slightly modified version of Carlos's answer which sets the
contentInset
instead of thecontentOffset
. In addition to being compatible with iOS 9, it also seems to be less buggy on iOS 8.4.UITextView+VerticalAlignment.h
UITextView+VerticalAlignment.m
Auto-layout solution: