UITextField Function Based on UITextView (with placeholder function)
Preface
First of all, while customizing UITextView, we need to figure out the difference between UITextField and UITextView, which are the functions of UITextView, but UITextField does not, or UITextField does not. next let's take a look at their respective features and their differences.
What is the difference between UITextField and UITextView?
UITextVIew is more flexible than UITextField in View attributes. The most important thing is that UITextFiled can set the attributes of InputText. UITextFiled allows you to set SecureInput and other related attributes. UITextView can only implement basic text input functions, and almost cannot set content attributes. UITextView supports multi-line input, while UITextField can only be single-line input. UITextView inherits from UIScrollView and UITextField inherits from UIView. Therefore, we can regard UITextView as the enhanced version of UITextField. UITextField has a placeholder while UITextVIew does not.
After clarifying the differences, how can I enable UITextVIew to have all UITextField functions? Such as placeholders? Next, let's focus on the specific implementation and look at the Code:
Step 2
Step 1: Create a project
Step 2: Customize a UIView + Extension
1. h file
. M file
Step 3: Customize a view that inherits from UITextView.
1. h file
2. What is the actual stuffing in the m file? Http://www.bkjia.com/kf/yidong/wp/ "target =" _ blank "class =" keylink "> WPGJyIC8 + coding + yoteisuHNqNaqvODM/coding + DQo8aW1nIGFsdD0 =" here write picture description "src =" http://www.bkjia.com/uploads/allimg/160422/04113230K-6.png "title = "\" />
2) implementation of various functional functions
3) override-(void) layoutSubviews Method
Step 4: Implement ViewController. m
3. Effect
Summary
In summary, a custom UITextView is implemented.