效果如上图所示
//写到获取信息后的请求完成里面
//数据示例*********
{
Latas = (
330ML,
500ML
);
Marca = (
Refriango
);
Latas = (
330ML,
500ML
);
Marca = (
Refriango
);
}
********************/
for (UIView *viewin_selectScrollView.subviews)
{
if (view !=_nameLabel && view !=logoImageView && view !=priceLabel && view !=line_scroll) {
[view removeFromSuperview];
}
}
selectYES = [NSMutableArrayarrayWithArray:[[_dataDictobjectForKey:@"attr"]componentsSeparatedByString:@","]];
_moreHeight =120;
int j =0;
int k =1;
int l =0;
//BOOL _default = NO;
for (NSString *keyin details) {
NSMutableArray *arr = [NSMutableArrayarrayWithArray:[detailsobjectForKey:key]];
j = 0;
if (view !=_nameLabel && view !=logoImageView && view !=priceLabel && view !=line_scroll) {
[view removeFromSuperview];
}
}
selectYES = [NSMutableArrayarrayWithArray:[[_dataDictobjectForKey:@"attr"]componentsSeparatedByString:@","]];
_moreHeight =120;
int j =0;
int k =1;
int l =0;
//BOOL _default = NO;
for (NSString *keyin details) {
NSMutableArray *arr = [NSMutableArrayarrayWithArray:[detailsobjectForKey:key]];
j = 0;
for (int
i=0; i<arr.count; i++) {
NSString *str = [NSStringstringWithFormat:@"%@",[arrobjectAtIndex:i]];
NSDictionary *dictSize = [NSDictionarydictionaryWithObjectsAndKeys:[UIFontsystemFontOfSize:14.0],NSFontAttributeName,nil];
CGSize size = [strboundingRectWithSize:CGSizeMake(_selectScrollView.bounds.size.width-100,20)options:NSStringDrawingUsesLineFragmentOriginattributes:dictSizecontext:nil].size;
UILabel *label = [[UILabelalloc]init];
label.font = [UIFontsystemFontOfSize:14.0];
label.textAlignment =NSTextAlignmentCenter;
label.layer.cornerRadius =2.0;
label.layer.masksToBounds =NO;
label.textColor = [UIColorblackColor];
label.layer.borderWidth =0.5;
label.tag =1000*k + i;
label.layer.borderColor =ColorWihtRGB(175,175,175,1.0).CGColor;
if (i ==0) {
label.frame =CGRectMake(10,_moreHeight+10+l*10, size.width+10,20);
_prevWith = size.width+20;
_moreThanWideHeight =_moreHeight+10;
} else {
label.frame =CGRectMake(_prevWith+10,_moreThanWideHeight+l*10, size.width+20,20);
_prevWith += size.width+30;
}
if (_prevWith >_selectScrollView.bounds.size.width-20) {
_prevWith =10;
label.frame =CGRectMake(_prevWith,_moreThanWideHeight+30+l*10, size.width+20,20);
_prevWith = size.width+30;
_moreThanWideHeight +=30;
//_moreHeight = _moreThanWideHeight;
j++;
}
label.text = str;
[_selectScrollViewaddSubview:label];
UITapGestureRecognizer *tap = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(attributeSelect:)];
label.userInteractionEnabled =YES;
[label addGestureRecognizer:tap];
for (NSString *strinselectYES) {
if ([strisEqualToString:label.text]) {
label.layer.borderColor =ColorWihtRGB(240,75,75,1.0).CGColor;
break;
}
}
}
UILabel *nameLabel = [[UILabelalloc]initWithFrame:CGRectMake(10,_moreHeight-25+l*10,_selectScrollView.bounds.size.width-20,40)];
nameLabel.text = key;
nameLabel.font = [UIFontsystemFontOfSize:14.0];
[_selectScrollViewaddSubview:nameLabel];
_moreHeight +=40+j*30;
k++;
l++;
}
UILabel *nameLabel = [[UILabelalloc]initWithFrame:CGRectMake(10,_moreHeight+l*10-5,_selectScrollView.bounds.size.width-20,20)];
nameLabel.text =NSLocalizedString(@"数量","Localizable");
nameLabel.font = [UIFontsystemFontOfSize:14.0];
[_selectScrollViewaddSubview:nameLabel];
bgView_num.frame =CGRectMake(10,_moreHeight+20+l*10,93,28);
[_selectScrollViewaddSubview:bgView_num];
NSDictionary *dictSize = [NSDictionarydictionaryWithObjectsAndKeys:[UIFontsystemFontOfSize:14.0],NSFontAttributeName,nil];
CGSize size = [strboundingRectWithSize:CGSizeMake(_selectScrollView.bounds.size.width-100,20)options:NSStringDrawingUsesLineFragmentOriginattributes:dictSizecontext:nil].size;
UILabel *label = [[UILabelalloc]init];
label.font = [UIFontsystemFontOfSize:14.0];
label.textAlignment =NSTextAlignmentCenter;
label.layer.cornerRadius =2.0;
label.layer.masksToBounds =NO;
label.textColor = [UIColorblackColor];
label.layer.borderWidth =0.5;
label.tag =1000*k + i;
label.layer.borderColor =ColorWihtRGB(175,175,175,1.0).CGColor;
if (i ==0) {
label.frame =CGRectMake(10,_moreHeight+10+l*10, size.width+10,20);
_prevWith = size.width+20;
_moreThanWideHeight =_moreHeight+10;
} else {
label.frame =CGRectMake(_prevWith+10,_moreThanWideHeight+l*10, size.width+20,20);
_prevWith += size.width+30;
}
if (_prevWith >_selectScrollView.bounds.size.width-20) {
_prevWith =10;
label.frame =CGRectMake(_prevWith,_moreThanWideHeight+30+l*10, size.width+20,20);
_prevWith = size.width+30;
_moreThanWideHeight +=30;
//_moreHeight = _moreThanWideHeight;
j++;
}
label.text = str;
[_selectScrollViewaddSubview:label];
UITapGestureRecognizer *tap = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(attributeSelect:)];
label.userInteractionEnabled =YES;
[label addGestureRecognizer:tap];
for (NSString *strinselectYES) {
if ([strisEqualToString:label.text]) {
label.layer.borderColor =ColorWihtRGB(240,75,75,1.0).CGColor;
break;
}
}
}
UILabel *nameLabel = [[UILabelalloc]initWithFrame:CGRectMake(10,_moreHeight-25+l*10,_selectScrollView.bounds.size.width-20,40)];
nameLabel.text = key;
nameLabel.font = [UIFontsystemFontOfSize:14.0];
[_selectScrollViewaddSubview:nameLabel];
_moreHeight +=40+j*30;
k++;
l++;
}
UILabel *nameLabel = [[UILabelalloc]initWithFrame:CGRectMake(10,_moreHeight+l*10-5,_selectScrollView.bounds.size.width-20,20)];
nameLabel.text =NSLocalizedString(@"数量","Localizable");
nameLabel.font = [UIFontsystemFontOfSize:14.0];
[_selectScrollViewaddSubview:nameLabel];
bgView_num.frame =CGRectMake(10,_moreHeight+20+l*10,93,28);
[_selectScrollViewaddSubview:bgView_num];
_selectScrollView.contentSize = CGSizeMake(screenWidth-50, _moreThanWideHeight+30+30+30+l*10);
//点击切换产品
//_propertyDict 产品关联字典 数据示例************
"details":{
"246":"Refriango,500ML",
"243":"Refriango,330ML"
}
*************************/
- (void)attributeSelect:(UITapGestureRecognizer
*)tap {
selectYES = [[NSMutableArrayalloc]init];
for (UILabel *labelin_selectScrollView.subviews) {
if ([labelisKindOfClass:[UILabelclass]]) {
//NSLog(@"%@",label.layer.borderColor);
label.textColor = [UIColorblackColor];
if (label.tag/1000 == tap.view.tag/1000) {
if (label.tag == tap.view.tag) {
NSLog(@"111 == %ld",label.tag);
label.layer.borderColor =ColorWihtRGB(240,75,75,1.0).CGColor;
[selectYESaddObject:label.text];
} else {
if(label.layer.borderColor == ColorWihtRGB(240,75,75,1.0).CGColor) {
[selectYESaddObject:label.text];
} else {
NSLog(@"222 == %ld",label.tag);
label.layer.borderColor =ColorWihtRGB(175,175,175,1.0).CGColor;
}
}
} else {
if(label.layer.borderColor == ColorWihtRGB(240,75,75,1.0).CGColor) {
[selectYESaddObject:label.text];
} else {
NSLog(@"222 == %ld",label.tag);
//label.layer.borderColor = ColorWihtRGB(175, 175, 175, 1.0).CGColor;
}
}
}
}
BOOL _select =NO;
for (NSString *key11in_propertyDict) {
NSArray *arr = [NSMutableArrayarrayWithArray:[[_propertyDictobjectForKey:key11]componentsSeparatedByString:@","]];
NSPredicate *filterPredicate = [NSPredicatepredicateWithFormat:@"NOT (SELF IN %@)",arr];
//过滤数组
NSArray *reslutFilteredArray = [selectYESfilteredArrayUsingPredicate:filterPredicate];
if (reslutFilteredArray.count ==0) {
if ([key11integerValue] == [self.good_idintegerValue]) {
[buyToCarsetBackgroundColor:[UIColorcolorWithRed:240/255.0green:75/255.0blue:75/255.0alpha:1.0]];
buyToCar.selected =YES;
return;
}
self.good_id = key11;
_select = YES;
[buyToCarsetBackgroundColor:[UIColorcolorWithRed:240/255.0green:75/255.0blue:75/255.0alpha:1.0]];
buyToCar.selected =YES;
break;
} else {
[buyToCarsetBackgroundColor:[UIColorcolorWithRed:175/255.0green:175/255.0blue:175/255.0alpha:1.0]];
buyToCar.selected =NO;
}
}
if (_select) {
//NSLog(@"%@",good_id);
[selfgood_info];//获取商品详情的接口调用
} else {
[buyToCarsetBackgroundColor:[UIColorcolorWithRed:175/255.0green:175/255.0blue:175/255.0alpha:1.0]];
for (UILabel *labelin_selectScrollView.subviews) {
if ([labelisKindOfClass:[UILabelclass]]) {
//NSLog(@"%@",label.layer.borderColor);
label.textColor = [UIColorblackColor];
if (label.tag/1000 == tap.view.tag/1000) {
if (label.tag == tap.view.tag) {
NSLog(@"111 == %ld",label.tag);
label.layer.borderColor =ColorWihtRGB(240,75,75,1.0).CGColor;
[selectYESaddObject:label.text];
} else {
if(label.layer.borderColor == ColorWihtRGB(240,75,75,1.0).CGColor) {
[selectYESaddObject:label.text];
} else {
NSLog(@"222 == %ld",label.tag);
label.layer.borderColor =ColorWihtRGB(175,175,175,1.0).CGColor;
}
}
} else {
if(label.layer.borderColor == ColorWihtRGB(240,75,75,1.0).CGColor) {
[selectYESaddObject:label.text];
} else {
NSLog(@"222 == %ld",label.tag);
//label.layer.borderColor = ColorWihtRGB(175, 175, 175, 1.0).CGColor;
}
}
}
}
BOOL _select =NO;
for (NSString *key11in_propertyDict) {
NSArray *arr = [NSMutableArrayarrayWithArray:[[_propertyDictobjectForKey:key11]componentsSeparatedByString:@","]];
NSPredicate *filterPredicate = [NSPredicatepredicateWithFormat:@"NOT (SELF IN %@)",arr];
//过滤数组
NSArray *reslutFilteredArray = [selectYESfilteredArrayUsingPredicate:filterPredicate];
if (reslutFilteredArray.count ==0) {
if ([key11integerValue] == [self.good_idintegerValue]) {
[buyToCarsetBackgroundColor:[UIColorcolorWithRed:240/255.0green:75/255.0blue:75/255.0alpha:1.0]];
buyToCar.selected =YES;
return;
}
self.good_id = key11;
_select = YES;
[buyToCarsetBackgroundColor:[UIColorcolorWithRed:240/255.0green:75/255.0blue:75/255.0alpha:1.0]];
buyToCar.selected =YES;
break;
} else {
[buyToCarsetBackgroundColor:[UIColorcolorWithRed:175/255.0green:175/255.0blue:175/255.0alpha:1.0]];
buyToCar.selected =NO;
}
}
if (_select) {
//NSLog(@"%@",good_id);
[selfgood_info];//获取商品详情的接口调用
} else {
[buyToCarsetBackgroundColor:[UIColorcolorWithRed:175/255.0green:175/255.0blue:175/255.0alpha:1.0]];
buyToCar.selected = NO;
}