First, set the line spacing of the TextView
1. If you just statically display the TextView content as the set line spacing, execute the following code:
//???? TextView Change the line spacing of the font?
???? Nsmutableparagraphstyle *paragraphstyle = [[Nsmutableparagraphstyle alloc] init];?
???? paragraphstyle.linespacing = line spacing for 10;//fonts?
?????
???? Nsdictionary *attributes = @{?
???????????????????????????????? Nsfontattributename:[uifont systemfontofsize:15],?
???????????????????????????????? Nsparagraphstyleattributename:paragraphstyle?
???????????????????????????????? };?
???? Textview.attributedtext = [[Nsattributedstring alloc] initwithstring:@ "Enter your Content" attributes:attributes];
?
2. If you want to dynamically change the line spacing as you enter it, you need to put the above code in the TextView delegate method
-(void) Textviewdidchange: (Uitextview *) TextView
{
? ? //? ? TextView changing the line spacing of a font
? ? Nsmutableparagraphstyle *paragraphstyle = [[Nsmutableparagraphstyle alloc] init];
? ? paragraphstyle.linespacing = line spacing for 20;//fonts
?? ?
? ? Nsdictionary *attributes = @{
?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Nsfontattributename:[uifont Systemfontofsize:15],
?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Nsparagraphstyleattributename:paragraphstyle
?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? };
? ? Textview.attributedtext = [[Nsattributedstring alloc] InitWithString:textView.text attributes:attributes];
?
}
?
First, set the placeholder of TextView
Uitextview on how to add similar to Uitextfield placeholder, in fact, add a Uilabel or Uitextview on Uitextview, if used uilable, A problem arises when placeholder's text is too long to break the line, and using Uitextview can effectively avoid this problem.
-(BOOL) TextView: (Uitextview *) TextView Shouldchangetextinrange: (nsrange) Range Replacementtext: (NSString *) text
{?? if (![ Text isequaltostring:@ ""])
? ? ? ? {
? ? ? ? ? ? _placeholderlabel.hidden = YES;
? ? ? ? }
?? ? if ([Text isequaltostring:@ ""] && range.location = = 0 && Range.length = = 1)
? ? ? ? {
? ? ? ? ? ? _placeholderlabel.hidden = NO;
? ? ? ? }
? ? return YES;
}
?
The description is as follows:
? (1) _placeholderlabel? is added to the uitextview behind the Uitextview,_placeholderlabel to ensure that the same as the real input box settings, the font is set to light gray, and then [_ Placeholderlabel Seteditable:no]; True input box to set the background color transparent, guaranteed to see the bottom of the _placeholderlabel.
? ? (2) [Text isequaltostring:@ ""] means the BACKSPACE key is entered
? ? (3) Range.location = = 0 && Range.length = = 1 indicates the first character entered
iOS development Uitextview, set TextView line spacing and placeholder