// MyShopCell.h
// 瀑布流
//
// Created by Jose on 15-7-12.
// Copyright (c) 2015年 Jose. All rights reserved.
//
#import "MyWaterFlowViewCell.h"
@class MyWaterFlowView,MyShop;
@interface MyShopCell : MyWaterFlowViewCell
+(instancetype)cellWithWaterFlowView:(MyWaterFlowView *)mywaterflowview;
@property(nonatomic,strong)MyShop *shop;
@end
**************************************************************************************************************
*************************************************************************************************************
*************************************************************************************************************
//
// MyShopCell.m
// 瀑布流
//
// Created by Jose on 15-7-12.
// Copyright (c) 2015年 Jose. All rights reserved.
//
#import "MyShopCell.h"
#import "MyWaterFlowView.h"
#import "MyShop.h"
#import "UIImageView+WebCache.h"
@interface MyShopCell()
/**显示商品的图片*/
@property(nonatomic,weak)UIImageView *imageview;
/**显示商品的价格*/
@property(nonatomic,weak)UILabel *pricelabel;
@end
@implementation MyShopCell
-(id)initWithFrame:(CGRect)frame{
self=[super initWithFrame:frame];
if (self) {
//设置显示图片的控件
UIImageView *imageview=[[UIImageView alloc]init];
[self addSubview:imageview];
self.imageview=imageview;
//设置价格的控件
UILabel *label=[[UILabel alloc]init];
label.backgroundColor=[UIColor colorWithRed:0 green:0 blue:0 alpha:0.3];
label.textAlignment=NSTextAlignmentCenter;
label.textColor=[UIColor whiteColor];
[self addSubview:label];
self.pricelabel=label;
}
return self;
}
+(instancetype)cellWithWaterFlowView:(MyWaterFlowView *)mywaterflowview{
static NSString *ID=@"shop";
MyShopCell *cell=[mywaterflowview dequeueReusableCellWithIdentifier:ID];
if (cell==nil) {
cell=[[MyShopCell alloc]init];
cell.identifier=ID;
}
return cell;
}
//通过set进行赋值
-(void)setShop:(MyShop *)shop{
_shop=shop;
self.pricelabel.text=shop.price;
[self.imageview sd_setImageWithURL:[NSURL URLWithString:shop.img] placeholderImage:[UIImage imageNamed:@"loading"]];
}
-(void)layoutSubviews{
[super layoutSubviews];
self.imageview.frame=self.bounds;
CGFloat pricex=0;
CGFloat priceh=25;
CGFloat pricey=self.bounds.size.height-priceh;
CGFloat pricew=self.bounds.size.width;
self.pricelabel.frame=CGRectMake(pricex, pricey, pricew, priceh);
}
@end