InspectUpLoadFootView.m 11.8 KB
Newer Older
admin's avatar
admin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
//
//  InspectUpLoadFootView.m
//  redstar
//
//  Created by admin on 15/11/25.
//  Copyright © 2015年 ZWF. All rights reserved.
//

#import "InspectUpLoadFootView.h"
#import <UIImageView+WebCache.h>


@implementation InspectUpLoadFootView

- (instancetype)initWithAnswerAttachments:(NSArray *)answerAttachments referenceAttachments:(NSArray *)referenceAttachments remark:(NSString *)remark
{
    self = [super init];
    if (self) {
        self.backgroundColor = kSectionBackGroundColor;
        CGFloat imageMaginX = 20;
        CGFloat imageMaginY = 10;
        CGFloat imageW = (kScreenWidth - imageMaginX * 3) / 2;
        CGFloat imageH = 100;
        
        int answerCount = (int)answerAttachments.count;
        int answerRow = 0;
        if (answerCount % 2 == 0) {
            answerRow = answerCount / 2;
        } else {
            answerRow = (answerCount + 1) / 2;
        }
        
        int referenceCount = (int)referenceAttachments.count;
        int referenceRow = 0;
        if (referenceCount % 2 == 0) {
            referenceRow = referenceCount / 2;
        } else {
            referenceRow = (referenceCount + 1) / 2;
        }
        
        self.height = imageMaginY + (25 * 2) + answerRow * (imageH + imageMaginY) + imageMaginY + referenceRow * (imageH + imageMaginY) + imageMaginY + 100 + 60;
        
        self.titleLabel.text = @"现场照片";

        // 现场照片
        for (int i = 0; i < answerAttachments.count; i++) {
            UIImageView *imageView = [[UIImageView alloc] init];
admin's avatar
admin committed
48
            imageView.userInteractionEnabled = YES;
admin's avatar
admin committed
49 50 51
            NSDictionary *dict = (NSDictionary *)answerAttachments[i];
            NSURL *imageUrl = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@", kRedStarURL ,dict[@"fileUrl"]]];
            [imageView sd_setImageWithURL:imageUrl placeholderImage:[UIImage imageNamed:@"default_pic"]];
admin's avatar
admin committed
52 53
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageCilck:)];
            [imageView addGestureRecognizer:tap];
admin's avatar
admin committed
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
            int j = 0;
            if ((i + 1) % 2 == 0) {
                j = (i + 1) / 2;
                imageView.frame = CGRectMake(imageMaginX + (imageW + imageMaginX), 35 + imageMaginY + (j-1) * (imageH + imageMaginY), imageW, imageH);
            } else {
                j = (i + 2) / 2;
                imageView.frame = CGRectMake(imageMaginX, 35 + imageMaginY + (j-1) * (imageH + imageMaginY), imageW, imageH);
            }
            [self addSubview:imageView];
        }
        
        UILabel *referenceLabel = [[UILabel alloc] initWithFrame:CGRectMake(imageMaginX, 40 + answerRow * imageH + (answerRow + 1) * imageMaginY, kScreenWidth - imageMaginX * 2, 25)];
        referenceLabel.font = [UIFont systemFontOfSize:15.0];
        referenceLabel.textColor = kLightGray;
        referenceLabel.text = @"参考照片";
        [self addSubview:referenceLabel];
        
        
        
        // 参考照片
        for (int i = 0; i < referenceAttachments.count; i++) {
            UIImageView *imageView = [[UIImageView alloc] init];
admin's avatar
admin committed
76
            imageView.userInteractionEnabled = YES;
admin's avatar
admin committed
77 78
            NSDictionary *dict = (NSDictionary *)referenceAttachments[i];
            NSURL *imageUrl = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@", kRedStarURL ,dict[@"fileUrl"]]];
admin's avatar
admin committed
79
        
admin's avatar
admin committed
80
            [imageView sd_setImageWithURL:imageUrl placeholderImage:[UIImage imageNamed:@"default_pic"]];
admin's avatar
admin committed
81 82 83
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageCilck:)];
            [imageView addGestureRecognizer:tap];

