// // PJViewController.m // jiaPei // // Created by EchoShacolee on 2017/2/17. // Copyright © 2017年 JCZ. All rights reserved. // #import "PJViewController.h" #import "RatingBar.h" @interface PJViewController () { CGRect _frame; } @property (weak, nonatomic) IBOutlet UIImageView *headImgV; @property (weak, nonatomic) IBOutlet UIView *ratingBar; @property (weak, nonatomic) IBOutlet UILabel *ratingLab; @property (weak, nonatomic) IBOutlet UIView *lableView; @property (weak, nonatomic) IBOutlet UITextView *textView; @end @implementation PJViewController - (void)viewDidLoad { [super viewDidLoad]; [self setTitle:@"评论详情"]; self.navigationController.navigationBar.translucent = NO; [self configNavigationBarDismissNav]; [self myInit]; } - (IBAction)nextBtnClick:(id)sender { ShowMsg(@"let's go!"); if (_textView.text.length == 0) { ShowMsg(@"请给出评价再走"); } } -(void)myInit { NSString * filePtah = [[NSBundle mainBundle] pathForResource:@"zz" ofType:@"jpg"]; _headImgV.image = [UIImage imageWithContentsOfFile:filePtah]; RatingBar * starBar = [[RatingBar alloc]initWithFrame:_ratingBar.bounds Flag:YES]; starBar.starNumber =5; starBar.enable = YES; [starBar changeStarNumberBlock:^(NSString *starNumString) { NSLog(@"%@", starNumString); }]; [_ratingBar addSubview:starBar]; // switch (ratin) { // case <#constant#>: // <#statements#> // break; // // default: // break; // } //textView //定义一个toolBar UIToolbar * topView = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, kSize.width, 50)]; //设置style [topView setBarStyle:UIBarStyleDefault]; //定义两个flexibleSpace的button,放在toolBar上,这样完成按钮就会在最右边 UIBarButtonItem * button1 =[[UIBarButtonItem alloc]initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target:self action:nil]; UIBarButtonItem * button2 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target:self action:nil]; //定义完成按钮 UIBarButtonItem * doneButton = [[UIBarButtonItem alloc]initWithTitle:@"完成" style:UIBarButtonItemStyleDone target:self action:@selector(endBtnClick)]; //在toolBar上加上这些按钮 NSArray * buttonsArray = [NSArray arrayWithObjects:button1,button2,doneButton,nil]; [topView setItems:buttonsArray]; [_textView setInputAccessoryView:topView]; } #pragma mark - UITextViewDelegate协议中的方法 - (void)textViewDidBeginEditing:(UITextView *)textView { if ([_textView.text isEqualToString:@"教练哪些地方让你印象深刻?快和大家分享一下吧"]) { _textView.text = @""; } _textView.frame = CGRectMake(10, 20, kSize.width-20, kSize.height*0.5 - 50); _textView.font = [UIFont systemFontOfSize:Font17]; //@lee 写下面的上面的就不起作用了。why // _endBtn = [UIButton buttonWithType:UIButtonTypeSystem]; // _endBtn.frame = CGRectMake(kSize.width-110, 10+kSize.height*0.5 - 50, 80, 40); // [_endBtn addTarget:self action:@selector(endBtnClick) forControlEvents:UIControlEventTouchUpInside]; // [self.view addSubview:_endBtn]; } - (void)textViewDidEndEditing:(UITextView *)textView { if (_textView.text.length == 0) { _textView.text = @"教练哪些地方让你印象深刻?快和大家分享一下吧"; } _textView.frame = _frame; _textView.font = [UIFont systemFontOfSize:15]; } -(void)endBtnClick { [_textView resignFirstResponder]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)viewDidAppear:(BOOL)animated{ _frame = _textView.frame; } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end