UITextField Function Based on UITextView (with placeholder function)

Source: Internet
Author: User

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.
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.