瀑布流接口的设计以及应用(四)
2015-07-15 22:57
267 查看
//
// 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
// 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
相关文章推荐
- 简化通知中心的使用
- Android -- Volley解析
- linux系统时间同步,硬件时钟和系统时间同步,时区的设置
- 二分查找法及其应用
- java的myeclipse,java页面修改默认的javadoc方法
- jquery 连接在div中显示
- android 游戏sdk嫁接方式
- ORACLE中创建表空间,创建表,修改表,授权
- 40岁应该学会的是面对和取舍
- java网络编程(1)
- Eclipse中设置ButterKnife进行注解式开发步骤
- Android网络框架-Volley(五) 使用Volley发送自定义Request
- 大数据技术之Flume研究摘要(一)
- 瀑布流接口的设计以及应用(三)
- 指针(一)
- 欢迎来到我的博客~
- 2015.07.15总结
- 【LintCode】 Find Minimum in Rotated Sorted Array 寻找旋转排序数组中的最小值
- Mac下的UI自动化测试 (一)
- objdump及GDB的调试命令