iOS开发-团购例子Demo展示

那么今天给同学们带来一个团购的小demo,主要包括图片轮播器,自定义cell,以及刷新表格,其中涉及很多基础和细节的东西,那么废话不多说,先看效果图,直接上代码!

//

//  ZZTg.h

//  07-团购

//

//  Created by 周昭 on 16/11/22.

//  Copyright © 2016年 HT_Technology. All rights reserved.

//

 

#import <Foundation/Foundation.h>

 

@interface ZZTg : NSObject

/**

 *  标题

 */

@property (nonatomic,copy) NSString *title;

/**

 *  价格

 */

@property (nonatomic,copy) NSString *price;

/**

 *  图片

 */

@property (nonatomic,copy) NSString *icon;

/**

 *  购买人数

 */

@property (nonatomic,copy) NSString *buyCount;

 

+ (instancetype)tgWithDict:(NSDictionary *)dict;

 

- (instancetype)initWithDict:(NSDictionary *)dict;

 

@end

 

//

//  ZZTg.m

//  07-团购

//

//  Created by 周昭 on 16/11/22.

//  Copyright © 2016年 HT_Technology. All rights reserved.

//

 

#import "ZZTg.h"

 

@implementation ZZTg

+ (instancetype)tgWithDict:(NSDictionary *)dict

{

    return [[selfalloc] initWithDict:dict];

}

 

 

- (instancetype)initWithDict:(NSDictionary *)dict

{

    if (self = [superinit]) {

#pragma mark - kvc 直接字典转模型

        [selfsetValuesForKeysWithDictionary:dict];

    }

    

    returnself;

}

@end

 

//

//  ZZTgHeader.h

//  07-团购

//

//  Created by 周昭 on 16/11/22.

//  Copyright © 2016年 HT_Technology. All rights reserved.

//

 

#import <Foundation/Foundation.h>

 

@interface ZZTgHeader : NSObject

/**

 *  图标

 */

@property (nonatomic,copy) NSString *icon;

 

+ (instancetype)headerWithDict:(NSDictionary *)dict;

 

- (instancetype)initWithDict:(NSDictionary *)dict;

@end

 

//

//  ZZTgHeader.m

//  07-团购

//

//  Created by 周昭 on 16/11/22.

//  Copyright © 2016年 HT_Technology. All rights reserved.

//

 

#import "ZZTgHeader.h"

 

@implementation ZZTgHeader

+ (instancetype)headerWithDict:(NSDictionary *)dict

{

    return [[selfalloc] initWithDict:dict];

}

 

- (instancetype)initWithDict:(NSDictionary *)dict

{

    if (self = [superinit]) {

        [selfsetValuesForKeysWithDictionary:dict];

    }

    returnself;

}

@end

 

//

//  ZZTgCell.h

//  07-团购

//

//  Created by 周昭 on 16/11/22.

//  Copyright © 2016年 HT_Technology. All rights reserved.

//

 

#import <UIKit/UIKit.h>

 

@class ZZTg;

@interface ZZTgCell :UITableViewCell

/**

 *  团购模型

 */

@property (nonatomic,strong) ZZTg *tg;

 

/**

 *  通过一个tableView来创建一个cell

 */

+ (instancetype)cellWithTableView:(UITableView *)tableView;

 

@end

 

//

//  ZZTgCell.m

//  07-团购

//

//  Created by 周昭 on 16/11/22.

//  Copyright © 2016年 HT_Technology. All rights reserved.

//

 

#import "ZZTgCell.h"

#import "ZZTg.h"

 

@interface ZZTgCell()

/**

 *  图标

 */

@property (nonatomic,weak) UIImageView *iconImg;

/**

 *  标题

 */

@property (nonatomic,weak) UILabel *titleLabel;

/**

 *  价格

 */

@property (nonatomic,weak) UILabel *priceLabel;

/**

 *  购买数

 */

@property (nonatomic,weak) UILabel *buyLabel;

 

@end

 

@implementation ZZTgCell

+ (instancetype)cellWithTableView:(UITableView *)tableView

{

    staticNSString *ID = @"tg";

    ZZTgCell *cell = [tableViewdequeueReusableCellWithIdentifier:ID];

    if (cell ==nil) {

        cell = [[ZZTgCellalloc] initWithStyle:UITableViewCellStyleSubtitlereuseIdentifier:ID];

    }

    return cell;

}

 

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier

{

    self = [superinitWithStyle:style reuseIdentifier:reuseIdentifier];

    

    UIImageView *iconImg = [[UIImageViewalloc] init];

    [self.contentViewaddSubview:iconImg];

    self.iconImg = iconImg;

    

    UILabel *titleLabel = [[UILabelalloc] init];

    titleLabel.font = [UIFontboldSystemFontOfSize:16.0f];

    [self.contentViewaddSubview:titleLabel];

    self.titleLabel = titleLabel;

    

    UILabel *priceLabel = [[UILabelalloc] init];

    priceLabel.font = [UIFontsystemFontOfSize:15.5f];

    priceLabel.textColor = [UIColorcolorWithRed:239 /255.0 green:134 /255.0 blue:130 /255.0 alpha:1.0];

    [self.contentViewaddSubview:priceLabel];

    self.priceLabel = priceLabel;

    

    UILabel *buyLabel = [[UILabelalloc] init];

    buyLabel.font = [UIFontsystemFontOfSize:14.0f];

    buyLabel.textColor = [UIColorlightGrayColor];

    buyLabel.textAlignment =NSTextAlignmentRight;

    [self.contentViewaddSubview:buyLabel];

    self.buyLabel = buyLabel;

 

    returnself;

}

 

/**

 *  拿到真实的尺寸进行布局

 */

- (void)layoutSubviews

{

    [superlayoutSubviews];

    

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值