-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageViewController.m
More file actions
83 lines (63 loc) · 2.52 KB
/
ImageViewController.m
File metadata and controls
83 lines (63 loc) · 2.52 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//
// ImageViewController.m
// LLSimpleCameraExample
//
// Created by Ömer Faruk Gül on 15/11/14.
// Copyright (c) 2014 Ömer Faruk Gül. All rights reserved.
//
#import "ImageViewController.h"
#import "ViewUtils.h"
#import "UIImage+Crop.h"
@interface ImageViewController ()
@property (strong, nonatomic) UIImage *image;
@property (strong, nonatomic) UIImageView *imageView;
@property (strong, nonatomic) UILabel *infoLabel;
@property (strong, nonatomic) UIButton *cancelButton;
@end
@implementation ImageViewController
- (instancetype)initWithImage:(UIImage *)image {
self = [super initWithNibName:nil bundle:nil];
if(self) {
_image = image;
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.imageView.backgroundColor = [UIColor blackColor];
CGRect screenRect = [[UIScreen mainScreen] bounds];
self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, screenRect.size.width, screenRect.size.height)];
self.imageView.contentMode = UIViewContentModeScaleAspectFit;
self.imageView.backgroundColor = [UIColor clearColor];
self.imageView.image = self.image;
[self.view addSubview:self.imageView];
NSString *info = [NSString stringWithFormat:@"Size: %@ - Orientation: %ld", NSStringFromCGSize(self.image.size), (long)self.image.imageOrientation];
self.infoLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 20)];
self.infoLabel.backgroundColor = [[UIColor darkGrayColor] colorWithAlphaComponent:0.7];
self.infoLabel.textColor = [UIColor whiteColor];
self.infoLabel.font = [UIFont fontWithName:@"AvenirNext-Regular" size:13];
self.infoLabel.textAlignment = NSTextAlignmentCenter;
self.infoLabel.text = info;
// [self.view addSubview:self.infoLabel];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewTapped:)];
[self.view addGestureRecognizer:tapGesture];
}
- (void)viewTapped:(UIGestureRecognizer *)gesture {
[self dismissViewControllerAnimated:NO completion:nil];
}
- (BOOL)prefersStatusBarHidden {
return YES;
}
- (void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];
self.imageView.frame = self.view.contentBounds;
[self.infoLabel sizeToFit];
self.infoLabel.width = self.view.contentBounds.size.width;
self.infoLabel.top = 0;
self.infoLabel.left = 0;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end