(分享)简单圆角UITextView

UITextView has square edges, and looks ugly compared to a UITextField!

Screen shot 2010-06-06 at 20.22.29

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:

  1. Add a UITextField to your View and put a UITextView on top of it.
  2. Decide on how high you want your UITextView and resize it.
  3. Give the UITextField a tag of 999 (or whatever you want) (hit CMD-1 to bring up the attributes inspector to do this).
  4. Save the .xib file and then right click the file > Open With > Other > TextEdit
  5. Search for your tag, 999, and in the same 
  6. You need to change 31 to the same height as your UITextView and then save the .xib file in TextEdit
  7. 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
  8. You should now see a tall UITextField behind your UITextView. Make sure your UITextView has a transparent background!
原文地址:https://www.cnblogs.com/woainilsr/p/2368517.html