PJViewController.m 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. //
  2. // PJViewController.m
  3. // jiaPei
  4. //
  5. // Created by EchoShacolee on 2017/2/17.
  6. // Copyright © 2017年 JCZ. All rights reserved.
  7. //
  8. #import "PJViewController.h"
  9. #import "RatingBar.h"
  10. @interface PJViewController ()<UITextViewDelegate>
  11. {
  12. CGRect _frame;
  13. }
  14. @property (weak, nonatomic) IBOutlet UIImageView *headImgV;
  15. @property (weak, nonatomic) IBOutlet UIView *ratingBar;
  16. @property (weak, nonatomic) IBOutlet UILabel *ratingLab;
  17. @property (weak, nonatomic) IBOutlet UIView *lableView;
  18. @property (weak, nonatomic) IBOutlet UITextView *textView;
  19. @end
  20. @implementation PJViewController
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. [self setTitle:@"评论详情"];
  24. self.navigationController.navigationBar.translucent = NO;
  25. [self configNavigationBarDismissNav];
  26. [self myInit];
  27. }
  28. - (IBAction)nextBtnClick:(id)sender {
  29. ShowMsg(@"let's go!");
  30. if (_textView.text.length == 0) {
  31. ShowMsg(@"请给出评价再走");
  32. }
  33. }
  34. -(void)myInit
  35. {
  36. NSString * filePtah = [[NSBundle mainBundle] pathForResource:@"zz" ofType:@"jpg"];
  37. _headImgV.image = [UIImage imageWithContentsOfFile:filePtah];
  38. RatingBar * starBar = [[RatingBar alloc]initWithFrame:_ratingBar.bounds Flag:YES];
  39. starBar.starNumber =5;
  40. starBar.enable = YES;
  41. [starBar changeStarNumberBlock:^(NSString *starNumString) {
  42. NSLog(@"%@", starNumString);
  43. }];
  44. [_ratingBar addSubview:starBar];
  45. // switch (ratin) {
  46. // case <#constant#>:
  47. // <#statements#>
  48. // break;
  49. //
  50. // default:
  51. // break;
  52. // }
  53. //textView
  54. //定义一个toolBar
  55. UIToolbar * topView = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, kSize.width, 50)];
  56. //设置style
  57. [topView setBarStyle:UIBarStyleDefault];
  58. //定义两个flexibleSpace的button,放在toolBar上,这样完成按钮就会在最右边
  59. UIBarButtonItem * button1 =[[UIBarButtonItem alloc]initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target:self action:nil];
  60. UIBarButtonItem * button2 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target:self action:nil];
  61. //定义完成按钮
  62. UIBarButtonItem * doneButton = [[UIBarButtonItem alloc]initWithTitle:@"完成" style:UIBarButtonItemStyleDone target:self action:@selector(endBtnClick)];
  63. //在toolBar上加上这些按钮
  64. NSArray * buttonsArray = [NSArray arrayWithObjects:button1,button2,doneButton,nil];
  65. [topView setItems:buttonsArray];
  66. [_textView setInputAccessoryView:topView];
  67. }
  68. #pragma mark - UITextViewDelegate协议中的方法
  69. - (void)textViewDidBeginEditing:(UITextView *)textView
  70. {
  71. if ([_textView.text isEqualToString:@"教练哪些地方让你印象深刻?快和大家分享一下吧"]) {
  72. _textView.text = @"";
  73. }
  74. _textView.frame = CGRectMake(10, 20, kSize.width-20, kSize.height*0.5 - 50);
  75. _textView.font = [UIFont systemFontOfSize:Font17];
  76. //@lee 写下面的上面的就不起作用了。why
  77. // _endBtn = [UIButton buttonWithType:UIButtonTypeSystem];
  78. // _endBtn.frame = CGRectMake(kSize.width-110, 10+kSize.height*0.5 - 50, 80, 40);
  79. // [_endBtn addTarget:self action:@selector(endBtnClick) forControlEvents:UIControlEventTouchUpInside];
  80. // [self.view addSubview:_endBtn];
  81. }
  82. - (void)textViewDidEndEditing:(UITextView *)textView
  83. {
  84. if (_textView.text.length == 0) {
  85. _textView.text = @"教练哪些地方让你印象深刻?快和大家分享一下吧";
  86. }
  87. _textView.frame = _frame;
  88. _textView.font = [UIFont systemFontOfSize:15];
  89. }
  90. -(void)endBtnClick
  91. {
  92. [_textView resignFirstResponder];
  93. }
  94. - (void)didReceiveMemoryWarning {
  95. [super didReceiveMemoryWarning];
  96. // Dispose of any resources that can be recreated.
  97. }
  98. - (void)viewDidAppear:(BOOL)animated{
  99. _frame = _textView.frame;
  100. }
  101. /*
  102. #pragma mark - Navigation
  103. // In a storyboard-based application, you will often want to do a little preparation before navigation
  104. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  105. // Get the new view controller using [segue destinationViewController].
  106. // Pass the selected object to the new view controller.
  107. }
  108. */
  109. @end