iOS development-The use of feedback Uitextview

Source: Internet
Author: User

@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

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.