自动布局,防京东商品属性,Label自适应
来源:互联网 发布:手机破解软件 编辑:程序博客网 时间:2024/06/05 05:42
效果如上图所示
//写到获取信息后的请求完成里面
//数据示例*********
{
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;
}
0 0
- 自动布局,防京东商品属性,Label自适应
- 自动布局小知识--UITableViewCell自定义高度,Label长度自适应
- 商品添加-选择商品类型自动加载商品属性
- css3 calc()自适应布局属性
- Label自适应
- label自适应
- iOS label 根据内容自动布局
- Masonry自动布局label少一行'bug'
- Label字体大小自适应label
- Label--Label自适应
- iOS label自适应宽度 左端对齐 自动换行
- iOS中AutoLayout自动布局,自适应高度
- 基于StoryBoard自动布局--Cell自适应高度
- iOS 关于自动布局 自适应宽高
- iOS 9 Auto Layout界面自动布局系列-自适应布局
- android:高仿京东商品属性筛选(流式布局)
- 自动布局下设置Label的宽度和获取Label的高度
- 自适应label的宽度
- 每天一个linux命令:ln 命令
- 如何搭建Spring4项目
- 设计模式之观察者模式
- Linux进程编程
- android电池驱动(五)(自用)
- 自动布局,防京东商品属性,Label自适应
- 读书笔记MoreEffectiveC++(16)
- Gdb调试多进程程序
- OC属性
- 【Tomcat】Tomcat报错追踪
- 判断两三角形是否相交
- asp.net连接access数据库的登录页面
- Struts学习总结之配置文件
- CodeForces 463C - Gargari and Bishops