// // RightSubView.m // Lighting // // Created by mac on 16/5/10. // Copyright © 2016年 上海勾芒科技有限公司. All rights reserved. // #import "RightSubView.h" @implementation RightSubView - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { [self initdata]; [self initSubView]; } return self; } -(void)initdata { NSString *imageName = [NSString stringWithFormat:@"05产品库-详情_03" ]; UIImage *image= [UIImage imageNamed:imageName]; self.dataArray=[[NSMutableArray alloc]initWithObjects:image,image,image,nil]; // 待接收 } -(void)initSubView { UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom]; button.frame=CGRectMake(self.frame.size.width-100, self.frame.size.height-60, 60, 60); button.tag=300; [button setBackgroundImage:[UIImage imageNamed:@"产品1"] forState:UIControlStateNormal]; [button addTarget:self action:@selector(rightBtnDidSelected:) forControlEvents:UIControlEventTouchUpInside]; [self addSubview:button]; self.scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height-100)]; // 禁用滚动条,只设置水平方向的滚动条即可,竖直方向的滚动范围是0,所以没必要设置 self.scrollView.showsVerticalScrollIndicator = NO; [self addSubview:self.scrollView]; [self showProductPicture]; } -(void)showProductPicture { [self.scrollView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)]; // contentSize的y值为0表示在垂直方向上不做滚动 self.scrollView.contentSize = CGSizeMake(0, (self.dataArray.count+1) * (100+10)); for (int i=0; iindex) { [self.dataArray removeObjectAtIndex:index]; [self showProductPicture]; } } else { } NSLog(@"长按"); } -(void)rightBtnDidSelected:(UIButton *)sender { if ([self.delegate respondsToSelector:@selector(buttonClick:withButton:)]) { [self.delegate buttonClick:sender.tag withButton:sender]; } } -(void)addRightSubViewImage:(UIImage*)image { [self.dataArray addObject:image]; [self showProductPicture]; } /* // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect { // Drawing code } */ @end