---------------- Uitextfield limits the input length ------------
.
Class to inherit uitextfielddelegate.
.
Uitextfield * content = [uitextfield
Alloc] initwithframe:
Cgrectmake (X, Y, width, height)];
Content. textcolor = [uicolor
Graycolor];
Content. font = [uifont
Systemfontofsize: 17];
Content. Delegate =
Self; // specify your delegate
.
# Pragma mark-
# Pragma mark uitextfielddelegate
-(Bool) textfield :( uitextfield *) textfield shouldchangecharactersinrange :( nsange) range replacementstring :( nsstring
*) String
{
If (range. Location>
20)
{
Uialertview * alertview = [uialertview
Alloc] initwithtitle: Nil
Message: @ "length cannot exceed 20"
Delegate: Nil
Cancelbuttontitle: @ "close"
Otherbuttontitles: Nil];
[Alertview
Show];
[Alertview
Release];
Return
No;
}
Return yes;
}
---------------- Uitextview limits the input length ------------
.
<Uitextviewdelegate>
.
Inputtextview. Delegate = self;
// Specify the delegate
.
# Pragma mark-
# Pragma mark textview
-(Bool) textview :( uitextview *) textview shouldchangetextinrange :( nsange) range replacementtext :( nsstring *) text {
If ([text length] = 0 ){
Return yes;
}
If ([textview. Text length] + range. length> = 140 ){
Return no;
}
Return yes;
}
-(Void) textviewdidchange :( uitextview *) textview {
// [Nsstring stringwithformat: @ "% d", 140-[textview. Text length];
// The length that can be entered.
}