iOS综合练习 哈欠阅读

本文介绍了在iOS应用中如何集成常见第三方库,如AFNetworking、SDWebImage等,用于实现图片轮播、下拉菜单、上拉刷新等功能。此外,还展示了如何创建用户资料页面,包括头像选择、昵称、手机号、出生日期等信息的编辑,以及使用UIPickerView和UIDatePicker进行交互操作。
摘要由CSDN通过智能技术生成

常用第三方库:

pod "AFNetworking", “3.0.1”
pod 'MJExtension', '~> 3.0.10'   字典模型
pod 'Masonry', '~> 1.0.0'
pod 'SDWebImage', '~> 3.7.5'
pod 'IQKeyboardManager'         键盘
pod 'TZImagePickerController'   相册、拍照


DOPDropDownMenu - Enhanced  下拉菜单

SDAutoLayout   自适应高度宽度

SDCycleScrollView  轮播

SDRefeshView 上拉刷新

LZCartViewController  购物车

涉及知识点:table表偏移量,购物车利用block回传数值,个人资料出生日期选择,选择相册

#import "HomeViewController.h"

#import "SDCycleScrollView.h"

#import "HomeModels.h"

#import "HomeCell.h"

@interface HomeViewController ()<UITableViewDelegate,UITableViewDataSource>{

    NSArray *photoArray;

    SDRefreshFooterView *_refreshFooter;

}

@property (nonatomic,strong)NSArray *dataArray;

@property(nonatomic,retain)UITableView *tableView;

@property (nonatomic,assign)NSInteger rowCount;

@end


@implementation HomeViewController

#pragma mark - 加载数据

- (NSArray *)dataArray{

    if (_dataArray ==nil) {

        //路径

        NSString *path = [[NSBundlemainBundle]pathForResource:@"Books"ofType:@"plist"];

        

        //读取

        NSArray *tempArray = [NSArrayarrayWithContentsOfFile:path];

        

        //可变

        NSMutableArray *mutableArray = [NSMutableArrayarray];

        NSLog(@"%@",mutableArray);

        

        //转换

        for (NSDictionary *dictin tempArray) {

            HomeModels *homeModels = [HomeModelsmj_objectWithKeyValues:dict];

            [mutableArray addObject:homeModels];

            NSLog(@"homeModels = %@",homeModels);

        }

        

        //赋值

        _dataArray = mutableArray;

    }

    return_dataArray;

}


- (void)viewDidLoad {

    [superviewDidLoad];

    self.view.backgroundColor = [UIColorwhiteColor];

    

    self.tableView = [[UITableViewalloc]initWithFrame:self.view.framestyle:UITableViewStylePlain];

    [self.viewaddSubview:self.tableView];


    UIView *headView = [[UIViewalloc]initWithFrame:CGRectMake(0,0,kMainScreenWidth,kMainScreenWidth+kMainScreenHeight/3)];

    self.tableView.tableHeaderView = headView;

    // 本地加载 ---创建不带标题的图片轮播器

    NSArray *imageArray =@[@"DSC_2709.JPG",@"DSC_2792.JPG"];

    SDCycleScrollView *cycleScrollView = [SDCycleScrollViewcycleScrollViewWithFrame:CGRectMake(0,0,kMainScreenWidth,kMainScreenHeight/3)shouldInfiniteLoop:YESimageNamesGroup:imageArray];

    //    cycleScrollView.delegate = self;

//    cycleScrollView.pageControlStyle = SDCycleScrollViewPageContolStyleAnimated;

    [headView addSubview:cycleScrollView];


    //--- 轮播时间间隔,默认1.0秒,可自定义

    //cycleScrollView.autoScrollTimeInterval = 4.0;

    

    //4张图片按钮

    NSArray *btnPhotos =@[@"DSC_2749.JPG",@"DSC_2784.JPG",@"DSC_2794.JPG",@"DSC_2712.JPG"];

    

    for (int i =0; i<4; i++) {

        float x = (i%2)*(kMainScreenWidth/2);

        float y =CGRectGetMaxY(cycleScrollView.frame)+(i/2)*(kMainScreenWidth/2);

        

        UIButton *imageBtn = [[UIButtonalloc]initWithFrame:CGRectMake(x, y,kMainScreenWidth/2,kMainScreenWidth/2)];

        [imageBtn setImage:[UIImageimageNamed:btnPhotos[i]]forState:UIControlStateNormal];

//        imageBtn.backgroundColor = [UIColor orangeColor];

        imageBtn.tag = i;

        [imageBtn addTarget:selfaction:@selector(getImageBtn:)forControlEvents:UIControlEventTouchUpInside];

        [headView addSubview:imageBtn];

    }

    

    self.tableView.delegate =self;

    self.tableView.dataSource =self;

    

//    [self creatModelsWithCount:18];

    _rowCount = (long)6;

    [self.tableViewregisterClass:[HomeCellclass]forCellReuseIdentifier:NSStringFromClass([HomeCellclass])];

    

    __weaktypeof(self) weakSelf =self;

    

    // 上拉加载

    _refreshFooter = [SDRefreshFooterViewrefreshView];

    [_refreshFooteraddToScrollView:self.tableView];

    __weaktypeof(_refreshFooter) weakRefreshFooter =_refreshFooter;

    _refreshFooter.beginRefreshingOperation = ^() {

        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 *NSEC_PER_SEC)),dispatch_get_main_queue(), ^{

//            [weakSelf creatModelsWithCount:10];

            weakSelf.rowCount +=6;

            [weakSelf.tableViewreloadData];

            [weakRefreshFooter endRefreshing];

        });

    };

    [self.tableViewreloadData];

    

}


