Commit 16252f9d authored by admin's avatar admin

修改轮播图 添加点击事件

parent 3a46e680
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "blue-trilateral_down@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "blue-trilateral_down@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "grey-trilateral_right@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "grey-trilateral_right@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "medal_red@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "medal_red@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "medal_orange@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "medal_orange@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "medal_blue@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "medal_blue@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
......@@ -46,6 +46,19 @@
// #666666
#define kHomeItemTextColor [UIColor colorWithRed:102 / 255.0 green:102 / 255.0 blue:102 / 255.0 alpha:1.0]
// RankingList
// #999999
#define kRankHeadTitleTextColor [UIColor colorWithRed:153 / 255.0 green:153 / 255.0 blue:153 / 255.0 alpha:1.0]
// #006fbc
#define kDateButtonTextColor [UIColor colorWithRed:0 / 255.0 green:111 / 255.0 blue:188 / 255.0 alpha:1.0]
#define kShopCountTextColor [UIColor colorWithRed:255 / 255.0 green:0 / 255.0 blue:0 / 255.0 alpha:1.0]
// #006fbc
#define kScoreTextColor [UIColor colorWithRed:0 / 255.0 green:111 / 255.0 blue:188 / 255.0 alpha:1.0]
// #444444
#define kShopNameTextColor [UIColor colorWithRed:68 / 255.0 green:68 / 255.0 blue:68 / 255.0 alpha:1.0]
// #fe6903
#define kGradeNumberTextColor [UIColor colorWithRed:254 / 255.0 green:105 / 255.0 blue:3 / 255.0 alpha:1.0]
#import "UIView+Extension.h"
#endif /* Constant_h */
......@@ -25,4 +25,5 @@ typedef enum ScoreState : NSUInteger {
@property (nonatomic, strong) UILabel *someoneLabel; // 发表评语的人
@property (nonatomic, strong) UILabel *dateLabel; // 发表时间
@property (nonatomic, strong) UILabel *remarkLabel; // 评语
@property (nonatomic, strong) UIImageView *arrowImageView;
@end
......@@ -24,11 +24,10 @@
#pragma mark - Private Methods
- (void)setup
{
[self.shopNameButton setTitle:@"上海真北店" forState:UIControlStateNormal];
self.scoreLabel.text = @"99分";
self.arrowImageView.image = [UIImage imageNamed:@"grey-trilateral_right"];
self.shopNameButton.titleLabel.font = [UIFont systemFontOfSize:18.0];
self.scoreLabel.textColor = kDateButtonTextColor;
self.gradeView.backgroundColor = [UIColor clearColor];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
......@@ -42,32 +41,55 @@
{
_scoreState = scoreState;
if (self.scoreState == ScoreStateHigh) {
self.gradeImageView.backgroundColor = [UIColor grayColor];
self.gradeImageView.backgroundColor = [UIColor clearColor];
} else {
self.gradeLabel.text = @"4";
self.gradeLabel.textColor = kScoreTextColor;
}
}
#pragma mark - Layz loading
- (UIImageView *)arrowImageView
{
if (!_arrowImageView) {
_arrowImageView = [[UIImageView alloc] init];
_arrowImageView.translatesAutoresizingMaskIntoConstraints = NO;
[self.contentView insertSubview:_arrowImageView aboveSubview:self.shopNameButton];
NSLayoutConstraint *shoppingTop = [NSLayoutConstraint constraintWithItem:_arrowImageView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:19];
[self.contentView addConstraint:shoppingTop];
NSLayoutConstraint *shoppingRight = [NSLayoutConstraint constraintWithItem:_arrowImageView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.shopNameButton attribute:NSLayoutAttributeLeft multiplier:1.0 constant:10];
[self.contentView addConstraint:shoppingRight];
NSLayoutConstraint *shoppingWidth = [NSLayoutConstraint constraintWithItem:_arrowImageView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:8];
[self.contentView addConstraint:shoppingWidth];
NSLayoutConstraint *shoppingHeight = [NSLayoutConstraint constraintWithItem:_arrowImageView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:12];
[self.contentView addConstraint:shoppingHeight];
}
return _arrowImageView;
}
- (UIButton *)shopNameButton
{
if (!_shopNameButton) {
_shopNameButton = [[UIButton alloc] init];
_shopNameButton.translatesAutoresizingMaskIntoConstraints = NO;
_shopNameButton.titleLabel.textAlignment = NSTextAlignmentCenter;
[_shopNameButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[_shopNameButton setTitleColor:kShopNameTextColor forState:UIControlStateNormal];
[self.contentView addSubview:_shopNameButton];
NSLayoutConstraint *shoppingTop = [NSLayoutConstraint constraintWithItem:_shopNameButton attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0];
NSLayoutConstraint *shoppingTop = [NSLayoutConstraint constraintWithItem:_shopNameButton attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:1];
[self.contentView addConstraint:shoppingTop];
NSLayoutConstraint *shoppingLeft = [NSLayoutConstraint constraintWithItem:_shopNameButton attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0];
NSLayoutConstraint *shoppingLeft = [NSLayoutConstraint constraintWithItem:_shopNameButton attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:10];
[self.contentView addConstraint:shoppingLeft];
NSLayoutConstraint *shoppingRight = [NSLayoutConstraint constraintWithItem:_shopNameButton attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.scoreLabel attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0];
[self.contentView addConstraint:shoppingRight];
NSLayoutConstraint *shoppingHeight = [NSLayoutConstraint constraintWithItem:_shopNameButton attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:40];
NSLayoutConstraint *shoppingHeight = [NSLayoutConstraint constraintWithItem:_shopNameButton attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:50];
[self.contentView addConstraint:shoppingHeight];
NSLayoutConstraint *shoppingWidth = [NSLayoutConstraint constraintWithItem:_shopNameButton attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.scoreLabel attribute:NSLayoutAttributeWidth multiplier:1.2 constant:0];
......@@ -84,9 +106,10 @@
_scoreLabel = [[UILabel alloc] init];
_scoreLabel.translatesAutoresizingMaskIntoConstraints = NO;
_scoreLabel.textAlignment = NSTextAlignmentCenter;
_scoreLabel.font = [UIFont systemFontOfSize:17.0];
[self.contentView addSubview:_scoreLabel];
NSLayoutConstraint *scoreTop = [NSLayoutConstraint constraintWithItem:_scoreLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0];
NSLayoutConstraint *scoreTop = [NSLayoutConstraint constraintWithItem:_scoreLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:1];
[self.contentView addConstraint:scoreTop];
NSLayoutConstraint *scoreRight = [NSLayoutConstraint constraintWithItem:_scoreLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.gradeView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0];
......@@ -95,7 +118,7 @@
NSLayoutConstraint *scoreWidth = [NSLayoutConstraint constraintWithItem:_scoreLabel attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.gradeView attribute:NSLayoutAttributeWidth multiplier:1.0 constant:0];
[self.contentView addConstraint:scoreWidth];
NSLayoutConstraint *scoreHeight = [NSLayoutConstraint constraintWithItem:_scoreLabel attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:40];
NSLayoutConstraint *scoreHeight = [NSLayoutConstraint constraintWithItem:_scoreLabel attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:50];
[self.contentView addConstraint:scoreHeight];
}
return _scoreLabel;
......@@ -110,13 +133,13 @@
}
//
NSLayoutConstraint *gradeTop = [NSLayoutConstraint constraintWithItem:_gradeView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0];
NSLayoutConstraint *gradeTop = [NSLayoutConstraint constraintWithItem:_gradeView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:2];
[self.contentView addConstraint:gradeTop];
NSLayoutConstraint *gradeRight = [NSLayoutConstraint constraintWithItem:_gradeView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeRight multiplier:1.0 constant:0];
[self.contentView addConstraint:gradeRight];
NSLayoutConstraint *gradeHeight = [NSLayoutConstraint constraintWithItem:_gradeView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:40];
NSLayoutConstraint *gradeHeight = [NSLayoutConstraint constraintWithItem:_gradeView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:50];
[self.contentView addConstraint:gradeHeight];
return _gradeView;
......@@ -128,7 +151,6 @@
_gradeLabel = [[UILabel alloc] init];
_gradeLabel.translatesAutoresizingMaskIntoConstraints = NO;
_gradeLabel.textAlignment = NSTextAlignmentCenter;
[self.gradeView addSubview:_gradeLabel];
//
......@@ -161,10 +183,10 @@
NSLayoutConstraint *gradeCenterY = [NSLayoutConstraint constraintWithItem:_gradeImageView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.gradeView attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0];
[self.gradeView addConstraint:gradeCenterY];
NSLayoutConstraint *gradeWidth = [NSLayoutConstraint constraintWithItem:_gradeImageView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:30];
NSLayoutConstraint *gradeWidth = [NSLayoutConstraint constraintWithItem:_gradeImageView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:35];
[self.gradeView addConstraint:gradeWidth];
NSLayoutConstraint *gradeHeight = [NSLayoutConstraint constraintWithItem:_gradeImageView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:30];
NSLayoutConstraint *gradeHeight = [NSLayoutConstraint constraintWithItem:_gradeImageView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:34];
[self.gradeView addConstraint:gradeHeight];
}
return _gradeImageView;
......
......@@ -15,7 +15,7 @@
@interface RankingListViewController () <UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UIView *headView;
@property (nonatomic, strong) UIView *lineView1;
@property (nonatomic, strong) NSMutableDictionary *selectedIndexes;
@end
......@@ -57,7 +57,8 @@
self.tableView.tableHeaderView = self.headView;
self.pointLabel1.text = @"月度排名";
self.pointLabel2.text = @"参与商家数量";
self.lineView.backgroundColor = kLineColor;
self.lineView.backgroundColor = kSeparateLineColor;
self.lineView1.backgroundColor = kSeparateLineColor;
self.shoppingCountLabel.textAlignment = NSTextAlignmentCenter;
[self.dateButton addTarget:self action:@selector(changeDateClick:) forControlEvents:UIControlEventTouchUpInside];
}
......@@ -87,11 +88,18 @@
[_selectedIndexes setObject:selectedIndex forKey:path];
if (cell.isDrop) {
[UIView animateWithDuration:0.2 animations:^{
cell.arrowImageView.transform = CGAffineTransformIdentity;
cell.arrowImageView.transform = CGAffineTransformMakeRotation(M_PI / 2);
}];
cell.someoneLabel = [[UILabel alloc] init];
cell.someoneLabel.text = @"集团领导某总";
cell.someoneLabel.font = [UIFont systemFontOfSize:15.0];
cell.someoneLabel.textAlignment = NSTextAlignmentCenter;
cell.someoneLabel.textColor = [UIColor grayColor];
cell.someoneLabel.textColor = kRankHeadTitleTextColor;
cell.someoneLabel.translatesAutoresizingMaskIntoConstraints = NO;
[cell.contentView addSubview:cell.someoneLabel];
......@@ -99,7 +107,7 @@
cell.dateLabel.text = @"2015-09-25 12:12:09";
cell.dateLabel.font = [UIFont systemFontOfSize:15.0];
cell.dateLabel.textAlignment = NSTextAlignmentCenter;
cell.dateLabel.textColor = [UIColor grayColor];
cell.dateLabel.textColor = kRankHeadTitleTextColor;
cell.dateLabel.translatesAutoresizingMaskIntoConstraints = NO;
[cell.contentView addSubview:cell.dateLabel];
......@@ -107,8 +115,7 @@
cell.remarkLabel.translatesAutoresizingMaskIntoConstraints = NO;
cell.remarkLabel.text = @"评语:该店进步非常大,值得大家一起学习!";
cell.remarkLabel.font = [UIFont systemFontOfSize:15.0];
cell.remarkLabel.textAlignment = NSTextAlignmentCenter;
cell.remarkLabel.textColor = [UIColor grayColor];
cell.remarkLabel.textColor = kRankHeadTitleTextColor;
[cell.contentView addSubview:cell.remarkLabel];
NSLayoutConstraint *someoneTop = [NSLayoutConstraint constraintWithItem:cell.someoneLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:cell.shopNameButton attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
......@@ -140,7 +147,7 @@
NSLayoutConstraint *remarkTop = [NSLayoutConstraint constraintWithItem:cell.remarkLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:cell.someoneLabel attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
[cell.contentView addConstraint:remarkTop];
NSLayoutConstraint *remarkLeft = [NSLayoutConstraint constraintWithItem:cell.remarkLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:cell.someoneLabel attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0];
NSLayoutConstraint *remarkLeft = [NSLayoutConstraint constraintWithItem:cell.remarkLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:cell.someoneLabel attribute:NSLayoutAttributeLeft multiplier:1.0 constant:5];
[cell.contentView addConstraint:remarkLeft];
NSLayoutConstraint *remarkRight = [NSLayoutConstraint constraintWithItem:cell.remarkLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:cell.contentView attribute:NSLayoutAttributeRight multiplier:1.0 constant:-20];
......@@ -150,6 +157,12 @@
[cell.contentView addConstraint:remarkHeight];
} else {
[UIView animateWithDuration:0.2 animations:^{
cell.arrowImageView.transform = CGAffineTransformIdentity;
cell.arrowImageView.transform = CGAffineTransformMakeRotation(0);
}];
if (cell.someoneLabel) {
[cell.someoneLabel removeFromSuperview];
cell.someoneLabel = nil;
......@@ -186,10 +199,21 @@
// 前三个店名次显示图片
if (indexPath.row < 3) {
cell.scoreState = ScoreStateHigh;
NSString *imageName = [NSString stringWithFormat:@"medal_0%ld", (long)(indexPath.row + 1)];
cell.gradeImageView.image = [UIImage imageNamed:imageName];
} else {
cell.scoreState = ScoreStateLow;
NSString *rankStr = [NSString stringWithFormat:@"第 %ld 名", (long)(indexPath.row + 1)];
NSMutableAttributedString *rankAttr = [[NSMutableAttributedString alloc] initWithString:rankStr];
[rankAttr addAttributes:@{NSForegroundColorAttributeName:kRankHeadTitleTextColor,NSFontAttributeName:[UIFont systemFontOfSize:14.0f]} range:NSMakeRange(0,1)];
[rankAttr addAttributes:@{NSForegroundColorAttributeName:kGradeNumberTextColor} range:NSMakeRange(1,rankStr.length - 2)];
[rankAttr addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial-BoldMT" size:18.0] range:NSMakeRange(1,rankStr.length - 2)];
[rankAttr addAttributes:@{NSForegroundColorAttributeName:kRankHeadTitleTextColor,NSFontAttributeName:[UIFont systemFontOfSize:14.0f]} range:NSMakeRange(rankStr.length - 1,1)];
[cell.gradeLabel setAttributedText:rankAttr];
}
[cell.shopNameButton setTitle:@"上海真北店" forState:UIControlStateNormal];
cell.scoreLabel.text = @"98";
cell.selectionStyle = UITableViewCellSelectionStyleNone;
// 添加点击事件
[cell.shopNameButton addTarget:self action:@selector(loadMoreInfo:) forControlEvents:UIControlEventTouchUpInside];
......@@ -208,10 +232,10 @@
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if([self cellIsSelected:indexPath]) {
return 90;
return 108;
}
return 40;
return 50;
}
// section高度
......@@ -230,14 +254,14 @@
{
// 创建sectionView
UIView *sectionView = [[UIView alloc] init];
sectionView.backgroundColor = kMineBackGroundColor;
sectionView.backgroundColor = kSectionBackGroundColor;
// 商场
UILabel *shoppingLabel = [[UILabel alloc] init];
shoppingLabel.text = @"商场名称";
shoppingLabel.textAlignment = NSTextAlignmentCenter;
shoppingLabel.textColor = kHomeSectionTitleTextColor;
shoppingLabel.font = [UIFont systemFontOfSize:16.0];
shoppingLabel.textColor = kRankHeadTitleTextColor;
shoppingLabel.font = [UIFont systemFontOfSize:17.0];
shoppingLabel.translatesAutoresizingMaskIntoConstraints = NO;
[sectionView addSubview:shoppingLabel];
......@@ -245,8 +269,8 @@
UILabel *scoreLabel = [[UILabel alloc] init];
scoreLabel.text = @"总分";
scoreLabel.textAlignment = NSTextAlignmentCenter;
scoreLabel.textColor = kHomeSectionTitleTextColor;
scoreLabel.font = [UIFont systemFontOfSize:16.0];
scoreLabel.textColor = kRankHeadTitleTextColor;
scoreLabel.font = [UIFont systemFontOfSize:17.0];
scoreLabel.translatesAutoresizingMaskIntoConstraints = NO;
[sectionView addSubview:scoreLabel];
......@@ -254,13 +278,13 @@
UILabel *gradeLabel = [[UILabel alloc] init];
gradeLabel.text = @"排名";
gradeLabel.textAlignment = NSTextAlignmentCenter;
gradeLabel.textColor = kHomeSectionTitleTextColor;
gradeLabel.font = [UIFont systemFontOfSize:16.0];
gradeLabel.textColor = kRankHeadTitleTextColor;
gradeLabel.font = [UIFont systemFontOfSize:17.0];
gradeLabel.translatesAutoresizingMaskIntoConstraints = NO;
[sectionView addSubview:gradeLabel];
//
NSLayoutConstraint *shoppingTop = [NSLayoutConstraint constraintWithItem:shoppingLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:sectionView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0];
NSLayoutConstraint *shoppingTop = [NSLayoutConstraint constraintWithItem:shoppingLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:sectionView attribute:NSLayoutAttributeTop multiplier:1.0 constant:5];
[sectionView addConstraint:shoppingTop];
NSLayoutConstraint *shoppingLeft = [NSLayoutConstraint constraintWithItem:shoppingLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:sectionView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0];
......@@ -276,7 +300,7 @@
[sectionView addConstraint:shoppingWidth];
//
NSLayoutConstraint *scoreTop = [NSLayoutConstraint constraintWithItem:scoreLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:sectionView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0];
NSLayoutConstraint *scoreTop = [NSLayoutConstraint constraintWithItem:scoreLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:sectionView attribute:NSLayoutAttributeTop multiplier:1.0 constant:5];
[sectionView addConstraint:scoreTop];
NSLayoutConstraint *scoreRight = [NSLayoutConstraint constraintWithItem:scoreLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:gradeLabel attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0];
......@@ -289,7 +313,7 @@
[sectionView addConstraint:scoreBottom];
//
NSLayoutConstraint *gradeTop = [NSLayoutConstraint constraintWithItem:gradeLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:sectionView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0];
NSLayoutConstraint *gradeTop = [NSLayoutConstraint constraintWithItem:gradeLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:sectionView attribute:NSLayoutAttributeTop multiplier:1.0 constant:5];
[sectionView addConstraint:gradeTop];
NSLayoutConstraint *gradeRight = [NSLayoutConstraint constraintWithItem:gradeLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:sectionView attribute:NSLayoutAttributeRight multiplier:1.0 constant:0];
......@@ -308,12 +332,12 @@
if (!_pointLabel1) {
_pointLabel1 = [[UILabel alloc] init];
_pointLabel1.translatesAutoresizingMaskIntoConstraints = NO;
_pointLabel1.textColor = kHomeSectionTitleTextColor;
_pointLabel1.font = [UIFont systemFontOfSize:14.0];
_pointLabel1.textColor = kRankHeadTitleTextColor;
_pointLabel1.font = [UIFont systemFontOfSize:15.0];
_pointLabel1.textAlignment = NSTextAlignmentCenter;
[self.headView addSubview:_pointLabel1];
NSLayoutConstraint *point1Top = [NSLayoutConstraint constraintWithItem:_pointLabel1 attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.headView attribute:NSLayoutAttributeTop multiplier:1.0 constant:5];
NSLayoutConstraint *point1Top = [NSLayoutConstraint constraintWithItem:_pointLabel1 attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.headView attribute:NSLayoutAttributeTop multiplier:1.0 constant:7];
[self.headView addConstraint:point1Top];
NSLayoutConstraint *point1Right = [NSLayoutConstraint constraintWithItem:_pointLabel1 attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.lineView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0];
......@@ -333,12 +357,12 @@
if (!_pointLabel2) {
_pointLabel2 = [[UILabel alloc] init];
_pointLabel2.translatesAutoresizingMaskIntoConstraints = NO;
_pointLabel2.textColor = kHomeSectionTitleTextColor;
_pointLabel2.font = [UIFont systemFontOfSize:14.0];
_pointLabel2.textColor = kRankHeadTitleTextColor;
_pointLabel2.font = [UIFont systemFontOfSize:15.0];
_pointLabel2.textAlignment = NSTextAlignmentCenter;
[self.headView addSubview:_pointLabel2];
NSLayoutConstraint *point2Top = [NSLayoutConstraint constraintWithItem:_pointLabel2 attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.headView attribute:NSLayoutAttributeTop multiplier:1.0 constant:5];
NSLayoutConstraint *point2Top = [NSLayoutConstraint constraintWithItem:_pointLabel2 attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.headView attribute:NSLayoutAttributeTop multiplier:1.0 constant:7];
[self.headView addConstraint:point2Top];
NSLayoutConstraint *point2Right = [NSLayoutConstraint constraintWithItem:_pointLabel2 attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.headView attribute:NSLayoutAttributeRight multiplier:1.0 constant:0];
......@@ -385,9 +409,9 @@
NSString *dateStr = [NSString stringWithFormat:@"2015 年 08 月"];
NSMutableAttributedString *dateAttr = [[NSMutableAttributedString alloc] initWithString:dateStr];
[dateAttr addAttributes:@{NSForegroundColorAttributeName:kNavigationBarColor,NSFontAttributeName:[UIFont systemFontOfSize:20.0f]} range:NSMakeRange(0,5)];
[dateAttr addAttributes:@{NSForegroundColorAttributeName:kDateButtonTextColor,NSFontAttributeName:[UIFont systemFontOfSize:21.0f]} range:NSMakeRange(0,5)];
[dateAttr addAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor],NSFontAttributeName:[UIFont systemFontOfSize:15.0f]} range:NSMakeRange(5,1)];
[dateAttr addAttributes:@{NSForegroundColorAttributeName:kNavigationBarColor,NSFontAttributeName:[UIFont systemFontOfSize:20.0f]} range:NSMakeRange(6,4)];
[dateAttr addAttributes:@{NSForegroundColorAttributeName:kDateButtonTextColor,NSFontAttributeName:[UIFont systemFontOfSize:21.0f]} range:NSMakeRange(6,4)];
[dateAttr addAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor],NSFontAttributeName:[UIFont systemFontOfSize:15.0f]} range:NSMakeRange(10,1)];
[_dateButton setAttributedTitle:dateAttr forState:UIControlStateNormal];
......@@ -415,7 +439,7 @@
_shoppingCountLabel.translatesAutoresizingMaskIntoConstraints = NO;
NSString *shopCount = [NSString stringWithFormat:@"21 家"];
NSMutableAttributedString *shopAttr = [[NSMutableAttributedString alloc] initWithString:shopCount];
[shopAttr addAttributes:@{NSForegroundColorAttributeName:[UIColor redColor],NSFontAttributeName:[UIFont systemFontOfSize:20.0f]} range:NSMakeRange(0,shopCount.length - 2)];
[shopAttr addAttributes:@{NSForegroundColorAttributeName:kShopCountTextColor,NSFontAttributeName:[UIFont systemFontOfSize:21.0f]} range:NSMakeRange(0,shopCount.length - 2)];
[shopAttr addAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor],NSFontAttributeName:[UIFont systemFontOfSize:15.0f]} range:NSMakeRange(shopCount.length - 2,2)];
_shoppingCountLabel.attributedText = shopAttr;
......@@ -462,10 +486,32 @@
return _tableView;
}
- (UIView *)lineView1
{
if (!_lineView1) {
_lineView1 = [[UIView alloc] init];
_lineView1.translatesAutoresizingMaskIntoConstraints = NO;
[self.headView addSubview:_lineView1];
NSLayoutConstraint *lineBottom = [NSLayoutConstraint constraintWithItem:_lineView1 attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.headView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
[self.headView addConstraint:lineBottom];
NSLayoutConstraint *lineLeft = [NSLayoutConstraint constraintWithItem:_lineView1 attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.headView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0];
[self.headView addConstraint:lineLeft];
NSLayoutConstraint *lineRight = [NSLayoutConstraint constraintWithItem:_lineView1 attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.headView attribute:NSLayoutAttributeRight multiplier:1.0 constant:0];
[self.headView addConstraint:lineRight];
NSLayoutConstraint *lineHeight = [NSLayoutConstraint constraintWithItem:_lineView1 attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:2];
[_lineView1 addConstraint:lineHeight];
}
return _lineView1;
}
- (UIView *)headView
{
if (!_headView) {
_headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 70)];
_headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 76)];
_headView.backgroundColor = [UIColor whiteColor];
}
return _headView;
......
......@@ -7,16 +7,14 @@
//
#import "HomeHeaderView.h"
#define kCount 5
#define ImageCount 5
@interface HomeHeaderView () <UIScrollViewDelegate>
{
UIImageView *_centerView;
UIImageView *_reusableView;
}
@property (nonatomic,assign) BOOL isDragging; //是否正在拖动
@property (nonatomic,strong) NSTimer *timer; //设置动画
@end
@implementation HomeHeaderView
......@@ -36,34 +34,29 @@
#pragma mark - Private Methods
- (void)setup
{
_isDragging = NO;
// 天气label
self.weatherLabel.text = @"上海 ⛅️ 多云转晴 21-29℃";
// 设置代理
self.scrollView.delegate = self;
CGFloat w = _scrollView.frame.size.width;
CGFloat h = _scrollView.frame.size.height;
_scrollView.pagingEnabled = YES;
_scrollView.contentSize = CGSizeMake(w * 3, 0);
_scrollView.contentOffset = CGPointMake(w, 0);
_scrollView.showsHorizontalScrollIndicator = NO;
CGFloat width = self.scrollView.frame.size.width;
CGFloat height = self.scrollView.frame.size.height;
_scrollView.contentSize = CGSizeMake(ImageCount * width, 0);
_centerView = [[UIImageView alloc] init];
_centerView.image = [UIImage imageNamed:@"00.jpg"];
_centerView.frame = CGRectMake(w, 0, w, h);
_centerView.tag = 0;
_centerView.userInteractionEnabled = YES;
[_scrollView addSubview:_centerView];
for (int i = 0; i < ImageCount; i++) {
UIImageView *imageView = [[UIImageView alloc] init];
CGFloat imageX = i * width;
CGFloat imageY = 0.f;
imageView.frame = CGRectMake(imageX, imageY, width, height);
imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"0%d", i]];
imageView.userInteractionEnabled = YES;
UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGRClick:)];
[imageView addGestureRecognizer:tapGR];
[_scrollView addSubview:imageView];
}
// 添加点击事件
UITapGestureRecognizer *tapCenterGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGRClick:)];
[_centerView addGestureRecognizer:tapCenterGR];
_reusableView = [[UIImageView alloc] init];
_reusableView.frame = _scrollView.bounds;
UITapGestureRecognizer *tapReusableGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGRClick:)];
[_reusableView addGestureRecognizer:tapReusableGR];
// 设置时钟动画 定时器
self.timer = [NSTimer scheduledTimerWithTimeInterval:1.5f target:self selector:@selector(update:) userInfo:nil repeats:YES];
......@@ -78,12 +71,16 @@
return ;
}
CGPoint offSet = self.scrollView.contentOffset;
offSet.x +=offSet.x;
if (offSet.x == 0) {
offSet.x = _scrollView.frame.size.width;
} else if (offSet.x <= (ImageCount - 2) * _scrollView.frame.size.width){
offSet.x +=_scrollView.frame.size.width;
} else {
offSet.x = 0;
}
[self.scrollView setContentOffset:offSet animated:YES];
if (offSet.x >= self.frame.size.width *2) {
offSet.x = self.frame.size.width;
}
}
- (void)tapGRClick:(UITapGestureRecognizer *)sender
......@@ -95,44 +92,7 @@
#pragma mark - UIScrollView Delegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat offsetX = scrollView.contentOffset.x;
CGFloat w = scrollView.frame.size.width;
// 1.设置 循环利用view 的位置
CGRect f = _reusableView.frame;
NSInteger index = 0;
if (offsetX > _centerView.frame.origin.x) { // 显示在最右边
f.origin.x = scrollView.contentSize.width - w;
index = _centerView.tag + 1;
if (index >= kCount) index = 0;
} else { // 显示在最左边
f.origin.x = 0;
index = _centerView.tag - 1;
if (index < 0) index = kCount - 1;
}
_reusableView.frame = f;
_reusableView.tag = index;
NSString *icon = [NSString stringWithFormat:@"0%ld.jpg", (long)index];
_reusableView.image = [UIImage imageNamed:icon];
// 2.显示了 最左 或者 最右 的图片
if (offsetX <= 0 || offsetX >= w * 2) {
// 2.1.交换 中间的 和 循环利用的
UIImageView *temp = _centerView;
_centerView = _reusableView;
_reusableView = temp;
// 2.2.设置显示位置
_centerView.frame = _reusableView.frame;
scrollView.contentOffset = CGPointMake(w, 0);
[_reusableView removeFromSuperview];
} else {
[_scrollView addSubview:_reusableView];
}
}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
......@@ -152,6 +112,7 @@
_scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height)];
_scrollView.bounces = NO;
_scrollView.pagingEnabled = YES;
_scrollView.delegate = self;
_scrollView.showsHorizontalScrollIndicator = NO;
_scrollView.showsVerticalScrollIndicator = NO;
[self addSubview:_scrollView];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment