FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Coding-iOS/Coding_iOS/Views/CodingBannersView.m at master · magic-coder/Coding-iOS · GitHub
magic-coder
/
Coding-iOS
Public
forked from
coding/Coding-iOS
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Coding-iOS
/
Coding_iOS
/
Views
/
CodingBannersView.m
Copy path
More file actions
More file actions
Latest commit
History
History
History
175 lines (159 loc) · 6.98 KB
Breadcrumbs
Coding-iOS
/
Coding_iOS
/
Views
/
CodingBannersView.m
Copy path
File metadata and controls
175 lines (159 loc) · 6.98 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
//
//
CodingBannersView.m
//
Coding_iOS
//
//
Created by Ease on 15/7/29.
//
Copyright (c) 2015年 Coding. All rights reserved.
//
#
import
"
CodingBannersView.h
"
#
import
"
SMPageControl.h
"
#
import
"
AutoSlideScrollView.h
"
#
import
"
YLImageView.h
"
@interface
CodingBannersView
()
@property
(
assign
,
nonatomic
) CGFloat padding_top, padding_bottom, image_width, ratio;
@property
(
strong
,
nonatomic
) UILabel *typeLabel, *titleLabel;
@property
(
strong
,
nonatomic
) SMPageControl *myPageControl;
@property
(
strong
,
nonatomic
) AutoSlideScrollView *mySlideView;
@property
(
strong
,
nonatomic
)
NSMutableArray
*imageViewList;
@end
@implementation
CodingBannersView
- (
instancetype
)
init
{
self = [
super
init
];
if
(self) {
self.
backgroundColor
=
kColorTableBG
;
_padding_top =
0
;
_padding_bottom =
44
;
_image_width =
kScreen_Width
;
_ratio =
0.4
;
CGFloat viewHeight = _padding_top + _padding_bottom + _image_width * _ratio;
[
self
setSize:
CGSizeMake
(
kScreen_Width
, viewHeight)];
[
self
addLineUp:
NO
andDown:
YES
];
}
return
self;
}
- (
void
)
setCurBannerList
:
(
NSArray
*)
curBannerList
{
if
([[_curBannerList
valueForKey:
@"
title
"
]
isEqualToArray:
[curBannerList
valueForKey:
@"
title
"
]]) {
return
;
}
_curBannerList = curBannerList;
if
(!_mySlideView) {
_mySlideView = ({
__weak
typeof
(self) weakSelf = self;
AutoSlideScrollView *slideView = [[AutoSlideScrollView
alloc
]
initWithFrame:
CGRectMake
(
0
, _padding_top, _image_width, _image_width * _ratio)
animationDuration:
5.0
];
slideView.
layer
.
masksToBounds
=
YES
;
slideView.
scrollView
.
scrollsToTop
=
NO
;
slideView.
totalPagesCount
= ^
NSInteger
(){
return
weakSelf.
curBannerList
.
count
;
};
slideView.
fetchContentViewAtIndex
= ^UIView *(
NSInteger
pageIndex){
if
(weakSelf.
curBannerList
.
count
> pageIndex) {
YLImageView *imageView = [weakSelf
p_reuseViewForIndex:
pageIndex];
CodingBanner *curBanner = weakSelf.
curBannerList
[pageIndex];
[imageView
sd_setImageWithURL:
[curBanner.image
urlWithCodePath
]];
return
imageView;
}
else
{
return
[UIView
new
];
}
};
slideView.
currentPageIndexChangeBlock
= ^(
NSInteger
currentPageIndex){
if
(weakSelf.
curBannerList
.
count
> currentPageIndex) {
CodingBanner *curBanner = weakSelf.
curBannerList
[currentPageIndex];
weakSelf.
typeLabel
.
text
= curBanner.
displayName
;
weakSelf.
titleLabel
.
text
= curBanner.
title
;
}
else
{
weakSelf.
typeLabel
.
text
= weakSelf.
titleLabel
.
text
=
@"
...
"
;
}
weakSelf.
myPageControl
.
currentPage
= currentPageIndex;
};
slideView.
tapActionBlock
= ^(
NSInteger
pageIndex){
if
(weakSelf.
tapActionBlock
&& weakSelf.
curBannerList
.
count
> pageIndex) {
weakSelf.
tapActionBlock
(weakSelf.
curBannerList
[pageIndex]);
}
};
slideView;
});
[
self
addSubview:
_mySlideView];
}
if
(!_myPageControl) {
_myPageControl = ({
SMPageControl *pageControl = [[SMPageControl
alloc
]
initWithFrame:
CGRectMake
(
kScreen_Width
-
kPaddingLeftWidth
-
30
, _mySlideView.bottom + (_padding_bottom -
10
)/
2
,
30
,
10
)];
pageControl.
userInteractionEnabled
=
NO
;
pageControl.
backgroundColor
= [UIColor
clearColor
];
pageControl.
pageIndicatorImage
= [UIImage
imageNamed:
@"
banner__page_unselected
"
];
pageControl.
currentPageIndicatorImage
= [UIImage
imageNamed:
@"
banner__page_selected
"
];
pageControl.
numberOfPages
= _curBannerList.
count
;
pageControl.
currentPage
=
0
;
pageControl.
alignment
= SMPageControlAlignmentRight;
pageControl;
});
[
self
addSubview:
_myPageControl];
}
if
(!_typeLabel) {
_typeLabel = ({
UILabel *label = [UILabel
labelWithFont:
[UIFont
systemFontOfSize:
10
]
textColor:
kColorDark7
];
[label
setContentHuggingPriority:
UILayoutPriorityRequired
forAxis:
UILayoutConstraintAxisHorizontal];
[label
setContentCompressionResistancePriority:
UILayoutPriorityRequired
forAxis:
UILayoutConstraintAxisHorizontal];
[label
doBorderWidth:
0.5
color:
nil
cornerRadius:
2.0
];
label.
textAlignment
= NSTextAlignmentCenter;
label.
text
=
@"
活动
"
;
label;
});
_typeLabel.
text
= [(CodingBanner *)_curBannerList.firstObject
displayName
];
[
self
addSubview:
_typeLabel];
}
if
(!_titleLabel) {
_titleLabel = [UILabel
labelWithFont:
[UIFont
systemFontOfSize:
12
]
textColor:
kColorDark4
];
_titleLabel.
text
= [(CodingBanner *)_curBannerList.firstObject
title
];
[
self
addSubview:
_titleLabel];
}
[_typeLabel
mas_makeConstraints:
^(MASConstraintMaker *make) {
make.
left
.
equalTo
(self).
offset
(
kPaddingLeftWidth
);
make.
centerY
.
equalTo
(_myPageControl);
make.
height
.
mas_equalTo
(
18
);
}];
[_titleLabel
mas_makeConstraints:
^(MASConstraintMaker *make) {
make.
left
.
equalTo
(_typeLabel.
mas_right
).
offset
(
10
);
make.
right
.
equalTo
(_myPageControl.
mas_left
).
offset
(-
10
);
make.
centerY
.
equalTo
(_myPageControl);
}];
[
self
reloadData
];
NSLog
(
@"
%@
"
, _curBannerList);
}
- (YLImageView *)
p_reuseViewForIndex
:
(
NSInteger
)
pageIndex
{
if
(!_imageViewList) {
_imageViewList = [[
NSMutableArray
alloc
]
initWithCapacity:
3
];
for
(
int
i =
0
; i <
3
; i++) {
YLImageView *view = [[YLImageView
alloc
]
initWithFrame:
CGRectMake
(
kPaddingLeftWidth
, _padding_top, _image_width, _image_width * _ratio)];
view.
backgroundColor
= [UIColor
colorWithHexString:
@"
0xe5e5e5
"
];
view.
clipsToBounds
=
YES
;
view.
contentMode
= UIViewContentModeScaleAspectFill;
[_imageViewList
addObject:
view];
}
}
YLImageView *imageView;
NSInteger
currentPageIndex = self.
mySlideView
.
currentPageIndex
;
if
(pageIndex == currentPageIndex) {
imageView = _imageViewList[
1
];
}
else
if
(pageIndex == currentPageIndex +
1
|| (
labs
(pageIndex - currentPageIndex) >
1
&& pageIndex < currentPageIndex)){
imageView = _imageViewList[
2
];
}
else
{
imageView = _imageViewList[
0
];
}
return
imageView;
}
- (
void
)
reloadData
{
self.
hidden
= _curBannerList.
count
<=
0
;
if
(_curBannerList.
count
<=
0
) {
return
;
}
NSInteger
currentPageIndex =
MIN
(self.
mySlideView
.
currentPageIndex
, _curBannerList.
count
-
1
) ;
CodingBanner *curBanner = _curBannerList[currentPageIndex];
_titleLabel.
text
= curBanner.
title
;
_typeLabel.
text
= curBanner.
displayName
;
_myPageControl.
numberOfPages
= _curBannerList.
count
;
_myPageControl.
currentPage
= currentPageIndex;
[_mySlideView
reloadData
];
}
@end
Back
|
FazBrowse Home
|
New Git URL