ViewController.h
------------------
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController<UITextViewDelegate>{
UITextView *commentTf;
}
@end
ViewController.m
-----------------
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
commentTf = [[UITextView alloc] initWithFrame:CGRectMake(7, 40, 306, 85)];
[commentTf setFont:[UIFont systemFontOfSize:17.0]];
[commentTf setTextColor:[UIColor lightGrayColor]];
[commentTf setAutocapitalizationType:UITextAutocapitalizationTypeSentences];
commentTf.delegate=self;
commentTf.text =@"Write your comment here";
[self.view addSubview:commentTf];
}
- (BOOL) textViewShouldBeginEditing:(UITextView *)textView
{
if (commentTf.textColor == [UIColor lightGrayColor]) {
commentTf.text = @"";
commentTf.textColor = [UIColor blackColor];
}
return YES;
}
-(void) textViewDidChange:(UITextView *)textView
{
if(commentTf.text.length == 0){
commentTf.textColor = [UIColor lightGrayColor];
commentTf.text = @"Write your comment here";
[commentTf resignFirstResponder];
}
}
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
if([text isEqualToString:@"\n"]) {
[textView resignFirstResponder];
if(commentTf.text.length == 0){
commentTf.textColor = [UIColor lightGrayColor];
commentTf.text = @"Write your comment here";
[commentTf resignFirstResponder];
}
return NO;
}
return YES;
}
@end
------------------
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController<UITextViewDelegate>{
UITextView *commentTf;
}
@end
ViewController.m
-----------------
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
commentTf = [[UITextView alloc] initWithFrame:CGRectMake(7, 40, 306, 85)];
[commentTf setFont:[UIFont systemFontOfSize:17.0]];
[commentTf setTextColor:[UIColor lightGrayColor]];
[commentTf setAutocapitalizationType:UITextAutocapitalizationTypeSentences];
commentTf.delegate=self;
commentTf.text =@"Write your comment here";
[self.view addSubview:commentTf];
}
- (BOOL) textViewShouldBeginEditing:(UITextView *)textView
{
if (commentTf.textColor == [UIColor lightGrayColor]) {
commentTf.text = @"";
commentTf.textColor = [UIColor blackColor];
}
return YES;
}
-(void) textViewDidChange:(UITextView *)textView
{
if(commentTf.text.length == 0){
commentTf.textColor = [UIColor lightGrayColor];
commentTf.text = @"Write your comment here";
[commentTf resignFirstResponder];
}
}
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
if([text isEqualToString:@"\n"]) {
[textView resignFirstResponder];
if(commentTf.text.length == 0){
commentTf.textColor = [UIColor lightGrayColor];
commentTf.text = @"Write your comment here";
[commentTf resignFirstResponder];
}
return NO;
}
return YES;
}
@end
think your blog is pretty good which have some useful information. Thanks for sharing us!
ReplyDeleteYour contents are too simple to read and easy to understand.
-------------------------------------------------------------------------------
iPhone App Development :: && ::Mobile and Web Application Development