-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathImagesViewController.m
More file actions
133 lines (86 loc) · 3.8 KB
/
ImagesViewController.m
File metadata and controls
133 lines (86 loc) · 3.8 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
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
//
// ImagesViewController.m
// iFiles
//
// Created by Billy Ellis on 21/01/2016.
// Copyright © 2016 Billy Ellis. All rights reserved.
//
#import "ImagesViewController.h"
#import "CustomIOSAlertView.h"
@interface ImagesViewController ()
@end
@implementation ImagesViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
textField = [[UITextField alloc]initWithFrame:CGRectMake(20,70,self.view.frame.size.width - 40,30)];
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.placeholder = @"Enter a path of image to view";
[self.view addSubview:textField];
//button
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(self.view.frame.size.width/2-50,self.view.frame.size.height*0.25-25,100,50);
[button setTitle:@"View" forState:UIControlStateNormal];
[button addTarget:self action:@selector(viewFiles) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
-(void)viewFiles{
path = textField.text;
NSError *error = nil;
//NSArray *contentsArray = [[NSFileManager defaultManager]contentsOfDirectoryAtPath:path error:&error];
NSString *txtFilePath = textField.text;
NSString *contentsArray = [NSString stringWithContentsOfFile:txtFilePath encoding:NSUTF8StringEncoding error:NULL];
NSString *contentsString = [NSString stringWithFormat:@"%@",contentsArray];
NSString *titleString = [NSString stringWithFormat:@"%@%@", @"Contents of ", txtFilePath];
//alert
CustomIOSAlertView *alertView = [[CustomIOSAlertView alloc] init];
// Add some custom content to the alert view
[alertView setContainerView:[self createDemoView]];
// Modify the parameters
[alertView setButtonTitles:[NSMutableArray arrayWithObjects:@"Dismiss", nil]];
[alertView setDelegate:self];
// You may use a Block, rather than a delegate.
[alertView setOnButtonTouchUpInside:^(CustomIOSAlertView *alertView, int buttonIndex) {
NSLog(@"Block: Button at position %d is clicked on alertView %d.", buttonIndex, (int)[alertView tag]);
[alertView close];
}];
[alertView setUseMotionEffects:true];
// And launch the dialog
[alertView show];
[textField resignFirstResponder];
//image
/*UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 200, 200)];
image.image = [UIImage imageWithContentsOfFile:path];
[alert addSubview:image];
[alert show];
theImage.image = [UIImage imageWithContentsOfFile:path];*/
}
- (void)customIOS7dialogButtonTouchUpInside: (CustomIOSAlertView *)alertView clickedButtonAtIndex: (NSInteger)buttonIndex
{
NSLog(@"Alert closed");
[alertView close];
}
- (UIView *)createDemoView
{
UIView *demoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 180, 180)];
UILabel *nilLabel = [[UILabel alloc]initWithFrame:CGRectMake(30, 30,100, 40)];
nilLabel.text = @"null";
[demoView addSubview:nilLabel];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 150, 150)];
[imageView setImage:[UIImage imageWithContentsOfFile:path]];
[demoView addSubview:imageView];
return demoView;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end