123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389 |
- //
- // StampTextCell.m
- // PDFReader
- //
- // Copyright © 2014-2022 PDF Technologies, Inc. All Rights Reserved.
- //
- // The PDF Reader Sample applications are licensed with a modified BSD license.
- // Please see License for details. This notice may not be removed from this file.
- //
- #import "StampTextCell.h"
- @implementation StampTextCell
- @synthesize delegate = _delegate;
- @synthesize cellType = _cellType;
- @synthesize preView = _preView;
- @synthesize stampTextField = _stampTextField;
- @synthesize haveTimeSwitch = _haveTimeSwitch;
- @synthesize haveDateSwitch = _haveDateSwitch;
- - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
- if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
-
- }
- return self;
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
- [super setSelected:selected animated:animated];
- // Configure the view for the selected state
- }
- - (void)dealloc {
- _delegate = nil;
- if (_stampTextField) {
- _stampTextField.delegate = nil;
- [_stampTextField release];
- }
-
- if (_preView) {
- [_preView removeFromSuperview];
- [_preView release];
- }
-
- [btnBlack release];
- [btnGreen release];
- [btnRed release];
- [btnBlue release];
-
- [super dealloc];
- }
- #pragma mark - Custom Cell
- - (void)setCellStyle:(CustomTextCellType)cellType label:(NSString *)label {
- if (self.stampTextField) {
- self.stampTextField.delegate = nil;
- }
-
- self.stampTextField = nil;
- if (_preView) {
- [_preView removeFromSuperview];
- [_preView release];
- _preView = nil;
- }
-
- _cellType = cellType;
- switch (cellType)
- {
- case CustomTextCellType_Text:
- {
- self.textLabel.text = [label isEqualToString:@""] ? @"StampText":label;
- self.selectionStyle = UITableViewCellSelectionStyleNone;
-
- CGRect tFieldRect = CGRectMake(0.0, 0.0f, 200.0f, 31.0f);
- UITextField *tTextField = [self textFieldItemCreate_Text:tFieldRect];
- tTextField.delegate = self;
-
- self.stampTextField = tTextField;
- self.accessoryView = tTextField;
- [tTextField release];
- break;
- }
-
- case CustomTextCellType_Color:
- {
- self.textLabel.text = label;
- self.selectionStyle = UITableViewCellSelectionStyleNone;
-
- CGFloat offset = 0;
- CGFloat tSpace = 58.0;
- btnBlack = [self buttonItemCreate:CGRectMake(offset, 0, 44, 44) colorType:TextStampColorType_Black];
- btnGreen = [self buttonItemCreate:CGRectMake(offset+=tSpace, 0, 44, 44) colorType:TextStampColorType_Green];
- btnRed = [self buttonItemCreate:CGRectMake(offset+=tSpace, 0, 44, 44) colorType:TextStampColorType_Red];
- btnBlue = [self buttonItemCreate:CGRectMake(offset+=tSpace, 0, 44, 44) colorType:TextStampColorType_Blue];
-
- offset = 0;
- leftGreen = [self buttonItemCreate:CGRectMake(offset+=tSpace, 44, 44, 44) colorType:TextStampColorType_GreenLeft];
- leftRed = [self buttonItemCreate:CGRectMake(offset+=tSpace, 44, 44, 44) colorType:TextStampColorType_RedLeft];
- leftBlue = [self buttonItemCreate:CGRectMake(offset+=tSpace, 44, 44, 44) colorType:TextStampColorType_BlueLeft];
-
- offset = 0;
- rightGreen = [self buttonItemCreate:CGRectMake(offset+=tSpace, 88, 44, 44) colorType:TextStampColorType_GreenRight];
- rightRed = [self buttonItemCreate:CGRectMake(offset+=tSpace, 88, 44, 44) colorType:TextStampColorType_RedRight];
- rightBlue = [self buttonItemCreate:CGRectMake(offset+=tSpace, 88, 44, 44) colorType:TextStampColorType_BlueRight];
-
- offset = offset + tSpace*2.0/3.0;
- UIView *tSelectView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, offset, 135)];
- [tSelectView addSubview:btnBlack];
- [tSelectView addSubview:btnGreen];
- [tSelectView addSubview:btnRed];
- [tSelectView addSubview:btnBlue];
-
- [tSelectView addSubview:leftGreen];
- [tSelectView addSubview:leftRed];
- [tSelectView addSubview:leftBlue];
-
- [tSelectView addSubview:rightGreen];
- [tSelectView addSubview:rightRed];
- [tSelectView addSubview:rightBlue];
-
- btnBlack.selected = YES;
-
- self.accessoryView = tSelectView;
- [tSelectView release];
- self.backgroundColor = [UIColor whiteColor];
- break;
- }
-
- case CustomTextCellType_Date:
- {
- self.textLabel.text = label;
- self.selectionStyle = UITableViewCellSelectionStyleNone;
- UISwitch *switchView = [self switchItemCreate];
- self.haveDateSwitch = switchView;
-
- [switchView release];
- self.backgroundColor = [UIColor whiteColor];
- break;
- }
-
- case CustomTextCellType_Time:
- {
- self.textLabel.text = label;
- self.selectionStyle = UITableViewCellSelectionStyleNone;
- UISwitch *switchView = [self switchItemCreate];
- self.haveTimeSwitch = switchView;
-
- [switchView release];
- self.backgroundColor = [UIColor whiteColor];
- break;
- }
-
- case CustomTextCellType_Preview:
- {
- self.textLabel.text = nil;
- self.haveTimeSwitch = nil;
- self.accessoryView = nil;
-
- self.selectionStyle = UITableViewCellSelectionStyleNone;
- //清除边框 背景
- self.backgroundColor = [UIColor clearColor];
- UIView *tView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
- self.backgroundView = tView;
-
- _preView = [[StampPreview alloc] initWithFrame:CGRectMake(0, 0, 320, 60)];
- _preView.textStampText = label;
- [self.contentView addSubview:_preView];
- break;
- }
-
- default:
- break;
- }
- }
- - (void)preViewReDisplay {
- [_preView setNeedsDisplay];
- }
- - (void)layoutSubviews {
- [super layoutSubviews];
-
- _preView.frame = CGRectMake(0, 0, self.frame.size.width, _preView.frame.size.height);
- }
- #pragma mark
- - (UITextField *)textFieldItemCreate_Text:(CGRect)rect {
- UITextField *tTextField = [[UITextField alloc] initWithFrame:rect];
-
- tTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
- tTextField.returnKeyType = UIReturnKeyDone;
- tTextField.clearButtonMode = YES;
- [tTextField addTarget:self action:@selector(doAction:) forControlEvents:UIControlEventEditingChanged];
- tTextField.placeholder = @"StampText";
-
- return tTextField;
- }
- - (UISwitch *)switchItemCreate {
- UISwitch *switchView = [[UISwitch alloc] initWithFrame:CGRectZero];
-
- self.accessoryView = switchView;
- [switchView setOn:NO animated:NO];
- [switchView addTarget:self action:@selector(doAction:) forControlEvents:UIControlEventValueChanged];
-
- return switchView;
- }
- - (UIButton *)buttonItemCreate:(CGRect)rect colorType:(TextStampColorType)type {
- UIImage *tImage = nil;
- switch (type) {
- case TextStampColorType_Black:
- tImage = [UIImage imageNamed:@"a_1.png"];
- break;
- case TextStampColorType_Green:
- tImage = [UIImage imageNamed:@"a_2.png"];
- break;
- case TextStampColorType_Red:
- tImage = [UIImage imageNamed:@"a_3.png"];
- break;
- case TextStampColorType_Blue:
- tImage = [UIImage imageNamed:@"a_4.png"];
- break;
- case TextStampColorType_GreenLeft:
- tImage = [UIImage imageNamed:@"a_2a.png"];
- break;
- case TextStampColorType_RedLeft:
- tImage = [UIImage imageNamed:@"a_3a.png"];
- break;
- case TextStampColorType_BlueLeft:
- tImage = [UIImage imageNamed:@"a_4a.png"];
- break;
- case TextStampColorType_GreenRight:
- tImage = [UIImage imageNamed:@"a_2b.png"];
- break;
- case TextStampColorType_RedRight:
- tImage = [UIImage imageNamed:@"a_3b.png"];
- break;
- case TextStampColorType_BlueRight:
- tImage = [UIImage imageNamed:@"a_4b.png"];
- break;
- default:
- break;
- }
-
- UIButton *tBtn = [[UIButton alloc] initWithFrame:rect];
- tBtn.tag = type;
- [tBtn setBackgroundColor:[UIColor clearColor]];
- [tBtn setBackgroundImage:[UIImage imageNamed:@"select_a.png"] forState:UIControlStateSelected];
- [tBtn setImage:tImage forState:UIControlStateNormal];
- [tBtn setImageEdgeInsets:UIEdgeInsetsMake(0.0, 4.0, 0, 4.0)];
- [tBtn addTarget:self action:@selector(buttonItemClicked:) forControlEvents:UIControlEventTouchUpInside];
-
- return tBtn;
- }
- #pragma mark UI Action
- - (void)doAction:(id)sender {
- switch (_cellType)
- {
- case CustomTextCellType_Text:
- if ([_delegate respondsToSelector:@selector(textFieldWithText_Text:)]) {
- [_delegate textFieldWithText_Text:sender];
- }
- break;
-
- case CustomTextCellType_Color:
- if ([_delegate respondsToSelector:@selector(buttonItemClicked_Color:)]) {
- [_delegate buttonItemClicked_Color:sender];
- }
- break;
-
- case CustomTextCellType_Date:
- if ([_delegate respondsToSelector:@selector(switchValueChanged_Date:)]) {
- [_delegate switchValueChanged_Date:sender];
- }
- break;
-
- case CustomTextCellType_Time:
- if ([_delegate respondsToSelector:@selector(switchValueChanged_Time:)]) {
- [_delegate switchValueChanged_Time:sender];
- }
- break;
-
- default:
- break;
- }
- }
- - (void)buttonItemClicked:(id)sender {
- btnBlack.selected = NO;
- btnGreen.selected = NO;
- btnRed.selected = NO;
- btnBlue.selected = NO;
-
- leftRed.selected = NO;
- leftBlue.selected = NO;
- leftGreen.selected = NO;
-
- rightRed.selected = NO;
- rightGreen.selected = NO;
- rightBlue.selected = NO;
-
- UIButton *tCurBtn = sender;
- tCurBtn.selected = YES;
-
- [self doAction:tCurBtn];
- }
- - (void)buttonItemClicked_GreenA:(id)sender {
- btnBlack.selected = NO;
- btnGreen.selected = YES;
- btnRed.selected = NO;
- btnBlue.selected = NO;
-
- [self doAction:btnGreen];
- }
- - (void)buttonItemClicked_RedA:(id)sender {
- btnBlack.selected = NO;
- btnGreen.selected = NO;
- btnRed.selected = YES;
- btnBlue.selected = NO;
-
- [self doAction:btnRed];
- }
- - (void)buttonItemClicked_BlueA:(id)sender {
- btnBlack.selected = NO;
- btnGreen.selected = NO;
- btnRed.selected = NO;
- btnBlue.selected = YES;
-
- [self doAction:btnBlue];
- }
- - (void)selectColor:(NSInteger)buttonColor {
- switch (buttonColor)
- {
- case TextStampColorType_GreenLeft:
- [self buttonItemClicked:leftGreen];
- break;
- case TextStampColorType_BlueLeft:
- [self buttonItemClicked:leftBlue];
- break;
- case TextStampColorType_RedLeft:
- [self buttonItemClicked:leftRed];
- break;
- case TextStampColorType_GreenRight:
- [self buttonItemClicked:rightGreen];
- break;
- case TextStampColorType_BlueRight:
- [self buttonItemClicked:rightBlue];
- break;
- case TextStampColorType_RedRight:
- [self buttonItemClicked:rightRed];
- break;
- case TextStampColorType_Green:
- [self buttonItemClicked:btnGreen];
- break;
- case TextStampColorType_Blue:
- [self buttonItemClicked:btnBlue];
- break;
- case TextStampColorType_Red:
- [self buttonItemClicked:btnRed];
- break;
- case TextStampColorType_Black:
- default:
- [self buttonItemClicked:btnBlack];
- break;
- }
- }
- #pragma mark - UITextFieldDelegate
- - (BOOL)textFieldShouldReturn:(UITextField *)textField {
- [textField resignFirstResponder];
- if ([_delegate respondsToSelector:@selector(textFieldWithText_Text:)]) {
- [_delegate textFieldWithText_Text:textField];
- }
- return YES;
- }
- @end
|