Skip to content

Instantly share code, notes, and snippets.

@agiletalk
Created May 4, 2011 18:12
Show Gist options
  • Save agiletalk/955696 to your computer and use it in GitHub Desktop.
Save agiletalk/955696 to your computer and use it in GitHub Desktop.
UITextView Tutorial
//
// UITextViewTutorialViewController.h
// UITextViewTutorial
//
// Created by chanju Jeon on 11. 5. 4..
// Copyright 2011 Talk on :Play. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UITextViewTutorialViewController : UIViewController <UITextViewDelegate> {
UITextView *textView;
UILabel *countLabel;
}
@property (nonatomic, retain) IBOutlet UITextView *textView;
@property (nonatomic, retain) IBOutlet UILabel *countLabel;
@end
//
// UITextViewTutorialViewController.m
// UITextViewTutorial
//
// Created by chanju Jeon on 11. 5. 4..
// Copyright 2011 Talk on :Play. All rights reserved.
//
// 생략
#pragma - Textview delegate
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
// Any new character added is passed in as the "text" parameter
if([text isEqualToString:@"\n"]) {
// Be sure to test for equality using the "isEqualToString" message
[textView resignFirstResponder];
// Return FALSE so that the final '\n' character doesn't get added
return FALSE;
}
// For any other character return TRUE so that the text gets added to the view
return TRUE;
}
- (void)textViewDidChange:(UITextView *)textView {
countLabel.text = [NSString stringWithFormat:@"%d", [textView.text length]];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment