【代碼筆記】點評內容,代碼筆記點評
一,。
二,工程圖。
三,代碼。
ViewController.h
#import <UIKit/UIKit.h>@interface ViewController : UIViewController<UITextViewDelegate>{ //評論內容 UITextView *commentTextView;}@end
ViewController.m
#import "ViewController.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. //初始化點評內容 [self addCommentView]; }#pragma -mark -functions//初始化點評內容-(void)addCommentView{ //點評內容 commentTextView=[[UITextView alloc]initWithFrame:CGRectMake(50, 180, 300, 90)]; commentTextView.text=@"親,您對商戶感覺如何,環境怎樣,服務態度如何。(500字元內)"; commentTextView.font=[UIFont systemFontOfSize:14]; commentTextView.backgroundColor=[UIColor redColor]; commentTextView.delegate=self; [self.view addSubview:commentTextView];}#pragma mark - UITextView Delegate Methods-(BOOL)textViewShouldBeginEditing:(UITextView *)textView{ if ([textView.text isEqualToString:@"親,您對商戶感覺如何,環境怎樣,服務態度如何。(500字元內)"]) { textView.text=@""; } return YES;}-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{ if ([text isEqualToString:@"\n"]) { [textView resignFirstResponder]; return NO; } return YES;}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}