123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- //
- // RDSHomeTopView.m
- // Temperature
- //
- // Created by RD on 2022/10/25.
- //
- #import "RDSHomeTopView.h"
- #import "NSDate+currentDate.h"
- #import <SDWebImage/SDWebImage.h>
- @interface RDSHomeTopView ()
- @property (weak, nonatomic) IBOutlet UIButton *addBtn;
- @property (weak, nonatomic) IBOutlet UIButton *messageBtn;
- @property (weak, nonatomic) IBOutlet UILabel *titleLab;
- @property (weak, nonatomic) IBOutlet UIImageView *topArrowImageView;
- @property (weak, nonatomic) IBOutlet UIView *firstView;
- @property (weak, nonatomic) IBOutlet UIView *secondView;
- @property (weak, nonatomic) IBOutlet UIView *thirdView;
- @property (weak, nonatomic) IBOutlet NSLayoutConstraint *firstViewWidth;
- @property (weak, nonatomic) IBOutlet UILabel *tempLab;// 温度
- @property (weak, nonatomic) IBOutlet UILabel *cityLab;// 城市
- @property (weak, nonatomic) IBOutlet UILabel *rhLab;// 湿度
- @property (weak, nonatomic) IBOutlet UIView *styleView;
- @property (weak, nonatomic) IBOutlet NSLayoutConstraint *styleHeight;
- @property (weak, nonatomic) UIScrollView *styleScrollView;
- @end
- @implementation RDSHomeTopView
- - (void)awakeFromNib {
- [super awakeFromNib];
- // Initialization code
- [self creatStyleScrollView];
- self.redView.hidden = YES;
- self.titleLab.userInteractionEnabled = YES;
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(titleTapAction:)];
- [self.titleLab addGestureRecognizer:tap];
-
- self.topArrowImageView.userInteractionEnabled = YES;
- UITapGestureRecognizer *imgTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(titleTapAction:)];
- [self.topArrowImageView addGestureRecognizer:imgTap];
- }
- -(void)titleTapAction:(UITapGestureRecognizer *)tap{
- if (self.headTitleClick) {
- self.headTitleClick(self.titleLab);
- }
- }
- - (void)setTitle:(NSString *)title{
- _title = title;
- _titleLab.text = title;
- }
- - (void)setModel:(WeatherModel *)model{
- _model = model;
-
- if (model.name == nil) {
- _cityLab.text = @"点击获取位置";
- _cityLab.textColor = [UIColor colorWithHexString:@"#267AFF"];
- _firstViewWidth.constant = 112;
-
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(firstTapAction)];
- [_firstView addGestureRecognizer:tap];
-
- self.secondView.hidden = YES;
- self.thirdView.hidden = YES;
- }else{
- _cityLab.text = model.name;
- _firstViewWidth.constant = _cityLab.text.length * 10 + 55;
- _cityLab.textColor = [UIColor colorWithHexString:@"#333333"];
-
- _tempLab.text = [NSString stringWithFormat:@"%@°C", model.temperature];
-
- _rhLab.text = [NSString stringWithFormat:@"%@%%", model.humidity];
-
- self.secondView.hidden = NO;
- self.thirdView.hidden = NO;
- }
- }
- -(void)firstTapAction
- {
- if (self.locationClick) {
- self.locationClick();
- }
- }
- - (void)setSystemParameter:(RDSSystemParameterModel *)systemParameter {
- _systemParameter = systemParameter;
- }
- - (IBAction)clickAddBtnAction:(id)sender {
- if (self.addBtnClick) {
- self.addBtnClick(sender);
- }
- }
- - (IBAction)clickMessageBtnAction:(id)sender {
- if (self.messageClick) {
- self.messageClick(sender);
- }
- }
- -(void)creatStyleScrollView{
- UIScrollView *styleScrollView = [[UIScrollView alloc]init];
- styleScrollView.showsVerticalScrollIndicator = NO;
- styleScrollView.showsHorizontalScrollIndicator = NO;
- [self.styleView addSubview:styleScrollView];
- self.styleScrollView = styleScrollView;
- [styleScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(@0);
- make.right.equalTo(@0);
- make.bottom.equalTo(@0);
- make.top.equalTo(@0);
- }];
-
- [self addItemView];
- }
- -(void)setScenesArray:(NSArray *)scenesArray
- {
- _scenesArray = scenesArray;
- [self addItemView];
- }
- -(void)addItemView{
- CGFloat itemWidth = 130;
- CGFloat itemSpace = 15;
- self.styleScrollView.contentSize = CGSizeMake(self.scenesArray.count * (itemWidth + itemSpace), 45);
- [self.styleScrollView removeAllSubviews];
-
- for (int i = 0; i < self.scenesArray.count; i++) {
- YXHomeSceneModel *model = self.scenesArray[i];
- NSString *text = model.name;
-
- YXItemView *itemView = [[YXItemView alloc]init];
- itemView.frame = CGRectMake(i*(itemWidth + itemSpace), 0, itemWidth, self.styleScrollView.frame.size.height);
- [itemView.picImgView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@", TheApiHelper.baseUrlHeadImg, model.icon]]];
-
- itemView.textLabel.text = text;
- itemView.layer.cornerRadius = 5;
- if ([model.status integerValue] == 1) {
- itemView.colorView.backgroundColor = [UIColor colorWithHexString:@"#48E441"];
- }else{
- itemView.colorView.backgroundColor = [UIColor colorWithHexString:@"#CBD0DB"];
- }
- [self.styleScrollView addSubview:itemView];
-
- itemView.tag = i;
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(itemTapAction:)];
- [itemView addGestureRecognizer:tap];
- }
-
- }
- -(void)itemTapAction:(UITapGestureRecognizer *)tap{
- NSInteger tag = tap.view.tag;
- NSArray *views = self.styleScrollView.subviews;
- for (int i = 0; i < views.count; i++) {
- YXItemView *itemView = views[i];
- if (i == tag) {
- itemView.colorView.backgroundColor = [UIColor colorWithHexString:@"#48E441"];
- }else{
- itemView.colorView.backgroundColor = [UIColor colorWithHexString:@"#CBD0DB"];
- }
- }
-
- if (self.itemClick) {
- self.itemClick(tag);
- }
- }
- @end
|