The first part of the goal effect
The goals to be achieved today are as follows:
The second part of theoretical knowledge
From the above image and our frequent use of Sina Weibo experience, a click on the text input box will be called out of the keyboard will have two controls, one is Uitxtfield and Uitextview, then choose which control is OK, before selecting the control, we first look at their differences
The above table can be found that Uitextview has no placeholder attribute, but Uitextfield has, but, Uitextfield can only display a line of text, and Uitextview can display any line of text, on the actual effect, We choose Uitextview, and rewrite some of its methods, for the purpose of this time, add two properties, placeholder and placeholdercolor can be. After the goal is determined, we create a new class Lhtextview, inherited from Uitextview,
It's header files such as
So how do you show placeholder? , here we take quart2d drawing technique, redraw this placeholder, implement this method in the. m file as
Since the two properties are declared in the header file, the setter method must be called when called, so we also rewrite these two setter methods in. m files,
In order to change the text and font size of TextView in real time, it is also possible to rewrite their setter method
Of course, we customize the control and definitely implement its initialization method:
In this case, the custom control method is finished.
The third part of the test effect
After the custom space of course need to test, read is not correct, in this method to modify placeholder and Placeholdercolor two properties
We modify its font size (font property) to test, and the results are as follows
Change the color to orange as follows
The above test can be found, even if the test pass it, and finally don't forget to remove the notice OH
Well, today's blog on this, speak poorly, welcome criticism or message exchange!
iOS Sina Weibo Uitextview package (temporarily excluding emoticons on keyboard)