DetailTitleView.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. //
  2. // DetailTitleView.m
  3. // TheoryNetwork
  4. //
  5. // Created by tederen on 2019/9/26.
  6. // Copyright © 2019 tederen. All rights reserved.
  7. //
  8. #import "DetailTitleView.h"
  9. #import "DocumentModel.h"
  10. #import "ZYCTool.h"
  11. @interface DetailTitleView ()
  12. @property (nonatomic, strong) UILabel *titleLabel;
  13. @property (nonatomic, strong) UILabel *timeLabel;
  14. /// 来源 : 新华出版社
  15. @property (nonatomic, strong) UILabel *buninessLabel;
  16. @property (nonatomic, strong) UIView *verticalLine;
  17. @property (nonatomic, strong) UILabel *readLab;
  18. @property (nonatomic, strong) UIImageView *checkImgVi;
  19. @property (nonatomic, strong) UILabel *readNumLab;
  20. @property (nonatomic, strong) UILabel *authorLab;
  21. @property (nonatomic, strong) UILabel *refereeLab;
  22. @property (nonatomic, strong) UILabel *shoujianrenlab;
  23. @property (nonatomic, strong) UILabel *haveReadNumberlab;
  24. @property (nonatomic, strong) UILabel *noReadNumberlab;
  25. @property (nonatomic, strong) TDButton *noticButton;
  26. @property (nonatomic, strong) UIView *lineViewA;
  27. @property (nonatomic, strong) UIView *lineViewB;
  28. @property (nonatomic, strong) UIView *lineViewC;
  29. @end
  30. @implementation DetailTitleView
  31. - (instancetype)init
  32. {
  33. self = [super init];
  34. if (self) {
  35. [self addSubview:self.titleLabel];
  36. [self addSubview:self.timeLabel];
  37. [self addSubview:self.buninessLabel];
  38. [self addSubview:self.checkImgVi];
  39. [self addSubview:self.readLab];
  40. [self addSubview:self.readNumLab];
  41. [self addSubview:self.authorLab];
  42. [self addSubview:self.refereeLab];
  43. [self addSubview:self.shoujianrenlab];
  44. [self addSubview:self.haveReadNumberlab];
  45. [self addSubview:self.noticButton];
  46. [self addSubview:self.noReadNumberlab];
  47. }
  48. return self;
  49. }
  50. - (void)loadTitleModel:(Item *)model {
  51. //
  52. CGFloat topMargin = 14.f;
  53. CGFloat leftMargin = 22.f;
  54. _titleLabel.text = model.Title;
  55. _titleLabel.textColor = [UIColor hexStringToColor:@"0A0A0A"];
  56. _titleLabel.font = [UIFont systemFontOfSize:23.f];
  57. [ZYCTool setLabelSpace:_titleLabel withSpace:10.f withFont:_titleLabel.font];
  58. CGSize titleSize = [_titleLabel sizeThatFits:CGSizeMake(kGXScreenWidth-20*2, MAXFLOAT)];
  59. _titleLabel.frame = CGRectMake(leftMargin, topMargin, titleSize.width, titleSize.height);
  60. topMargin += titleSize.height;
  61. topMargin += 21.f;
  62. [_authorLab mas_makeConstraints:^(MASConstraintMaker *make) {
  63. make.left.mas_equalTo(leftMargin);
  64. make.top.mas_equalTo(topMargin);
  65. make.width.mas_lessThanOrEqualTo(60);
  66. }];
  67. if (!ISEmptyNumber(model.Author)) {
  68. _authorLab.text = model.Author;
  69. // 竖线
  70. UIView *lineViewA = [UIView new];
  71. lineViewA.backgroundColor = kColorFromRGB(0xe5e5e5);
  72. [self addSubview:lineViewA];
  73. [lineViewA mas_makeConstraints:^(MASConstraintMaker *make) {
  74. make.left.equalTo(self.authorLab.mas_right).offset(12);
  75. make.top.equalTo(self.authorLab).offset(2);
  76. make.height.mas_equalTo(12.5);
  77. make.width.mas_equalTo(1);
  78. }];
  79. self.lineViewA = lineViewA;
  80. } else {
  81. _authorLab.hidden = YES;
  82. }
  83. [self.buninessLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  84. make.left.equalTo(_authorLab.mas_right).offset(ISEmptyNumber(model.Author) ? 0 : 24);
  85. make.top.equalTo(self.authorLab);
  86. make.width.mas_lessThanOrEqualTo(60);
  87. }];
  88. if (!ISEmptyNumber(model.Source)) {
  89. _buninessLabel.text = model.Source;
  90. UIView *lineViewB = [UIView new];
  91. lineViewB.backgroundColor = kColorFromRGB(0xe5e5e5);
  92. [self addSubview:lineViewB];
  93. [lineViewB mas_makeConstraints:^(MASConstraintMaker *make) {
  94. make.left.equalTo(_buninessLabel.mas_right).offset(12);
  95. make.top.equalTo(_authorLab).offset(2);
  96. make.height.mas_equalTo(12.5);
  97. make.width.mas_equalTo(1);
  98. }];
  99. self.lineViewB = lineViewB;
  100. } else {
  101. _buninessLabel.hidden = YES;
  102. }
  103. _timeLabel.text = ISEmptyString(model.AddDate)?@"暂无":[ZYCTool yearMonthAndDay:model.AddDate];
  104. [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  105. make.left.equalTo(_buninessLabel.mas_right).offset(ISEmptyNumber(model.Source) ? 0 : 24);
  106. make.top.equalTo(self.authorLab);
  107. make.width.mas_lessThanOrEqualTo(84);
  108. }];
  109. if (!ISEmptyNumber(model.AddDate)) {
  110. UIView *lineViewC = [UIView new];
  111. lineViewC.backgroundColor = kColorFromRGB(0xe5e5e5);
  112. [self addSubview:lineViewC];
  113. [lineViewC mas_makeConstraints:^(MASConstraintMaker *make) {
  114. make.left.equalTo(self.timeLabel.mas_right).offset(12);
  115. make.top.equalTo(_authorLab).offset(2);
  116. make.height.mas_equalTo(12.5);
  117. make.width.mas_equalTo(1);
  118. }];
  119. self.lineViewC = lineViewC;
  120. }else{
  121. self.timeLabel.hidden = YES;
  122. }
  123. [self layoutIfNeeded];
  124. NSString *tmpStr = [NSString stringWithFormat:@"阅读:%@",@(model.ReadCount)];
  125. // 计算剩余宽度
  126. CGFloat maxWidth = kScreenWidth - CGRectGetMaxX(self.timeLabel.frame) - 10; // 22 右边距
  127. // 计算文字宽度
  128. CGFloat textWidth = [NSString sizeWith:CGSizeMake(MAXFLOAT, self.timeLabel.height) font:[UIFont systemFontOfSize:14.f] text:tmpStr].width;
  129. if (textWidth <= maxWidth) {
  130. // 放的下就一排显示
  131. self.readLab.text = tmpStr;
  132. } else {
  133. // 放不下就两排显示
  134. self.readLab.text = [NSString stringWithFormat:@"阅读:\n%@",@(model.ReadCount)];
  135. }
  136. [self.readLab mas_makeConstraints:^(MASConstraintMaker *make) {
  137. make.left.equalTo(self.timeLabel.mas_right).offset(ISEmptyNumber(model.AddDate) ? 0 : 24);
  138. make.top.equalTo(self.authorLab);
  139. make.width.mas_lessThanOrEqualTo(58);
  140. }];
  141. if (_authorLab.height > _buninessLabel.height) {
  142. topMargin += _authorLab.height;
  143. }else{
  144. topMargin += _buninessLabel.height;
  145. }
  146. topMargin += 14.0f;
  147. CGRect frame = self.frame;
  148. frame.size.height = topMargin;
  149. self.frame = frame;
  150. }
  151. - (void)loadTitleModel2:(Item *)model{
  152. // [self loadTitleModel:model];
  153. CGFloat topMargin = 14.f;
  154. CGFloat leftMargin = 22.f;
  155. CGFloat titleW = 10.f;
  156. _titleLabel.textColor = [UIColor hexStringToColor:@"0A0A0A"];
  157. _titleLabel.font = [UIFont systemFontOfSize:23.f];
  158. if (!ISEmptyString(model.Title)) {
  159. _titleLabel.text = model.Title;
  160. [ZYCTool setLabelSpace:_titleLabel withSpace:titleW withFont:_titleLabel.font];
  161. CGSize titleSize = [_titleLabel sizeThatFits:CGSizeMake(kGXScreenWidth-20*2, MAXFLOAT)];
  162. _titleLabel.frame = CGRectMake(leftMargin, topMargin, titleSize.width, titleSize.height);
  163. topMargin += titleSize.height;
  164. } else {
  165. _titleLabel.hidden = YES;
  166. }
  167. topMargin += 21.f;
  168. CGFloat MarginW = leftMargin;
  169. if (!ISEmptyNumber(model.Author)) {
  170. _authorLab.text = model.Author;
  171. CGSize authorSize = [_authorLab sizeThatFits:CGSizeZero];
  172. _authorLab.frame = CGRectMake(leftMargin, topMargin, authorSize.width, authorSize.height);
  173. } else {
  174. _authorLab.hidden = YES;
  175. self.lineViewA.hidden = YES;
  176. }
  177. if (!ISEmptyString(model.Source)) {
  178. _buninessLabel.text = model.Source;
  179. CGSize buninessSize = [_buninessLabel sizeThatFits:CGSizeZero];
  180. MarginW += _authorLab.width + 24;
  181. _buninessLabel.frame = CGRectMake(MarginW, topMargin, buninessSize.width, buninessSize.height);
  182. }else{
  183. _buninessLabel.hidden = YES;
  184. self.lineViewB.hidden = YES;
  185. }
  186. if (!ISEmptyString(model.AddDate)) {
  187. _timeLabel.text = [ZYCTool yearMonthAndDay:model.AddDate];
  188. CGSize timeSize = [_timeLabel sizeThatFits:CGSizeZero];
  189. MarginW += _buninessLabel.width + 24;
  190. _timeLabel.frame = CGRectMake(MarginW, topMargin, timeSize.width, timeSize.height);
  191. }else{
  192. _timeLabel.hidden = YES;
  193. self.lineViewC.hidden = YES;
  194. }
  195. _readLab.text = @"阅读:";
  196. CGSize readSize = [_readLab sizeThatFits:CGSizeZero];
  197. _readLab.frame = CGRectMake(MarginW + 12, topMargin ,readSize.width,readSize.height);
  198. _readNumLab.text = [NSString stringWithFormat:@"%ld",(long)model.ReadCount];
  199. CGSize checkSize = [_readNumLab sizeThatFits:CGSizeZero];
  200. _readNumLab.frame = CGRectMake(CGRectGetMaxX(_readLab.frame), topMargin, checkSize.width, checkSize.height);
  201. // _timeLabel.text = ISEmptyString(model.lastEditDate)?@"暂无":model.lastEditDate;
  202. // CGSize timeSize = [_timeLabel sizeThatFits:CGSizeZero];
  203. // _timeLabel.frame = CGRectMake(20, topMargin, timeSize.width, timeSize.height);
  204. // _checkImgVi.frame = CGRectMake(20 + timeSize.width + 20, topMargin + (timeSize.height - 9)/2.0 , 13, 9);
  205. // _readNumLab.text = [NSString stringWithFormat:@"%@", ISEmptyNumber(model.hits)?@0:model.hits];
  206. // CGSize checkSize = [_readNumLab sizeThatFits:CGSizeZero];
  207. // _readNumLab.frame = CGRectMake(20 + timeSize.width + 20 + 13 + 2, topMargin, checkSize.width, checkSize.height);
  208. //
  209. topMargin += _authorLab.height;
  210. topMargin += 8.f;
  211. self.checkImgVi.hidden = YES;
  212. self.readLab.hidden = YES;
  213. CGSize shoujianSize = [_shoujianrenlab sizeThatFits:CGSizeMake(kGXScreenWidth-20*2, MAXFLOAT)];
  214. _shoujianrenlab.frame = CGRectMake(22.f, topMargin, shoujianSize.width, shoujianSize.height);
  215. topMargin += shoujianSize.height;
  216. topMargin += 8.f;
  217. CGSize haveReadSize = [_haveReadNumberlab sizeThatFits:CGSizeMake(kGXScreenWidth-20*2, MAXFLOAT)];
  218. _haveReadNumberlab.frame = CGRectMake(22.f, topMargin, haveReadSize.width, haveReadSize.height);
  219. CGSize haveReadBtnSize = [_noticButton sizeThatFits:CGSizeMake(kGXScreenWidth-20*2, MAXFLOAT)];
  220. _noticButton.frame = CGRectMake(CGRectGetMaxX(self.haveReadNumberlab.frame), topMargin, haveReadBtnSize.width,17);
  221. CGSize noReadSize = [_noReadNumberlab sizeThatFits:CGSizeMake(kGXScreenWidth-20*2, MAXFLOAT)];
  222. _noReadNumberlab.frame = CGRectMake(22.f+haveReadSize.width+haveReadBtnSize.width, topMargin, noReadSize.width, noReadSize.height);
  223. topMargin += haveReadSize.height;
  224. topMargin += 14.f;
  225. CGRect frame = self.frame;
  226. frame.size.height = topMargin;
  227. self.frame = frame;
  228. }
  229. #pragma mark - setter
  230. - (UILabel *)titleLabel {
  231. if (!_titleLabel) {
  232. _titleLabel = [UILabel new];
  233. _titleLabel.numberOfLines = 0;
  234. _titleLabel.font = [UIFont systemFontOfSize:23.f];
  235. _titleLabel.textColor = UIColorHex(0A0A0A);
  236. }
  237. return _titleLabel;
  238. }
  239. - (UILabel *)timeLabel {
  240. if (!_timeLabel) {
  241. _timeLabel = [UILabel new];
  242. _timeLabel.font = [UIFont systemFontOfSize:14.f];
  243. _timeLabel.textColor = UIColorHex(999999);
  244. _timeLabel.textAlignment = NSTextAlignmentCenter;
  245. _timeLabel.numberOfLines = 0;
  246. }
  247. return _timeLabel;
  248. }
  249. - (UILabel *)buninessLabel {
  250. if (!_buninessLabel) {
  251. _buninessLabel = [UILabel new];
  252. _buninessLabel.font = [UIFont systemFontOfSize:14.f];
  253. _buninessLabel.textColor = UIColorHex(999999);
  254. _buninessLabel.numberOfLines = 0;
  255. _buninessLabel.textAlignment = NSTextAlignmentCenter;
  256. }
  257. return _buninessLabel;
  258. }
  259. - (UIImageView *)checkImgVi {
  260. if (!_checkImgVi) {
  261. _checkImgVi = [[UIImageView alloc] init];
  262. [_checkImgVi setImage:IMG(@"icon_browse")];
  263. }
  264. return _checkImgVi;
  265. }
  266. - (UILabel *)readLab{
  267. if (!_readLab){
  268. _readLab = [UILabel new];
  269. _readLab.font = [UIFont systemFontOfSize:14.f];
  270. _readLab.textColor = UIColorHex(999999);
  271. _readLab.numberOfLines = 0;
  272. _readLab.textAlignment = NSTextAlignmentCenter;
  273. }
  274. return _readLab;
  275. }
  276. - (UILabel *)readNumLab {
  277. if (!_readNumLab) {
  278. _readNumLab = [UILabel new];
  279. _readNumLab.font = [UIFont systemFontOfSize:14.f];
  280. _readNumLab.textColor = UIColorHex(999999);
  281. }
  282. return _readNumLab;
  283. }
  284. - (UILabel *)authorLab {
  285. if (!_authorLab) {
  286. _authorLab = [UILabel new];
  287. _authorLab.font = [UIFont systemFontOfSize:14.f];
  288. _authorLab.textColor = UIColorHex(999999);
  289. _authorLab.numberOfLines = 0;
  290. _authorLab.textAlignment = NSTextAlignmentCenter;
  291. }
  292. return _authorLab;
  293. }
  294. - (UILabel *)refereeLab {
  295. if (!_refereeLab) {
  296. _refereeLab = [UILabel new];
  297. _refereeLab.font = [UIFont systemFontOfSize:14.f];
  298. _refereeLab.textColor = UIColorHex(999999);
  299. }
  300. return _refereeLab;
  301. }
  302. - (UILabel *)shoujianrenlab{
  303. if (!_shoujianrenlab) {
  304. _shoujianrenlab = [UILabel new];
  305. _shoujianrenlab.font = [UIFont systemFontOfSize:14.f];
  306. _shoujianrenlab.textColor = UIColorHex(999999);
  307. _shoujianrenlab.text = @"收件人:编辑部、重要人员、广西出版传媒部";
  308. }
  309. return _shoujianrenlab;
  310. }
  311. - (UILabel *)haveReadNumberlab{
  312. if (!_haveReadNumberlab) {
  313. _haveReadNumberlab = [UILabel new];
  314. _haveReadNumberlab.font = [UIFont systemFontOfSize:14.f];
  315. _haveReadNumberlab.textColor = UIColorHex(999999);
  316. _haveReadNumberlab.text = @"已读:";
  317. }
  318. return _haveReadNumberlab;
  319. }
  320. - (TDButton *)noticButton{
  321. if (!_noticButton) {
  322. _noticButton = [[TDButton alloc]init];
  323. [_noticButton setTitle:@"542" forState:UIControlStateNormal];
  324. [_noticButton setTitleColor:UIColorHex(1F87DB) forState:UIControlStateNormal];
  325. [_noticButton addTarget:self action:@selector(didReadNumHander:) forControlEvents:UIControlEventTouchDown];
  326. [[_noticButton titleLabel] setFont:[UIFont systemFontOfSize:14.f]];
  327. [[_noticButton titleLabel] setTextAlignment:NSTextAlignmentRight];
  328. }
  329. return _noticButton;
  330. }
  331. - (UILabel *)noReadNumberlab{
  332. if (!_noReadNumberlab) {
  333. _noReadNumberlab = [UILabel new];
  334. _noReadNumberlab.text = @"/687";
  335. _noReadNumberlab.textColor = k9;
  336. _noReadNumberlab.font = [UIFont systemFontOfSize:14.f];
  337. }
  338. return _noReadNumberlab;
  339. }
  340. - (void)didReadNumHander:(TDButton *)sender{
  341. if ([self.delegate respondsToSelector:@selector(didDetailTitlefunctionTouch:)]) {
  342. [self.delegate didDetailTitlefunctionTouch:sender];
  343. }
  344. }
  345. @end