admin's avatar
admin committed
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
            int j = 0;
            if ((i + 1) % 2 == 0) {
                j = (i + 1) / 2;
                imageView.frame = CGRectMake(imageMaginX + (imageW + imageMaginX), 65 + answerRow * imageH + (answerRow + 1) * imageMaginY + imageMaginY + (j-1) * (imageH + imageMaginY), imageW, imageH);
            } else {
                j = (i + 2) / 2;
                imageView.frame = CGRectMake(imageMaginX, 65 + answerRow * imageH + (answerRow + 1) * imageMaginY + imageMaginY + (j-1) * (imageH + imageMaginY), imageW, imageH);
            }
            [self addSubview:imageView];
        }
        
        // 备注
        UILabel *remarkLanel = [[UILabel alloc] initWithFrame:CGRectMake(imageMaginX, 65 + answerRow * imageH + (answerRow + 1) * imageMaginY + referenceRow * imageH + (referenceRow + 1) * imageMaginY, kScreenWidth - imageMaginX * 2, 25)];
        remarkLanel.font = [UIFont systemFontOfSize:15.0];
        remarkLanel.textColor = kLightGray;
        remarkLanel.text = @"备注";
        [self addSubview:remarkLanel];
        
        // 背景ImageView
        UIImageView *bgImageView = [[UIImageView alloc] init];
        bgImageView.translatesAutoresizingMaskIntoConstraints = NO;
        UIImage *image = [UIImage imageNamed:@"textbox"];
        UIImage *resizingName = [image resizableImageWithCapInsets:UIEdgeInsetsMake(1, 1, 24, 24) resizingMode:UIImageResizingModeStretch];
        bgImageView.image = resizingName;
        [self addSubview:bgImageView];
        
        NSLayoutConstraint *overDateTop = [NSLayoutConstraint constraintWithItem:bgImageView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:remarkLanel attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
        [self addConstraint:overDateTop];
        
        NSLayoutConstraint *overDateLeft = [NSLayoutConstraint constraintWithItem:bgImageView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeft multiplier:1.0 constant:20];
        [self addConstraint:overDateLeft];
        
        NSLayoutConstraint *overDateRight = [NSLayoutConstraint constraintWithItem:bgImageView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeRight multiplier:1.0 constant:-20];
        [self addConstraint:overDateRight];
        
        
        NSLayoutConstraint *overDateWidth = [NSLayoutConstraint constraintWithItem:bgImageView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:70];
        [self addConstraint:overDateWidth];
        
        // textView
        UITextView *textView = [[UITextView alloc] init];
        textView.text = [NSString stringWithFormat:@"%@", remark];
        textView.backgroundColor = [UIColor clearColor];
        textView.translatesAutoresizingMaskIntoConstraints = NO;
        [bgImageView addSubview:textView];
        
        NSLayoutConstraint *textViewTop = [NSLayoutConstraint constraintWithItem:textView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:bgImageView attribute:NSLayoutAttributeTop multiplier:1.0 constant:1];
        [bgImageView addConstraint:textViewTop];
        
        NSLayoutConstraint *textViewLeft = [NSLayoutConstraint constraintWithItem:textView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:bgImageView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:1];
        [bgImageView addConstraint:textViewLeft];
        
        NSLayoutConstraint *textViewRight = [NSLayoutConstraint constraintWithItem:textView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:bgImageView attribute:NSLayoutAttributeRight multiplier:1.0 constant:-1];
        [bgImageView addConstraint:textViewRight];
        
        
        NSLayoutConstraint *textViewWidth = [NSLayoutConstraint constraintWithItem:textView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:bgImageView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:-1];
        [bgImageView addConstraint:textViewWidth];
        
        // 返回上一页
        UIButton *returnButton = [[UIButton alloc] init];
        returnButton.translatesAutoresizingMaskIntoConstraints = NO;
        returnButton.backgroundColor = kNavigationBarColor;
        returnButton.layer.cornerRadius = 4;
        [returnButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [returnButton setTitle:@"返回上一页面" forState:UIControlStateNormal];
        returnButton.titleLabel.font = [UIFont systemFontOfSize:20.0];
        [returnButton addTarget:self action:@selector(returnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:returnButton];

        NSLayoutConstraint *returnButtonTop = [NSLayoutConstraint constraintWithItem:returnButton attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:bgImageView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:10];
        [self addConstraint:returnButtonTop];
        
        NSLayoutConstraint *returnButtonLeft = [NSLayoutConstraint constraintWithItem:returnButton attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeft multiplier:1.0 constant:20];
        [self addConstraint:returnButtonLeft];
        
        NSLayoutConstraint *returnButtonRight = [NSLayoutConstraint constraintWithItem:returnButton attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeRight multiplier:1.0 constant:-20];
        [self addConstraint:returnButtonRight];
        
        NSLayoutConstraint *returnButtonHeight = [NSLayoutConstraint constraintWithItem:returnButton attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:40];
        [self addConstraint:returnButtonHeight];
    }
    return self;
}

- (void)returnClick:(UIButton *)sender
{
admin's avatar
admin committed
171
    if (_delegate && [_delegate respondsToSelector:@selector(returnParentsViewController)]) {
admin's avatar
admin committed
172 173 174 175
        [_delegate returnParentsViewController];
    }
}

admin's avatar
admin committed
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
- (void)imageCilck:(UITapGestureRecognizer *)sender
{
    if (_delegate && [_delegate respondsToSelector:@selector(showPicture:)]) {
        [_delegate showPicture:sender];
    }
}

- (UIImage *)image:(UIImage*)image scaledToSize:(CGSize)newSize
{
    // Create a graphics image context
    UIGraphicsBeginImageContext(newSize);
    // Tell the old image to draw in this new context, with the desired
    // new size
    [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
    // Get the new image from the context
    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
    // End the context
    UIGraphicsEndImageContext();
    // Return the new image.
    return newImage;
}

admin's avatar
admin committed
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
#pragma - lazy loading
- (UILabel *)titleLabel
{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
        _titleLabel.font = [UIFont systemFontOfSize:15.0];
        _titleLabel.textColor = kLightGray;
        [self addSubview:_titleLabel];
        
        NSLayoutConstraint *overDateTop = [NSLayoutConstraint constraintWithItem:_titleLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTop multiplier:1.0 constant:10];
        [self addConstraint:overDateTop];
        
        NSLayoutConstraint *overDateLeft = [NSLayoutConstraint constraintWithItem:_titleLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeft multiplier:1.0 constant:20];
        [self addConstraint:overDateLeft];
        
        NSLayoutConstraint *overDateRight = [NSLayoutConstraint constraintWithItem:_titleLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeRight multiplier:1.0 constant:-20];
        [self addConstraint:overDateRight];
        
        
        NSLayoutConstraint *overDateWidth = [NSLayoutConstraint constraintWithItem:_titleLabel attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:25];
        [self addConstraint:overDateWidth];
    }
    return _titleLabel;
}


@end