JXShareViewController.m 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. //
  2. // JXShareViewController.m
  3. // share
  4. //
  5. // Created by 1 on 2019/3/20.
  6. // Copyright © 2019年 Reese. All rights reserved.
  7. //
  8. #import "JXShareViewController.h"
  9. #import "JXHttpRequet.h"
  10. @interface JXShareViewController () <UITextViewDelegate>
  11. @end
  12. @implementation JXShareViewController
  13. - (void)viewDidLoad {
  14. [super viewDidLoad];
  15. UIView *baseView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT)];
  16. baseView.backgroundColor = HEXCOLOR(0xF2F2F2);
  17. [self.view addSubview:baseView];
  18. UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, JX_SCREEN_TOP)];
  19. headView.backgroundColor = [UIColor whiteColor];
  20. [baseView addSubview:headView];
  21. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(8, JX_SCREEN_TOP - 40, 31, 31)];
  22. [btn setImage:[UIImage imageNamed:@"share_back"] forState:UIControlStateNormal];
  23. [btn addTarget:self action:@selector(actionQuit) forControlEvents:UIControlEventTouchUpInside];
  24. [headView addSubview:btn];
  25. UIButton *send = [[UIButton alloc] initWithFrame:CGRectMake(JX_SCREEN_WIDTH - 60, JX_SCREEN_TOP - 35, 40, 20)];
  26. [send setTitle:@"发送" forState:UIControlStateNormal];
  27. [send setTitleColor:HEXCOLOR(0x31AD2A) forState:UIControlStateNormal];
  28. [send addTarget:self action:@selector(onSend) forControlEvents:UIControlEventTouchUpInside];
  29. [headView addSubview:send];
  30. UILabel* p = [[UILabel alloc]initWithFrame:CGRectMake(60, JX_SCREEN_TOP - 35, JX_SCREEN_WIDTH-60*2, 20)];
  31. p.backgroundColor = [UIColor clearColor];
  32. p.textAlignment = NSTextAlignmentCenter;
  33. p.text = @"分享给社交圈";
  34. p.font = [UIFont boldSystemFontOfSize:18.0];
  35. [headView addSubview:p];
  36. UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, JX_SCREEN_TOP-LINE_WH, JX_SCREEN_WIDTH, LINE_WH)];
  37. line.backgroundColor = [UIColor lightGrayColor];
  38. [headView addSubview:line];
  39. UIView *bigView = [[UIView alloc] initWithFrame:CGRectMake(0, JX_SCREEN_TOP, JX_SCREEN_WIDTH, 300)];
  40. bigView.backgroundColor = [UIColor whiteColor];
  41. [baseView addSubview:bigView];
  42. self.textView = [[UITextView alloc] initWithFrame:CGRectMake(20, 10, JX_SCREEN_WIDTH-40, 100)];
  43. self.textView.delegate = self;
  44. self.textView.textColor = [UIColor lightGrayColor];
  45. self.textView.font = SYSFONT(17);
  46. self.textView.text = @"这一刻的想法..";
  47. [bigView addSubview:self.textView];
  48. CGFloat b = self.image.size.height/self.image.size.width;
  49. UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(20, CGRectGetMaxY(self.textView.frame)+20, JX_SCREEN_WIDTH/5, JX_SCREEN_WIDTH/5*b)];
  50. imageV.image = self.image;
  51. [bigView addSubview:imageV];
  52. CGRect frame = bigView.frame;
  53. frame.size.height = CGRectGetMaxY(imageV.frame)+20;
  54. bigView.frame = frame;
  55. }
  56. - (void)onSend {
  57. if (self.delegate && [self.delegate respondsToSelector:@selector(sendToLifeCircleSucces:)]) {
  58. [self.delegate sendToLifeCircleSucces:self];
  59. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  60. [self actionQuit];
  61. });
  62. }
  63. }
  64. - (void)textViewDidChangeSelection:(UITextView *)textView {
  65. //如果是提示内容,光标放置开始位置
  66. if (textView.textColor==[UIColor lightGrayColor]) {
  67. NSRange range;
  68. range.location = 0;
  69. range.length = 0;
  70. textView.selectedRange = range;
  71. }
  72. }
  73. - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
  74. //如果不是delete响应,当前是提示信息,修改其属性
  75. if (![text isEqualToString:@""] && textView.textColor == [UIColor lightGrayColor]) {
  76. textView.text = @"";//置空
  77. textView.textColor = HEXCOLOR(0x595959);
  78. }
  79. return YES;
  80. }
  81. - (void)textViewDidChange:(UITextView *)textView {
  82. static CGFloat maxHeight =100.0f;
  83. //防止输入时在中文后输入英文过长直接中文和英文换行
  84. if ([textView.text isEqualToString:@""]) {
  85. textView.textColor = [UIColor lightGrayColor];
  86. textView.text = @"这一刻的想法..";
  87. }
  88. CGRect frame = textView.frame;
  89. CGSize constraintSize = CGSizeMake(JX_SCREEN_WIDTH-40, MAXFLOAT);
  90. CGSize size = [textView sizeThatFits:constraintSize];
  91. if (size.height >= maxHeight)
  92. {
  93. size.height = maxHeight;
  94. textView.scrollEnabled = YES; // 允许滚动
  95. }
  96. else
  97. {
  98. textView.scrollEnabled = NO; // 不允许滚动
  99. }
  100. textView.frame = CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, size.height);
  101. }
  102. - (void)actionQuit {
  103. [self dismissViewControllerAnimated:NO completion:nil];
  104. }
  105. @end