YMInvitingPrizesSharePosterPopupView.m 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. //
  2. // YMInvitingPrizesSharePosterPopupView.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/3/15.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMInvitingPrizesSharePosterPopupView.h"
  9. #import "YMInvitingPrizesViewModel.h"
  10. @interface YMInvitingPrizesSharePosterPopupView ()<TYCyclePagerViewDataSource,TYCyclePagerViewDelegate>
  11. /// 邀请有奖VM
  12. @property (nonatomic, strong) YMInvitingPrizesViewModel *viewModel;
  13. /// 海报图
  14. @property (nonatomic, strong) TYCyclePagerView *posterView;
  15. /// 按钮视图
  16. @property (nonatomic, strong) UIView *buttonView;
  17. /// 复制链接按钮
  18. @property (nonatomic, strong) UIButton *copyLinkBtn;
  19. /// 切换模式按钮
  20. @property (nonatomic, strong) UIButton *switchModeBtn;
  21. /// 保存二维码按钮
  22. @property (nonatomic, strong) UIButton *saveQRCodeBtn;
  23. /// 是否反方向
  24. @property (nonatomic, assign) BOOL isReverseDirectionScroll;
  25. @end
  26. @implementation YMInvitingPrizesSharePosterPopupView
  27. - (void)ym_setupViews{
  28. self.frame = CGRectMake(0, 0, kFrameWidth, kFrameHeight - kYMNavHeight);
  29. [self addSubview:self.posterView];
  30. [self addSubview:self.buttonView];
  31. [self.buttonView addSubview:self.copyLinkBtn];
  32. [self.buttonView addSubview:self.switchModeBtn];
  33. [self.buttonView addSubview:self.saveQRCodeBtn];
  34. [self setNeedsUpdateConstraints];
  35. [self updateConstraintsIfNeeded];
  36. }
  37. - (void)updateConstraints{
  38. [self.posterView mas_makeConstraints:^(MASConstraintMaker *make) {
  39. make.top.equalTo(self);
  40. make.left.equalTo(self);
  41. make.right.equalTo(self);
  42. }];
  43. [self.buttonView mas_makeConstraints:^(MASConstraintMaker *make) {
  44. make.top.equalTo(self.posterView.mas_bottom).offset(adapt(40));
  45. make.left.equalTo(self);
  46. make.right.equalTo(self);
  47. make.bottom.equalTo(self);
  48. }];
  49. [self.copyLinkBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  50. make.centerY.equalTo(self.switchModeBtn.mas_centerY);
  51. make.right.equalTo(self.switchModeBtn.mas_left).offset(adapt(-15));
  52. make.size.mas_equalTo(CGSizeMake(adapt(120), adapt(120)));
  53. }];
  54. [self.switchModeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  55. make.centerX.equalTo(self.buttonView.mas_centerX);
  56. make.top.equalTo(self.buttonView).offset(adapt(20));
  57. make.bottom.equalTo(self.buttonView).offset(adapt(-20));
  58. make.size.mas_equalTo(CGSizeMake(adapt(120), adapt(120)));
  59. }];
  60. [self.saveQRCodeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  61. make.centerY.equalTo(self.switchModeBtn.mas_centerY);
  62. make.left.equalTo(self.switchModeBtn.mas_right).offset(adapt(15));
  63. make.size.mas_equalTo(CGSizeMake(adapt(120), adapt(120)));
  64. }];
  65. // NSArray *btnArr = @[self.copyLinkBtn,self.switchModeBtn,self.saveQRCodeBtn];
  66. //
  67. // // 实现masonry水平固定控件宽度方法
  68. // // axisType 横排还是竖排
  69. // // fixedSpacing 两个控件间隔
  70. // // leadSpacing 第一个控件与边缘的间隔
  71. // // tailSpacing 最后一个控件与边缘的间隔
  72. // [btnArr mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:adapt(15) leadSpacing:adapt(10) tailSpacing:adapt(10)];
  73. //
  74. // // 设置array的垂直方向的约束
  75. // [btnArr mas_makeConstraints:^(MASConstraintMaker *make) {
  76. // make.top.equalTo(self.buttonView).offset(adapt(20));
  77. // make.bottom.equalTo(self.buttonView).offset(adapt(-20));
  78. // make.height.mas_equalTo(adapt(120));
  79. // }];
  80. [super updateConstraints];
  81. }
  82. - (void)ym_bindViewModel:(YMInvitingPrizesViewModel *)viewModel{
  83. if (!viewModel) {
  84. return;
  85. }
  86. _viewModel = viewModel;
  87. @weakify(self);
  88. [[self.viewModel.refreshUISubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id result) {
  89. @strongify(self)
  90. [self.posterView reloadData];
  91. }];
  92. }
  93. #pragma mark - TYCyclePagerViewDataSource
  94. - (NSInteger)numberOfItemsInPagerView:(TYCyclePagerView *)pageView {
  95. return self.viewModel.posterDataArray.count;
  96. }
  97. - (UICollectionViewCell *)pagerView:(TYCyclePagerView *)pagerView cellForItemAtIndex:(NSInteger)index {
  98. YMInvitingPrizesSharePosterCell *cell = [pagerView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([YMInvitingPrizesSharePosterCell class]) forIndex:index];
  99. [cell ym_bindViewModel:self.viewModel.posterDataArray[index]];
  100. return cell;
  101. }
  102. /** banner样式*/
  103. - (TYCyclePagerViewLayout *)layoutForPagerView:(TYCyclePagerView *)pageView {
  104. TYCyclePagerViewLayout *layout = [[TYCyclePagerViewLayout alloc]init];
  105. layout.itemSize = CGSizeMake(adapt(285), adapt(393));
  106. layout.itemSpacing = adapt(50);
  107. layout.itemHorizontalCenter = YES;
  108. layout.scrollDirection = TYCyclePagerScrollDirectionHorizontal;
  109. return layout;
  110. }
  111. #pragma mark - TYCyclePagerViewDelegate
  112. /** pagerView当前展示*/
  113. - (void)pagerView:(TYCyclePagerView *)pageView didScrollFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex {
  114. if (toIndex == 0) {
  115. self.isReverseDirectionScroll = NO;
  116. }
  117. if (toIndex+1 == self.viewModel.posterDataArray.count) {
  118. self.isReverseDirectionScroll = YES;
  119. }
  120. }
  121. - (void)pagerView:(TYCyclePagerView *)pageView didSelectedItemCell:(__kindof UICollectionViewCell *)cell atIndex:(NSInteger)index{
  122. }
  123. - (void)pagerViewDidScroll:(TYCyclePagerView *)pageView{
  124. }
  125. /** pagerView将开始拖动*/
  126. - (void)pagerViewWillBeginDragging:(TYCyclePagerView *)pageView{
  127. }
  128. /** pagerView将开始减速*/
  129. - (void)pagerViewWillBeginDecelerating:(TYCyclePagerView *)pageView{
  130. }
  131. /** pagerView确认结束*/
  132. - (void)pagerViewDidEndDragging:(TYCyclePagerView *)pageView willDecelerate:(BOOL)decelerate{
  133. }
  134. /** pagerView确认减速*/
  135. - (void)pagerViewDidEndDecelerating:(TYCyclePagerView *)pageView{
  136. }
  137. /** pagerView将开始滚动动画*/
  138. - (void)pagerViewWillBeginScrollingAnimation:(TYCyclePagerView *)pageView{
  139. }
  140. /** pagerView确认结束滚动动画*/
  141. - (void)pagerViewDidEndScrollingAnimation:(TYCyclePagerView *)pageView{
  142. }
  143. - (void)switchModeScrollToItem{
  144. NSInteger currentIndex = self.posterView.curIndex;
  145. if (self.isReverseDirectionScroll) {
  146. currentIndex--;
  147. [self.posterView scrollToItemAtIndex:currentIndex animate:YES];
  148. } else {
  149. currentIndex++;
  150. [self.posterView scrollToItemAtIndex:currentIndex animate:YES];
  151. }
  152. }
  153. #pragma mark - 保存到相册
  154. - (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {
  155. if(error) {
  156. [ZCHUDHelper showTitle:@"保存图片失败"];
  157. }else {
  158. [ZCHUDHelper showTitle:@"保存图片成功"];
  159. }
  160. }
  161. - (UIImage *)getCurrentImage {
  162. UIImage *image = nil;
  163. YMInvitingPrizesSharePosterCell *cell = (YMInvitingPrizesSharePosterCell *)[self.posterView curIndexCell];
  164. if (cell.finishedLoad) {
  165. image = [cell cutImage:cell.baseView];
  166. } else {
  167. [ZCHUDHelper showTitle:@"请等待图片加载完成"];
  168. }
  169. return image;
  170. }
  171. - (TYCyclePagerView *)posterView{
  172. if (!_posterView) {
  173. _posterView = [[TYCyclePagerView alloc]init];
  174. _posterView.dataSource = self;
  175. _posterView.delegate = self;
  176. //无限滚动
  177. _posterView.isInfiniteLoop = NO;
  178. //自动轮播
  179. _posterView.autoScrollInterval = 0;
  180. [_posterView registerClass:[YMInvitingPrizesSharePosterCell class] forCellWithReuseIdentifier:NSStringFromClass([YMInvitingPrizesSharePosterCell class])];
  181. _posterView.userInteractionEnabled = YES;
  182. WS(weakSelf)
  183. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
  184. [_posterView addGestureRecognizer:tap];
  185. [[[tap rac_gestureSignal] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
  186. if (weakSelf.dismissBlock) {
  187. weakSelf.dismissBlock();
  188. }
  189. }];
  190. }
  191. return _posterView;
  192. }
  193. - (UIView *)buttonView{
  194. if (!_buttonView) {
  195. _buttonView = [[UIView alloc]init];
  196. _buttonView.backgroundColor = HexColorFromRGB(0xFFFFFF);
  197. [_buttonView addRectCorner:UIRectCornerTopLeft|UIRectCornerTopRight radius:adapt(10)];
  198. _buttonView.userInteractionEnabled = YES;
  199. WS(weakSelf)
  200. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
  201. [_buttonView addGestureRecognizer:tap];
  202. [[[tap rac_gestureSignal] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
  203. if (weakSelf.dismissBlock) {
  204. weakSelf.dismissBlock();
  205. }
  206. }];
  207. }
  208. return _buttonView;
  209. }
  210. - (UIButton *)copyLinkBtn {
  211. if(!_copyLinkBtn){
  212. _copyLinkBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  213. _copyLinkBtn.frame = CGRectMake(0,0,adapt(120),adapt(120));
  214. _copyLinkBtn.titleLabel.font = LCFont(12);
  215. [_copyLinkBtn setTitleColor:HexColorFromRGB(0x333333) forState:UIControlStateNormal];
  216. [_copyLinkBtn ym_imageLocationStyle:YMImageLocationStyleTop spacing:adapt(5) imageLocationBlock:^(UIButton * _Nonnull button) {
  217. [button setTitle:@"复制链接" forState:UIControlStateNormal];
  218. [button setImage:ImageByName(@"ym_inviting_prizes_share_poster_copy_link_icon") forState:UIControlStateNormal];
  219. }];
  220. WS(weakSelf)
  221. [[[_copyLinkBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
  222. UIPasteboard *pab = [UIPasteboard generalPasteboard];
  223. pab.string = weakSelf.viewModel.posterDataArray[0].qrCodeContent;
  224. if (pab == nil) {
  225. [ZCHUDHelper showTitle:@"复制失败"];
  226. }else{
  227. [ZCHUDHelper showTitle:@"已复制"];
  228. }
  229. }];
  230. }
  231. return _copyLinkBtn;
  232. }
  233. - (UIButton *)switchModeBtn {
  234. if(!_switchModeBtn){
  235. _switchModeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  236. _switchModeBtn.frame = CGRectMake(0,0,adapt(120),adapt(120));
  237. _switchModeBtn.titleLabel.font = LCFont(12);
  238. [_switchModeBtn setTitleColor:HexColorFromRGB(0x333333) forState:UIControlStateNormal];
  239. [_switchModeBtn ym_imageLocationStyle:YMImageLocationStyleTop spacing:adapt(5) imageLocationBlock:^(UIButton * _Nonnull button) {
  240. [button setTitle:@"切换模式" forState:UIControlStateNormal];
  241. [button setImage:ImageByName(@"ym_inviting_prizes_share_poster_switch_mode_icon") forState:UIControlStateNormal];
  242. }];
  243. WS(weakSelf)
  244. [[[_switchModeBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
  245. [weakSelf switchModeScrollToItem];
  246. }];
  247. }
  248. return _switchModeBtn;
  249. }
  250. - (UIButton *)saveQRCodeBtn {
  251. if(!_saveQRCodeBtn){
  252. _saveQRCodeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  253. _saveQRCodeBtn.frame = CGRectMake(0,0,adapt(120),adapt(120));
  254. _saveQRCodeBtn.titleLabel.font = LCFont(12);
  255. [_saveQRCodeBtn setTitleColor:HexColorFromRGB(0x333333) forState:UIControlStateNormal];
  256. [_saveQRCodeBtn ym_imageLocationStyle:YMImageLocationStyleTop spacing:adapt(5) imageLocationBlock:^(UIButton * _Nonnull button) {
  257. [button setTitle:@"保存二维码" forState:UIControlStateNormal];
  258. [button setImage:ImageByName(@"ym_inviting_prizes_share_poster_save_qr_code_icon") forState:UIControlStateNormal];
  259. }];
  260. WS(weakSelf)
  261. [[[_saveQRCodeBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
  262. UIImage *poster = [weakSelf getCurrentImage];
  263. if (poster == nil) {
  264. return;
  265. }
  266. NSData *imageData = UIImagePNGRepresentation(poster);
  267. UIImage *image = [UIImage imageWithData:imageData];
  268. UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
  269. }];
  270. }
  271. return _saveQRCodeBtn;
  272. }
  273. @end
  274. @interface YMInvitingPrizesSharePosterCell()
  275. /** 海报lVM*/
  276. @property (nonatomic, strong) YMInvitingPrizesSharePosterCellViewModel *viewModel;
  277. /** 完成加载*/
  278. @property (nonatomic, assign, readwrite) BOOL finishedLoad;
  279. /** 海报图片*/
  280. @property (nonatomic, strong) UIImageView *posterImage;
  281. /** 用户头像图片*/
  282. @property (nonatomic, strong) UIImageView *userAvatarImage;
  283. /** 用户昵称标签*/
  284. @property (nonatomic, strong) UILabel *userNicknameLb;
  285. /** 用户代码标签*/
  286. @property (nonatomic, strong) UILabel *userCodeLb;
  287. /** 二维码图片*/
  288. @property (nonatomic, strong) UIImageView *qrCodeImage;
  289. @end
  290. @implementation YMInvitingPrizesSharePosterCell
  291. - (void)ym_setupViews{
  292. [self.contentView addSubview:self.baseView];
  293. [self.baseView addSubview:self.posterImage];
  294. [self.baseView addSubview:self.userAvatarImage];
  295. [self.baseView addSubview:self.userNicknameLb];
  296. [self.baseView addSubview:self.userCodeLb];
  297. [self.baseView addSubview:self.qrCodeImage];
  298. [self setNeedsUpdateConstraints];
  299. [self updateConstraintsIfNeeded];
  300. }
  301. - (void)updateConstraints {
  302. [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
  303. make.top.equalTo(self.contentView);
  304. make.left.equalTo(self.contentView);
  305. make.right.equalTo(self.contentView);
  306. make.bottom.equalTo(self.contentView);
  307. }];
  308. [self.posterImage mas_makeConstraints:^(MASConstraintMaker *make) {
  309. make.top.equalTo(self.baseView);
  310. make.left.equalTo(self.baseView);
  311. make.right.equalTo(self.baseView);
  312. }];
  313. [self.userAvatarImage mas_makeConstraints:^(MASConstraintMaker *make) {
  314. make.top.equalTo(self.posterImage.mas_bottom).offset(adapt(30));
  315. make.left.equalTo(self.baseView).offset(adapt(30));
  316. make.width.height.mas_equalTo(adapt(60));
  317. make.bottom.equalTo(self.baseView).offset(adapt(-30));
  318. }];
  319. [self.userNicknameLb mas_makeConstraints:^(MASConstraintMaker *make) {
  320. make.bottom.equalTo(self.userAvatarImage.mas_centerY).offset(adapt(-5));
  321. make.left.equalTo(self.userAvatarImage.mas_right).offset(adapt(10));
  322. }];
  323. [self.userCodeLb mas_makeConstraints:^(MASConstraintMaker *make) {
  324. make.top.equalTo(self.userAvatarImage.mas_centerY).offset(adapt(5));
  325. make.left.equalTo(self.userAvatarImage.mas_right).offset(adapt(10));
  326. }];
  327. [self.qrCodeImage mas_makeConstraints:^(MASConstraintMaker *make) {
  328. make.centerY.equalTo(self.userAvatarImage).offset(adapt(0));
  329. make.right.equalTo(self.baseView).offset(adapt(-20));
  330. make.width.height.mas_equalTo(adapt(46));
  331. }];
  332. [super updateConstraints];
  333. }
  334. - (void)ym_bindViewModel:(YMInvitingPrizesSharePosterCellViewModel*)viewModel{
  335. if (!viewModel) {
  336. return;
  337. }
  338. _viewModel = viewModel;
  339. // [self.posterImage sd_setImageWithURL:[LCTools getImageUrlWithAddress:@""] placeholderImage:nil options:SDWebImageRetryFailed | SDWebImageHighPriority | SDWebImageProgressiveDownload | SDWebImageAvoidAutoSetImage | SDWebImageScaleDownLargeImages completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
  340. // self.finishedLoad = image ? YES : NO;
  341. // if (image && cacheType == SDImageCacheTypeNone) {
  342. // CATransition *transition = [CATransition animation];
  343. // transition.type = kCATransitionFade;
  344. // transition.duration = 0.3;
  345. // transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
  346. // [self.posterImage.layer addAnimation:transition forKey:nil];
  347. // }
  348. // }];
  349. self.finishedLoad = YES;
  350. self.posterImage.image = ImageByName(self.viewModel.posterUrl);
  351. //[self.userAvatarImage sd_setImageWithURL:[LCTools getImageUrlWithAddress:[LCSaveModel getUserModel].youpaipuserinfo.youpaipavatar]];
  352. self.userAvatarImage.image = [self createQRCodeWithData:self.viewModel.qrCodeContent size:adapt(120)];
  353. self.userNicknameLb.text = [LCSaveModel getUserModel].youpaipuserinfo.youpaipnickname;
  354. self.userCodeLb.text = stringFormat(@"用户号:%@",[LCSaveModel getUserModel].youpaipuserinfo.youpaipusercode);
  355. //UIImage *qrCode = [self createQRCodeWithData:self.viewModel.qrCodeContent size:adapt(100)];
  356. self.qrCodeImage.image = ImageByName(@"ym_inviting_prizes_share_app_icon");
  357. }
  358. - (UIImage *)cutImage {
  359. UIImage *imageRet = nil;
  360. int scale = [UIScreen mainScreen].scale;
  361. CGSize Ksize = CGSizeMake(self.posterImage.frame.size.width*scale, self.posterImage.frame.size.height*scale);
  362. // 传入的View.frame.size是0的话,直接返回nil,防止 UIGraphicsBeginImageContext() 传入0,导致崩溃
  363. if (CGSizeEqualToSize(Ksize, CGSizeZero)) {
  364. return nil;
  365. }
  366. UIGraphicsBeginImageContextWithOptions(Ksize, NO, scale);
  367. [self.posterImage.image drawInRect:CGRectMake(0,0, Ksize.width, Ksize.height)];
  368. imageRet = UIGraphicsGetImageFromCurrentImageContext();
  369. UIGraphicsEndImageContext();
  370. return imageRet;
  371. }
  372. - (UIImage *)cutImage:(UIView *)view {
  373. int scale = [UIScreen mainScreen].scale;
  374. CGSize shotSize = CGSizeMake(view.frame.size.width*scale, view.frame.size.height*scale);
  375. // 传入的View.frame.size是0的话,直接返回nil,防止 UIGraphicsBeginImageContext() 传入0,导致崩溃
  376. if (CGSizeEqualToSize(shotSize, CGSizeZero)) {
  377. return nil;
  378. }
  379. UIGraphicsBeginImageContextWithOptions(shotSize, NO, scale);
  380. [view.layer renderInContext:UIGraphicsGetCurrentContext()];
  381. UIImage *tempImage = UIGraphicsGetImageFromCurrentImageContext();
  382. UIGraphicsEndImageContext();
  383. CGImageRef imageRef = tempImage.CGImage;
  384. CGRect rect = CGRectMake(0,0, shotSize.width, shotSize.height);
  385. CGImageRef imageRefRect = CGImageCreateWithImageInRect(imageRef, rect);
  386. UIImage *image = [[UIImage alloc]initWithCGImage:imageRefRect];
  387. return image;
  388. }
  389. - (UIImage *)createQRCodeWithData:(NSString *)data size:(CGFloat)size{
  390. NSData *string_data = [data dataUsingEncoding:NSUTF8StringEncoding];
  391. // 1、二维码滤镜
  392. CIFilter *fileter = [CIFilter filterWithName:@"CIQRCodeGenerator"];
  393. [fileter setValue:string_data forKey:@"inputMessage"];
  394. /*
  395. L (低):可以纠正7%左右的错误
  396. M (中):可以纠正15%左右的错误
  397. Q (高):可以纠正25%左右的错误
  398. H (高):可以纠正30%左右的错误
  399. */
  400. [fileter setValue:@"H" forKey:@"inputCorrectionLevel"];
  401. CIImage *ciImage = fileter.outputImage;
  402. // 2、颜色滤镜
  403. CIFilter *color_filter = [CIFilter filterWithName:@"CIFalseColor"];
  404. [color_filter setValue:ciImage forKey:@"inputImage"];
  405. [color_filter setValue:[CIColor colorWithCGColor:HexColorFromRGB(0x000000).CGColor] forKey:@"inputColor0"];
  406. [color_filter setValue:[CIColor colorWithCGColor:HexColorFromRGB(0xFFFFFF).CGColor] forKey:@"inputColor1"];
  407. // 3、生成处理
  408. CIImage *outImage = color_filter.outputImage;
  409. CGFloat scale = size / outImage.extent.size.width;
  410. outImage = [outImage imageByApplyingTransform:CGAffineTransformMakeScale(scale, scale)];
  411. return [UIImage imageWithCIImage:outImage];
  412. }
  413. - (UIView *)baseView{
  414. if (!_baseView) {
  415. _baseView = [[UIView alloc]init];
  416. _baseView.backgroundColor = HexColorFromRGB(0xFFFFFF);
  417. [_baseView addRectCorner:UIRectCornerAllCorners radius:adapt(16)];
  418. }
  419. return _baseView;
  420. }
  421. - (UIImageView *)posterImage{
  422. if (!_posterImage) {
  423. _posterImage = [[UIImageView alloc]init];
  424. //_posterImage.contentMode = UIViewContentModeScaleAspectFit;
  425. }
  426. return _posterImage;
  427. }
  428. - (UIImageView *)userAvatarImage{
  429. if (!_userAvatarImage) {
  430. _userAvatarImage = [[UIImageView alloc]init];
  431. _userAvatarImage.contentMode = UIViewContentModeScaleAspectFit;
  432. }
  433. return _userAvatarImage;
  434. }
  435. - (UILabel *)userNicknameLb{
  436. if (!_userNicknameLb) {
  437. _userNicknameLb = [[UILabel alloc]init];
  438. _userNicknameLb.font = LCBoldFont(13);
  439. _userNicknameLb.textColor = HexColorFromRGB(0x333333);
  440. _userNicknameLb.textAlignment = NSTextAlignmentLeft;
  441. _userNicknameLb.text = @"*****";
  442. /**
  443. *抗拉伸 setContentHuggingPriority(值越高,越不容易拉伸)
  444. */
  445. [_userNicknameLb setContentHuggingPriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];
  446. /**
  447. *抗压缩 setContentCompressionResistancePriority(值越高,越不容易压缩)
  448. **/
  449. [_userNicknameLb setContentCompressionResistancePriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];
  450. }
  451. return _userNicknameLb;
  452. }
  453. - (UILabel *)userCodeLb{
  454. if (!_userCodeLb) {
  455. _userCodeLb = [[UILabel alloc]init];
  456. _userCodeLb.font = LCFont(12);
  457. _userCodeLb.textColor = HexColorFromRGB(0x666666);
  458. _userCodeLb.textAlignment = NSTextAlignmentLeft;
  459. _userCodeLb.text = @"*****";
  460. /**
  461. *抗拉伸 setContentHuggingPriority(值越高,越不容易拉伸)
  462. */
  463. [_userCodeLb setContentHuggingPriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];
  464. /**
  465. *抗压缩 setContentCompressionResistancePriority(值越高,越不容易压缩)
  466. **/
  467. [_userCodeLb setContentCompressionResistancePriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];
  468. }
  469. return _userCodeLb;
  470. }
  471. - (UIImageView *)qrCodeImage{
  472. if (!_qrCodeImage) {
  473. _qrCodeImage = [[UIImageView alloc]init];
  474. }
  475. return _qrCodeImage;
  476. }
  477. @end