HelpDownScrollView.m 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //
  2. // ActionScrollView.m
  3. // VclustersGemini
  4. //
  5. // Created by APPLE on 2020/4/26.
  6. // Copyright © 2020 APPLE. All rights reserved.
  7. //
  8. #import "HelpDownScrollView.h"
  9. #import "UIView+View.h"
  10. @implementation HelpDownScrollView
  11. @synthesize presedDelegate;
  12. - (id)initWithFrame:(CGRect)frame withImageAry:(NSArray *)imageAry tilteAry:(NSArray *)titleAry numberOfLine:(NSInteger)numberOfLine
  13. {
  14. self = [super initWithFrame:frame];
  15. if (self)
  16. {
  17. [self setBackgroundColor:[UIColor clearColor]];
  18. [self drawAnyViewWithImageAry:imageAry tilteAry:titleAry numberOfLine:numberOfLine];
  19. }
  20. return self;
  21. }
  22. - (void)drawAnyViewWithImageAry:(NSArray *)imageAry tilteAry:(NSArray *)titleAry numberOfLine:(NSInteger)numberOfLine
  23. {
  24. NSInteger lines = titleAry.count/numberOfLine + ((titleAry.count%numberOfLine == 0)?0:1);
  25. CGFloat w_btn = self.width / numberOfLine;
  26. CGFloat h_btn = (self.frame.size.height - 15.f)/lines;
  27. for (NSInteger nFori = 0; nFori < [imageAry count]; nFori++)
  28. {
  29. /*x,y计算*/
  30. NSInteger xnumber = nFori%numberOfLine;
  31. NSInteger ynumber = nFori/numberOfLine;
  32. UIButton *tempBtn = [[UIButton alloc] initWithFrame:CGRectMake(xnumber*w_btn, 15.f + ynumber*h_btn, w_btn, h_btn)];
  33. [tempBtn setBackgroundColor:[UIColor clearColor]];
  34. [tempBtn setImage:[UIImage imageNamed:[imageAry objectAtIndex:nFori]] forState:(UIControlStateNormal)];
  35. [tempBtn setTag:nFori + 1];
  36. [tempBtn setContentMode:(UIViewContentModeScaleAspectFill)];
  37. tempBtn.clipsToBounds = YES;
  38. [tempBtn setTitle:[titleAry objectAtIndex:nFori] forState:(UIControlStateNormal)];
  39. [tempBtn addTarget:self action:@selector(actionPressed:) forControlEvents:(UIControlEventTouchUpInside)];
  40. [tempBtn.titleLabel setFont:[UIFont systemFontOfSize:13.f]];
  41. [tempBtn setTitleColor:HW0A132BColor forState:(UIControlStateNormal)];
  42. [tempBtn setTitleEdgeInsets:UIEdgeInsetsMake(tempBtn.imageView.frame.size.height+10,-tempBtn.imageView.frame.size.width+2, 0.0,0.0)];
  43. [tempBtn setImageEdgeInsets:UIEdgeInsetsMake(-tempBtn.bounds.size.width/4+15, tempBtn.bounds.size.width/4-2, tempBtn.titleLabel.bounds.size.height, -tempBtn.bounds.size.width/4)];
  44. [self addSubview:tempBtn];
  45. }
  46. [self setContentSize:CGSizeMake(self.width, self.height)];
  47. }
  48. - (void)actionPressed:(id)sender
  49. {
  50. NSInteger tag = ((UIButton *)sender).tag;
  51. NSInteger index = tag - 1;
  52. if ([presedDelegate respondsToSelector:@selector(helpDownScrollViewBePressed:withIndex:)])
  53. {
  54. [presedDelegate helpDownScrollViewBePressed:sender withIndex:index];
  55. }
  56. }
  57. @end