(分享)简单圆角UITextView
UITextView has square edges, and looks ugly compared to a UITextField!
Unfortunately, there isn’t an option to give the UITextView a nice border. There are various ways to do this, such as creating your own background image for the UITextView, but I have found a relatively easy way to do it – and one that anyone without photoshop skills can achieve.
I achieve it by placing a UITextField behind the UITextView. However, in InterfaceBuilder you can’t change the height of a UITextField, so you have to edit the .xib file in Text Edit to change its height.
Here are the steps you need to do:
- Add a UITextField to your View and put a UITextView on top of it.
- Decide on how high you want your UITextView and resize it.
- Give the UITextField a tag of 999 (or whatever you want) (hit CMD-1 to bring up the attributes inspector to do this).
- Save the .xib file and then right click the file > Open With > Other > TextEdit
- Search for your tag, 999, and in the same
- You need to change 31 to the same height as your UITextView and then save the .xib file in TextEdit
- When you return to IB it will tell you the document has been modified, click Revert
1 <object class="IBUITextField" id="154341485">
2 <reference key="NSNextResponder" ref="774585933"/>
3 <int key="NSvFlags">292</int>
4 <string key="NSFrame">{{25, 199}, {275, 31}}</string> THIS IS THE LINE THAT YOU NEED TO EDIT.... CHANGE 31 TO THE HEIGHT OF YOUR UITEXTVIEW
5 <reference key="NSSuperview" ref="774585933"/>
6 <reference key="IBUIBackgroundColor" ref="157267157"/>
7 <bool key="IBUIOpaque">NO</bool>
8 <bool key="IBUIClearsContextBeforeDrawing">NO</bool>
9 <int key="IBUITag">999</int>THIS IS THE TAG YOU CHOSE TO HELP YOU FIND THIS SECTION IN THE XIB FILE - You should now see a tall UITextField behind your UITextView. Make sure your UITextView has a transparent background!