-(void)getImageBtn:(UIButton *)imageBtn{


}


- (void)cycleScrollView{

    // 本地加载 ---创建不带标题的图片轮播器

    NSArray *imageArray =@[@"DSC_2709.JPG",@"DSC_2749.JPG",@"DSC_2792.JPG"];

    SDCycleScrollView *cycleScrollView = [SDCycleScrollViewcycleScrollViewWithFrame:CGRectMake(0,0,kMainScreenWidth,kMainScreenHeight/3)shouldInfiniteLoop:YESimageNamesGroup:imageArray];

//    cycleScrollView.delegate = self;

    cycleScrollView.pageControlStyle =SDCycleScrollViewPageContolStyleAnimated;

    [self.viewaddSubview:cycleScrollView];

//    [self.view addSubview:cycleScrollView];

//    cycleScrollView.scrollDirection = UICollectionViewScrollDirectionVertical;

    //         --- 轮播时间间隔,默认1.0秒,可自定义

    //cycleScrollView.autoScrollTimeInterval = 4.0;

}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

#warning Incomplete implementation, return the number of sections

    return1;

}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

#warning Incomplete implementation, return the number of rows

    returnself.dataArray.count;

}


 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

     Class currentClass = [HomeCellclass];

     HomeCell *cell =nil;     

     HomeModels *model =_dataArray[indexPath.row];

     cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(currentClass)];

     

     cell.model = model; 

 return cell;

}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

    Class currentClass = [HomeCellclass];    

    HomeModels *model =_dataArray[indexPath.row];

    /*

     普通版也可实现一步设置搞定高度自适应,不再推荐使用此套方法,具体参看“UITableView+SDAutoTableViewCellHeight”头文件

     return [self.tableView cellHeightForIndexPath:indexPath model:model keyPath:@"model" cellClass:currentClass];

     */

    

    // 推荐使用此普通简化版方法(一步设置搞定高度自适应,性能好,易用性好)

    return [self.tableViewcellHeightForIndexPath:indexPathmodel:modelkeyPath:@"model"cellClass:currentClasscontentViewWidth:[selfcellContentViewWith]];

}


- (CGFloat)cellContentViewWith

{

    CGFloat width = [UIScreenmainScreen].bounds.size.width;    

    // 适配ios7横屏

    if ([UIApplicationsharedApplication].statusBarOrientation !=UIInterfaceOrientationPortrait && [[UIDevicecurrentDevice].systemVersionfloatValue] < 8) {

        width = [UIScreenmainScreen].bounds.size.height;

    }

    return width;

}



#import "HomeCell.h"

#import "HomeModels.h"

@implementation HomeCell

{

    UILabel *_titleLabel;

    UIImageView *_imageView;

    UILabel *_price;

}


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

{

    if (self = [superinitWithStyle:stylereuseIdentifier:reuseIdentifier]) {

        [selfsetup];

    }

    returnself;

}


- (void)setup

{

    _titleLabel = [UILabelnew];

    [self.contentViewaddSubview:_titleLabel];

    _titleLabel.textColor = [UIColordarkGrayColor];

    _titleLabel.font = [UIFontsystemFontOfSize:15];

    _titleLabel.numberOfLines =0;

    

    _imageView = [UIImageViewnew];

    [self.contentViewaddSubview:_imageView];

    _imageView.layer.borderColor = [UIColorgrayColor].CGColor;

    _imageView.layer.borderWidth =1;

    

    _price = [UILabelnew];

    [self.contentViewaddSubview:_price];

    

    CGFloat margin =15;

    UIView *contentView =self.contentView;

    

    _imageView.sd_layout

    .topSpaceToView(contentView, margin)//距离顶

    .leftSpaceToView(contentView, margin)//

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值