CPDFImagePropertyCell.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. //
  2. // CPDFImagePropertyCell.m
  3. // compdfkit-tools
  4. //
  5. // THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
  6. // AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
  7. // UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
  8. //
  9. #import "CPDFImagePropertyCell.h"
  10. #import "CPDFDropDownMenu.h"
  11. #import "CPDFOpacitySliderView.h"
  12. #import <ComPDFKit/ComPDFKit.h>
  13. @interface CPDFImagePropertyCell()<CPDFDropDownMenuDelegate,CPDFOpacitySliderViewDelegate>
  14. @property (nonatomic, strong) CPDFDropDownMenu * menu;
  15. @property (weak, nonatomic) IBOutlet UISlider *transparencySlider;
  16. @property (nonatomic, strong) UILabel *rotateLabel;
  17. @property (nonatomic, strong) UILabel *transformLabel;
  18. @property (nonatomic, strong) UILabel *toolsLabel;
  19. @property (nonatomic, strong) UIButton * leftRotateBtn;
  20. @property (nonatomic, strong) UIButton * rightRotateBtn;
  21. @property (nonatomic, strong) UIView * transformView;
  22. @property (nonatomic, strong) UIButton * hBtn;
  23. @property (nonatomic, strong) UIButton * vBtn;
  24. @property (nonatomic, strong) CPDFOpacitySliderView * opacityView;
  25. @property (nonatomic, strong) UIButton * replaceBtn;
  26. @property (nonatomic, strong) UIButton * exportBtn;
  27. @property (nonatomic, strong) UIButton * cropBtn;
  28. @property (nonatomic, strong) UIView *transformSplitView;
  29. @end
  30. @implementation CPDFImagePropertyCell
  31. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  32. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  33. self.rotateLabel = [[UILabel alloc] init];
  34. self.rotateLabel.font = [UIFont systemFontOfSize:13];
  35. self.rotateLabel.text = NSLocalizedString(@"Rotate", nil);
  36. self.rotateLabel.textColor = [UIColor colorWithRed:153./255 green:153./255 blue:153./255 alpha:1.];
  37. [self.contentView addSubview:self.rotateLabel];
  38. self.leftRotateBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  39. [self.leftRotateBtn addTarget:self action:@selector(leftRotateAction:) forControlEvents:UIControlEventTouchUpInside];
  40. [self.leftRotateBtn setImage:[UIImage imageNamed:@"CPDFEditIRotate" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
  41. NSString * leftTitle = [NSString stringWithFormat:@" %@",NSLocalizedString(@"Left", nil)];
  42. [self.leftRotateBtn setTitle:leftTitle forState:UIControlStateNormal];
  43. [self.leftRotateBtn setTitleColor:[UIColor colorWithRed:67/255. green:71/255. blue:77/255. alpha:1.] forState:UIControlStateNormal];
  44. self.leftRotateBtn.titleLabel.font = [UIFont systemFontOfSize:14.];
  45. self.leftRotateBtn.layer.borderWidth = 1.;
  46. self.leftRotateBtn.layer.borderColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.1].CGColor;
  47. self.leftRotateBtn.backgroundColor = [UIColor whiteColor];
  48. [self addSubview:self.leftRotateBtn];
  49. self.rightRotateBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  50. [self.rightRotateBtn addTarget:self action:@selector(rightRotateAction:) forControlEvents:UIControlEventTouchUpInside];
  51. [self.rightRotateBtn setImage:[UIImage imageNamed:@"CPDFEditRRotate" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
  52. NSString * rightTitle = [NSString stringWithFormat:@" %@",NSLocalizedString(@"Right", nil)];
  53. [self.rightRotateBtn setTitle:rightTitle forState:UIControlStateNormal];
  54. [self.rightRotateBtn setTitleColor:[UIColor colorWithRed:67/255. green:71/255. blue:77/255. alpha:1.] forState:UIControlStateNormal];
  55. self.rightRotateBtn.titleLabel.font = [UIFont systemFontOfSize:14.];
  56. self.rightRotateBtn.layer.borderWidth = 1.;
  57. self.rightRotateBtn.layer.borderColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.1].CGColor;
  58. self.rightRotateBtn.backgroundColor = [UIColor whiteColor];
  59. [self addSubview:self.rightRotateBtn];
  60. self.transformLabel = [[UILabel alloc] init];
  61. self.transformLabel.font = [UIFont systemFontOfSize:13];
  62. self.transformLabel.text = NSLocalizedString(@"Transform", nil);
  63. self.transformLabel.textColor = [UIColor colorWithRed:153./255 green:153./255 blue:153./255 alpha:1.];
  64. [self.contentView addSubview:self.transformLabel];
  65. self.transformView = [[UIView alloc] init];
  66. self.transformView.layer.borderWidth = 1;
  67. self.transformView.layer.borderColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.2].CGColor;
  68. [self.contentView addSubview:self.transformView];
  69. self.vBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  70. [self.vBtn setImage:[UIImage imageNamed:@"CPDFEditVerticalFlip" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
  71. [self.vBtn addTarget:self action:@selector(verticalAction:) forControlEvents:UIControlEventTouchUpInside];
  72. self.hBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  73. [self.hBtn setImage:[UIImage imageNamed:@"CPDFEditHorizontalFlip" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
  74. [self.hBtn addTarget:self action:@selector(horizontalAction:) forControlEvents:UIControlEventTouchUpInside];
  75. [self.transformView addSubview:self.hBtn];
  76. [self.transformView addSubview:self.vBtn];
  77. self.opacityView = [[CPDFOpacitySliderView alloc] init];
  78. self.opacityView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  79. self.opacityView.titleLabel.text = NSLocalizedString(@"Opacity", nil);
  80. self.opacityView.titleLabel.font = [UIFont systemFontOfSize:13];
  81. self.opacityView.titleLabel.textColor = [UIColor colorWithRed:153./255 green:153./255 blue:153./255 alpha:1.];
  82. self.opacityView.startLabel.text = @"0";
  83. self.opacityView.defaultValue = 1;
  84. self.opacityView.bgColor = [UIColor clearColor];
  85. self.opacityView.delegate = self;
  86. [self.contentView addSubview:self.opacityView];
  87. self.toolsLabel = [[UILabel alloc] init];
  88. self.toolsLabel.font = [UIFont systemFontOfSize:13];
  89. self.toolsLabel.text = NSLocalizedString(@"Tools", nil);
  90. self.toolsLabel.textColor = [UIColor colorWithRed:153./255 green:153./255 blue:153./255 alpha:1.];
  91. [self.contentView addSubview:self.toolsLabel];
  92. self.replaceBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  93. [self.replaceBtn addTarget:self action:@selector(replaceImageAction:) forControlEvents:UIControlEventTouchUpInside];
  94. [self.replaceBtn setImage:[UIImage imageNamed:@"CPDFEditReplace" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
  95. NSString * replaceTitle = [NSString stringWithFormat:@" %@",NSLocalizedString(@"Replace", nil)];
  96. [self.replaceBtn setTitle:replaceTitle forState:UIControlStateNormal];
  97. [self.replaceBtn setTitleColor: [UIColor colorWithRed:67/255. green:71/255. blue:77/255. alpha:1.] forState:UIControlStateNormal];
  98. self.replaceBtn.titleLabel.font = [UIFont systemFontOfSize:14.f];
  99. self.replaceBtn.layer.borderWidth = 1;
  100. self.replaceBtn.layer.borderColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.1].CGColor;
  101. [self addSubview:self.replaceBtn];
  102. self.replaceBtn.backgroundColor = [UIColor whiteColor];
  103. self.exportBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  104. [self.exportBtn addTarget:self action:@selector(exportImageAction:) forControlEvents:UIControlEventTouchUpInside];
  105. [self.exportBtn setImage:[UIImage imageNamed:@"CPDFEditExport" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
  106. NSString * exportTitle = [NSString stringWithFormat:@" %@",NSLocalizedString(@"Export", nil)];
  107. [self.exportBtn setTitle:exportTitle forState:UIControlStateNormal];
  108. [self.exportBtn setTitleColor: [UIColor colorWithRed:67/255. green:71/255. blue:77/255. alpha:1.] forState:UIControlStateNormal];
  109. self.exportBtn.titleLabel.font = [UIFont systemFontOfSize:14.f];
  110. self.exportBtn.layer.borderWidth = 1;
  111. self.exportBtn.layer.borderColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.1].CGColor;
  112. [self addSubview:self.exportBtn];
  113. self.exportBtn.backgroundColor = [UIColor whiteColor];
  114. self.cropBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  115. [self.cropBtn addTarget:self action:@selector(cropImageAction:) forControlEvents:UIControlEventTouchUpInside];
  116. [self.cropBtn setImage:[UIImage imageNamed:@"CPDFEditCrop" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
  117. NSString * cropTitle = [NSString stringWithFormat:@" %@",NSLocalizedString(@"Crop", nil)];
  118. [self.cropBtn setTitle:cropTitle forState:UIControlStateNormal];
  119. [self.cropBtn setTitleColor: [UIColor colorWithRed:67/255. green:71/255. blue:77/255. alpha:1.] forState:UIControlStateNormal];
  120. self.cropBtn.titleLabel.font = [UIFont systemFontOfSize:14.f];
  121. self.cropBtn.layer.borderWidth = 1;
  122. self.cropBtn.layer.borderColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.1].CGColor;
  123. [self addSubview:self.cropBtn];
  124. self.cropBtn.backgroundColor = [UIColor whiteColor];
  125. self.transformSplitView = [[UIView alloc] init];
  126. self.transformSplitView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.1];
  127. [self.transformView addSubview:self.transformSplitView];
  128. self.opacityView.rightMargin = 10;
  129. self.opacityView.leftMargin = 5;
  130. }
  131. return self;
  132. }
  133. - (void)layoutSubviews {
  134. [super layoutSubviews];
  135. self.rotateLabel.frame = CGRectMake(16, 0, self.bounds.size.width, 20);
  136. self.leftRotateBtn.frame = CGRectMake(16, CGRectGetMaxY(self.rotateLabel.frame) + 12, (self.bounds.size.width - 16*2 - 8)/2, 32);
  137. self.rightRotateBtn.frame = CGRectMake(CGRectGetMaxX(self.leftRotateBtn.frame) + 4, CGRectGetMaxY(self.rotateLabel.frame) + 12, (self.bounds.size.width - 16*2 -8)/2, 32);
  138. self.transformLabel.frame = CGRectMake(16, CGRectGetMaxY(self.leftRotateBtn.frame) + 16, self.bounds.size.width, 20);
  139. self.transformView.frame = CGRectMake(16, CGRectGetMaxY(self.transformLabel.frame) + 16, 101, 32);
  140. self.hBtn.frame = CGRectMake(0, 0, 50, 32);
  141. self.transformSplitView.frame = CGRectMake(50, 0, 1, 32);
  142. self.vBtn.frame = CGRectMake(51, 0, 50, 32);
  143. self.opacityView.frame = CGRectMake(6, CGRectGetMaxY(self.transformView.frame)+ 10, self.frame.size.width - 12, 80);
  144. self.toolsLabel.frame = CGRectMake(16, CGRectGetMaxY(self.opacityView.frame) + 16, self.bounds.size.width, 20);
  145. self.replaceBtn.frame = CGRectMake(16, CGRectGetMaxY(self.toolsLabel.frame) + 16,(self.bounds.size.width - 16 * 2 - 8*2)/3, 32);
  146. self.exportBtn.frame = CGRectMake(CGRectGetMaxX(self.replaceBtn.frame) + 8, CGRectGetMaxY(self.toolsLabel.frame) + 16,(self.bounds.size.width - 16 * 2 - 8*2)/3, 32);
  147. self.cropBtn.frame = CGRectMake(CGRectGetMaxX(self.exportBtn.frame) + 8, CGRectGetMaxY(self.toolsLabel.frame) + 16,(self.bounds.size.width - 16 * 2 - 8*2)/3, 32);
  148. }
  149. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  150. [super setSelected:selected animated:animated];
  151. // Configure the view for the selected state
  152. }
  153. #pragma mark - Action
  154. - (IBAction)leftRotateAction:(UIButton *)sender {
  155. sender.selected = !sender.selected;
  156. if(self.rotateBlock){
  157. self.rotateBlock(CPDFImageRotateTypeLeft, sender.selected);
  158. }
  159. }
  160. - (IBAction)rightRotateAction:(UIButton *)sender {
  161. sender.selected = !sender.selected;
  162. if(self.rotateBlock){
  163. self.rotateBlock(CPDFImageRotateTypeRight, sender.selected);
  164. }
  165. }
  166. - (IBAction)horizontalAction:(UIButton *)sender {
  167. sender.selected = !sender.selected;
  168. if(self.transFormBlock){
  169. self.transFormBlock(CPDFImageTransFormTypeHorizontal, sender.selected);
  170. }
  171. }
  172. - (IBAction)verticalAction:(UIButton *)sender{
  173. sender.selected = !sender.selected;
  174. if(self.transFormBlock){
  175. self.transFormBlock(CPDFImageTransFormTypeVertical, sender.selected);
  176. }
  177. }
  178. - (IBAction)replaceImageAction:(UIButton *)sender {
  179. if(self.replaceImageBlock){
  180. self.replaceImageBlock();
  181. }
  182. }
  183. - (IBAction)exportImageAction:(UIButton *)sender {
  184. if(self.exportImageBlock){
  185. self.exportImageBlock();
  186. }
  187. }
  188. - (IBAction)cropImageAction:(UIButton *)sender {
  189. if(self.cropImageBlock){
  190. self.cropImageBlock();
  191. }
  192. }
  193. - (IBAction)sliderAction:(UISlider *)sender {
  194. self.menu.defaultValue = [NSString stringWithFormat:@"%.2f",sender.value];
  195. if(self.transparencyBlock){
  196. self.transparencyBlock(sender.value);
  197. }
  198. }
  199. #pragma mark - CPDFDropDownMenuDelegate
  200. - (void)dropDownMenu:(CPDFDropDownMenu *)menu didEditWithText:(NSString *)text{
  201. if([text floatValue] >= 0 && [text floatValue] <= 1){
  202. self.transparencySlider.value = [text floatValue];
  203. if(self.transparencyBlock){
  204. self.transparencyBlock([text floatValue]);
  205. }
  206. }
  207. }
  208. - (void)dropDownMenu:(CPDFDropDownMenu *)menu didSelectWithIndex:(NSInteger)index{
  209. float value = [self.menu.options[index] floatValue];
  210. self.transparencySlider.value = value;
  211. if(self.transparencyBlock){
  212. self.transparencyBlock(value);
  213. }
  214. }
  215. - (void)opacitySliderView:(CPDFOpacitySliderView *)opacitySliderView opacity:(CGFloat)opacity {
  216. if(self.transparencyBlock){
  217. self.transparencyBlock(opacity);
  218. }
  219. }
  220. - (void)setPdfView:(CPDFView *)pdfView {
  221. _pdfView = pdfView;
  222. self.opacityView.defaultValue = [pdfView getCurrentOpacity];
  223. }
  224. @end