新浪微博开发之十七(图片工具)

//
//  MyPictureTool.h
//  新浪微博
//
//  Created by jose on 15-3-30.
//  Copyright (c) 2015年 jose. All rights reserved.
//  图片工具


#import <UIKit/UIKit.h>


@interface MyPictureTool : UIView
-(void)AddImage:(UIImage *)image;
//保存添加的图片数组
-(NSArray *)SaveImages;

@end


******************************************************************************************************************************************************

*****************************************************************************************************************************************************

*******************************************************************************************************************************************************

//
//  MyPictureTool.m
//  新浪微博
//
//  Created by jose on 15-3-30.
//  Copyright (c) 2015年 jose. All rights reserved.
//


#import "MyPictureTool.h"
#import "UIView+Extension.h"


@implementation MyPictureTool


//添加图片
-(void)AddImage:(UIImage *)image{
    UIImageView *imageview=[[UIImageView alloc]init];
    //设置图片自适应
    imageview.contentMode=UIViewContentModeScaleToFill;
    //裁剪超出的部分
    imageview.clipsToBounds=YES;
    imageview.image=image;
    [self addSubview:imageview];
}


-(void)layoutSubviews{
    [super layoutSubviews];
    //获取当前视图的子控件有多少个
    NSInteger count=self.subviews.count;
    //一行显示最多的个数
    int maxcol=4;
    //空隙
    CGFloat margin=10;
    //设置图片显示宽高
    CGFloat imgw=(self.width-(maxcol+1)*margin)/maxcol;
    CGFloat imgh=imgw;
    for (int i=0; i<count; i++) {
        int row=i/maxcol;
        int col=i%maxcol;
        //取出当前视图的子视图
        UIImageView *imageview=self.subviews[i];
        //设置图片的大小
        imageview.width=imgw;
        imageview.height=imgh;
        imageview.y=row*(imgh+margin);
        imageview.x=col*(imgw+margin)+margin;
    }
}


//添加一个上传图片的数组
-(NSArray *)SaveImages{
    NSMutableArray *img=[NSMutableArray array];
    for (UIImageView *imageview in self.subviews) {
        [img addObject:imageview.image];
    }
    return img;
}


@end

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值