You may encounter a variety of effects when using Uitextview, for example, in front of the first line of Uitextview the hint text, and after the text entered in the hint after the word, in the input before the default text, the input process the default text will disappear hidden, the specific implementation code as follows:
#import "UItextviewSuoJinViewController.h"
@interface Uitextviewsuojinviewcontroller () <uitextviewdelegate>{
Opinion content
Uitextview *contenttextview;
Cover a uilable on top of the Uitextview.
Uilabel *promptlabel;
}
@end
@implementation Uitextviewsuojinviewcontroller
-(void) Viewdidload {
[Super Viewdidload];
Self.view.backgroundColor = [Uicolor Graycolor];
Opinion content
Contenttextview = [[Uitextview alloc] Initwithframe:cgrectmake (0, Kheaderheight, Kscreenwidth, 86)];
Contenttextview.font = font (13);
Contenttextview.delegate = self;
[Self.view Addsubview:contenttextview];
Uilabel *contentlabel = [[Uilabel alloc] Initwithframe:cgrectmake (14, 0, 60, 35)];
Contentlabel.font = font (13);
Contentlabel.text = @ "* Your opinion";
[Contenttextview Addsubview:contentlabel];
Cover a uilable on top of the Uitextview.
Promptlabel = [[Uilabel alloc] init];
Promptlabel.frame =cgrectmake (5,5,200,25);
Promptlabel.text = @ "Please input comments";
promptlabel.enabled = NO;
Promptlabel.backgroundcolor = [Uicolor Clearcolor];
Promptlabel.font = [Uifont systemfontofsize:13];
Promptlabel.textcolor = RGB (245, 245, 245);
[Contenttextview Addsubview:promptlabel];
Change the color of the pentagram
nsmutableattributedstring *contentstr = [[Nsmutableattributedstring alloc] initWithString:contentLabel.text];
[Contentstr addattribute:nsforegroundcolorattributename Value:[uicolor Redcolor] Range:NSMakeRange (0, 1)];
Contentlabel.attributedtext = Contentstr;
}
Proxy method of #pragma mark-uitextview
-(void) Textviewdidchange: (Uitextview *) textview{
if (TextView.text.length = = 0) {
Promptlabel.hidden = NO;
}else{
Promptlabel.hidden = YES;
}
First Line Indent
Nsmutableparagraphstyle *paragraphstyle = [[Nsmutableparagraphstyle alloc] init];
paragraphstyle.linespacing = 3; Line spacing
Paragraphstyle.maximumlineheight = 60; /** Maximum line Height * *
Paragraphstyle.firstlineheadindent = 93.F; /** First Line Indent width * *
Paragraphstyle.alignment = nstextalignmentjustified;
Nsdictionary *attributes = @{
Nsfontattributename:[uifont Systemfontofsize:13],
Nsparagraphstyleattributename:paragraphstyle
};
Textview.attributedtext = [[Nsattributedstring alloc] InitWithString:textView.text attributes:attributes];
}
You can copy the code to your own project file to see the effect.