This repository has been archived by the owner on Jan 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRBNotificationController.m
355 lines (268 loc) · 19.2 KB
/
RBNotificationController.m
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
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
//
// RBNotificationController.m
// kupikupon
//
// Created by Василий Думанов on 31.01.15.
// Copyright (c) 2015 kupikupon.ru. All rights reserved.
//
#import "RBNotificationController.h"
@interface RBNotificationController() <UINavigationBarDelegate>
@property (nonatomic, strong) UIImageView *rbImageView;
@property (nonatomic, strong) UILabel *rbTitleLabel;
@property (nonatomic, strong) UILabel *rbDescriptionLabel;
@property (nonatomic, strong) UIScrollView *scrollView;
@end
@implementation RBNotificationController
-(instancetype)init {
if (self = [super init]) {
}
return self;
}
-(void)viewDidLoad {
self.view.backgroundColor = [UIColor whiteColor];
//Добавляем navigationBar
UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 20, self.view.frame.size.width, 44)];
navBar.delegate = self;
navBar.barStyle = UIBarStyleDefault;
UINavigationItem *navItem = [[UINavigationItem alloc] initWithTitle: self.rbControllerBarTitle ? self.rbControllerBarTitle : @"Акция"];
if (!self.rbControllerBackButton) {
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismiss)];
navItem.leftBarButtonItem = backButton;
} else {
self.rbControllerBackButton.target = self;
self.rbControllerBackButton.action = @selector(dismiss);
navItem.leftBarButtonItem = self.rbControllerBackButton;
}
navBar.items = @[navItem];
[self.view addSubview:navBar];
//Создаем UIScrollView
UIScrollView *scrollView = [[UIScrollView alloc] init];
scrollView.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:scrollView];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:scrollView
attribute:NSLayoutAttributeLeft
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeLeft
multiplier:1.0
constant:0]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:scrollView
attribute:NSLayoutAttributeRight
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeRight
multiplier:1.0
constant:0]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:scrollView
attribute:NSLayoutAttributeBottom
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeBottom
multiplier:1.0
constant:0]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:scrollView
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeTop
multiplier:1.0
constant:64]];
//Добавляем contentView к scrollView
UIView *contentView = [[UIView alloc] init];
contentView.translatesAutoresizingMaskIntoConstraints = NO;
[scrollView addSubview:contentView];
[scrollView addConstraint:[NSLayoutConstraint constraintWithItem:scrollView
attribute:NSLayoutAttributeBottom
relatedBy:NSLayoutRelationEqual
toItem:contentView
attribute:NSLayoutAttributeBottom
multiplier:1.0
constant:0]];
[scrollView addConstraint:[NSLayoutConstraint constraintWithItem:scrollView
attribute:NSLayoutAttributeCenterX
relatedBy:NSLayoutRelationEqual
toItem:contentView
attribute:NSLayoutAttributeCenterX
multiplier:1.0
constant:0]];
[scrollView addConstraint:[NSLayoutConstraint constraintWithItem:scrollView
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:contentView
attribute:NSLayoutAttributeTop
multiplier:1.0
constant:0]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:scrollView
attribute:NSLayoutAttributeRight
relatedBy:NSLayoutRelationEqual
toItem:contentView
attribute:NSLayoutAttributeRight
multiplier:1.0
constant:0]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"[contentView(320)]"
options:0
metrics:nil
views:NSDictionaryOfVariableBindings(contentView)]];
//Добавляем постер
UIImageView *rbImageView = [[UIImageView alloc] init];
rbImageView.translatesAutoresizingMaskIntoConstraints = NO;
[contentView addSubview:rbImageView];
[contentView addConstraint:[NSLayoutConstraint constraintWithItem:rbImageView
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1.0
constant:70]];
[contentView addConstraint:[NSLayoutConstraint constraintWithItem:rbImageView
attribute:NSLayoutAttributeHeight
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1.0
constant:70]];
/*[contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"[rbImageView(70)]"
options:0
metrics:nil
views:NSDictionaryOfVariableBindings(rbImageView)]];
[contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[rbImageView(70)]"
options:0
metrics:nil
views:NSDictionaryOfVariableBindings(rbImageView)]];*/
[contentView addConstraint:[NSLayoutConstraint constraintWithItem:contentView
attribute:NSLayoutAttributeRight
relatedBy:NSLayoutRelationEqual
toItem:rbImageView
attribute:NSLayoutAttributeRight
multiplier:1.0
constant:242.0]];
[contentView addConstraint:[NSLayoutConstraint constraintWithItem:rbImageView
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:contentView
attribute:NSLayoutAttributeTop
multiplier:1.0
constant:18.0]];
/*[contentView addConstraint:[NSLayoutConstraint constraintWithItem:contentView
attribute:NSLayoutAttributeBottom
relatedBy:NSLayoutRelationEqual
toItem:rbImageView
attribute:NSLayoutAttributeBottom
multiplier:1.0
constant:18.0]];*/
//NSString *testString = [NSString stringWithFormat:@"%f %f", self.rbImageView.frame.size.width, self.rbImageView.frame.size.height];
dispatch_queue_t myQueue = dispatch_queue_create("imageQueue",NULL);
dispatch_async(myQueue, ^{
UIImage *img = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:self.imageUrl]]];
dispatch_async(dispatch_get_main_queue(), ^{
/*UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Test"
message:@"here we are"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];*/
/*CGFloat imageWidth = img.size.width;
CGFloat imageHeight = img.size.height;
CGFloat ratio = rbImageView.frame.size.width / imageWidth;
CGFloat newImageViewHeight = (int)(imageHeight * ratio);
CGRect newImageRect = rbImageView.frame;
newImageRect.size.height = newImageViewHeight;
rbImageView.frame = newImageRect;*/
[rbImageView setImage:img];
});
});
//Добавляем заголовок
UILabel *rbTitleLabel = [[UILabel alloc] init];
rbTitleLabel.text = self.rbTitle;
rbTitleLabel.font = [UIFont boldSystemFontOfSize:18];
rbTitleLabel.translatesAutoresizingMaskIntoConstraints = NO;
rbTitleLabel.lineBreakMode = NSLineBreakByWordWrapping;
rbTitleLabel.numberOfLines = 0;
[contentView addSubview:rbTitleLabel];
[contentView addConstraint:[NSLayoutConstraint constraintWithItem:contentView
attribute:NSLayoutAttributeRight
relatedBy:NSLayoutRelationEqual
toItem:rbTitleLabel
attribute:NSLayoutAttributeRight
multiplier:1.0
constant:17.0]];
[contentView addConstraint:[NSLayoutConstraint constraintWithItem:rbTitleLabel
attribute:NSLayoutAttributeHeight
relatedBy:NSLayoutRelationGreaterThanOrEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1.0
constant:21]];
[contentView addConstraint:[NSLayoutConstraint constraintWithItem:rbTitleLabel
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1.0
constant:206]];
[contentView addConstraint:[NSLayoutConstraint constraintWithItem:rbTitleLabel
attribute:NSLayoutAttributeCenterY
relatedBy:NSLayoutRelationEqual
toItem:rbImageView
attribute:NSLayoutAttributeCenterY
multiplier:1.0
constant:0]];
//Добавляем описание
UILabel *rbDescriptionLabel = [[UILabel alloc] init];
rbDescriptionLabel.text = self.rbDescription;
rbDescriptionLabel.font = [UIFont systemFontOfSize:15];
rbDescriptionLabel.translatesAutoresizingMaskIntoConstraints = NO;
rbDescriptionLabel.lineBreakMode = NSLineBreakByWordWrapping;
rbDescriptionLabel.numberOfLines = 0;
[contentView addSubview:rbDescriptionLabel];
[contentView addConstraint:[NSLayoutConstraint constraintWithItem:rbDescriptionLabel
attribute:NSLayoutAttributeLeft
relatedBy:NSLayoutRelationEqual
toItem:contentView
attribute:NSLayoutAttributeLeft
multiplier:1.0
constant:13.0]];
[contentView addConstraint:[NSLayoutConstraint constraintWithItem:rbDescriptionLabel
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1.0
constant:299]];
[contentView addConstraint:[NSLayoutConstraint constraintWithItem:rbDescriptionLabel
attribute:NSLayoutAttributeHeight
relatedBy:NSLayoutRelationGreaterThanOrEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1.0
constant:21]];
[contentView addConstraint:[NSLayoutConstraint constraintWithItem:contentView
attribute:NSLayoutAttributeBottom
relatedBy:NSLayoutRelationEqual
toItem:rbDescriptionLabel
attribute:NSLayoutAttributeBottom
multiplier:1.0
constant:10.0]];
[contentView addConstraint:[NSLayoutConstraint constraintWithItem:rbTitleLabel
attribute:NSLayoutAttributeBottom
relatedBy:NSLayoutRelationGreaterThanOrEqual
toItem:rbDescriptionLabel
attribute:NSLayoutAttributeTop
multiplier:1.0
constant:33.0]];
[contentView addConstraint:[NSLayoutConstraint constraintWithItem:rbDescriptionLabel
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:rbImageView
attribute:NSLayoutAttributeBottom
multiplier:1.0
constant:23.0]];
}
-(void)dismiss {
[self dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark - UINavigationBarDelegate
-(UIBarPosition)positionForBar:(id<UIBarPositioning>)bar {
return UIBarPositionTopAttached;
}
@end