@interface Dmfeedbackviewcontroller () <UITextViewDelegate,UIAlertViewDelegate>
@property (nonatomic, strong) Uitextview *feedbacktextview;//feedback input Box
@property (nonatomic, strong) UILabel *mostlabel;//can also be entered
Submitted by @property (Nonatomic, strong) UIButton *submitbt;//
@property (nonatomic, strong) UILabel *feedbacknotelabel;//Enter feedback here
@end
Determine if the user entered text, Feedbacknotelabel text display or hide
Use notifications to resolve:
[[Nsnotificationcenter defaultcenter]addobserver:self selector: @selector (textviewchange) Name: Uitextviewtextdidchangenotification Object:nil];
Release notification
-(void) dealloc
{
Debugmethod ();
[[Nsnotificationcenter defaultcenter]removeobserver:self name:uitextviewtextdidchangenotification Object:nil];
}
-(void) Textviewchange
{
if (_feedbacktextview.text.length== 0) {
[_feedbacknotelabel Sethidden:no];
}else
{
[_feedbacknotelabel Sethidden:yes];
}
}
Due to the design needs, the Uitextview input box is very long, the submit button at the bottom, in order to facilitate the user experience, added drag is also a swipe gesture
Uipangesturerecognizer *pangesturerecognizer= [[Uipangesturerecognizer alloc] initwithtarget:self action: @selector ( Handlepangestures:)];
Pangesturerecognizer.minimumnumberoftouches = 1;
Pangesturerecognizer.maximumnumberoftouches = 5;
[Self.view Addgesturerecognizer:pangesturerecognizer];
#pragma mark-swipe the blank area to close the keyboard
-(void) Handlepangestures: (Uipangesturerecognizer *) sender{
[Self.view Endediting:yes];
}
# # #您最多还可以输入多个字的代理方法
-(BOOL) TextView: (Uitextview *) TextView Shouldchangetextinrange: (nsrange) Range Replacementtext: (NSString *) text
{
NSString *temp = [Textview.text stringbyreplacingcharactersinrange:range withstring:text];
if (temp.length== 0) {
Input text is 0, submit button touch event hidden
[_SUBMITBT Setbackgroundcolor:dmrgb (235, 235, 240)];
[_submitbt Settitlecolor:dmrgb (, Forstate:uicontrolstatenormal, ");
_submitbt.userinteractionenabled = NO;
}
Else
{
[_SUBMITBT Settitlecolor:[uicolor Whitecolor] forstate:uicontrolstatenormal];
_submitbt.backgroundcolor = [Uicolor colorwithred:65.0/255 green:109.0/255 blue:218.0/255 alpha:1];
_submitbt.userinteractionenabled = YES;
}
NSString *str = [NSString stringwithformat:@ "%lu", 100-temp.length];
_mostlabel.attributedtext =[self getstring:[nsstring stringwithformat:@ "You can enter up to%lu words", 100-temp.length] Withfontsize:dmfontsize14 Withtextcoler:dmrgb (153, 153, 153) Othertextcoler:dmrgb (237,) WithRange:NSMakeRange ( 8,str.length)];
if (temp.length >= 100) {//If the input exceeds the specified word count of 100, the input is no longer allowed
return NO;
}
return YES;
}
-(nsmutableattributedstring*) getString: (nsstring*) str withfontsize: (cgfloat) fontSize Withtextcoler: (Uicolor *) Color Othertextcoler: (Uicolor *) Othercolor Withrange: (nsrange) Strrange
{
nsmutableattributedstring *attristring = [[Nsmutableattributedstring alloc] initwithstring:str];
Nsrange mainrange=nsmakerange (0, str.length);
[Attristring setattributes: @{nsfontattributename: [Uifont systemfontofsize:fontsize],
Nsforegroundcolorattributename:color} Range:mainrange];
[Attristring setattributes: @{nsfontattributename: [Uifont systemfontofsize:fontsize],
Nsforegroundcolorattributename:othercolor} Range:strrange];
return attristring;
}
iOS development-The use of feedback Uitextview