iOS九宫格布局按钮样式/不规则布局按钮样式/类似淘宝星星布局按钮样式

/**
 *  添加九宫格按钮
 */
-(void)setupBtnWithBtnArr:(NSMutableArray *)arr {
    
    //
    int totalloc =3;
    CGFloat btnVW = (mDeviceWidth-20*4)/3;
    CGFloat btnVH = 30;
    CGFloat margin =15;
    int count =(int)arr.count;
    for (int i=0;i


 
  

iOS九宫格布局按钮样式/不规则布局按钮样式/类似淘宝星星布局按钮样式_第1张图片

//布局不规则的按钮样式
-(void)addTypeBtnView{
    
    UIView *btnView =[[UIView alloc]init];
    btnView.frame =CGRectMake(0, 110, mDeviceWidth, 60);
    
    btnView.backgroundColor=[UIColor whiteColor];
    
    [self.view  addSubview:btnView];
    
    NSArray *arr =[[NSArray alloc]initWithObjects:@"精选住宿",@"大气舒适",@"配套齐全",@"美味",@"漂亮",@"干净",@"哈哈哈哈哈",@"精选住",@"舒适",@"配套齐全齐全",nil];
    
    CGFloat width =30;
    CGFloat j=0;
    CGFloat row =1;
    
    for (int i =0;imDeviceWidth-60) {
            
            j=0;
            width=30;
            row++;
            btn.frame = CGRectMake(10*j+width, row * 35,btnWidth, 30);
            width =width+btnWidth;
            j++;
            DLog(@"row:%f",row);
        }
        typeBtnHight =(row+2)*35;
        DLog(@"row33333:%f",row);
        btnView.frame =CGRectMake(0, 110, mDeviceWidth,typeBtnHight);
    }
}
//点击多选按钮事件
-(void)btnClicke:(UIButton *)sender{
    
    UIButton *btn =[self.view viewWithTag:sender.tag];
    if(btn.selected==YES){
        btn.selected=NO;
        btn.layer.borderColor=borderCol.CGColor;
    } else {
        btn.selected=YES;
        btn.layer.borderColor=fontHightRedColor.CGColor;
    }
    
}
//判断按钮title长度
+(float)longFloatWithstring:(NSString *)aString
                  andHeight:(float)aHeigt
                    andSize:(float)aSize
{
    CGSize textSiz = [aString sizeWithFont:[UIFont fontWithName:uFont size:aSize]
                         constrainedToSize:CGSizeMake(MAXFLOAT, aHeigt)];
    float textHeight = textSiz.width;
    return textHeight;
}

 

 
  iOS九宫格布局按钮样式/不规则布局按钮样式/类似淘宝星星布局按钮样式_第2张图片 
  

//类似淘宝评论的星星按钮布局
-(void)addStarBtnView{
    
    for (int i =0;i<5;i++){
        //
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake((mDeviceWidth-200)/2+i*40+5, 80, 30, 30);
        
        [btn setBackgroundImage:[UIImage imageNamed:@"star_nomal"] forState:UIControlStateNormal];
        [btn setBackgroundImage:[UIImage imageNamed:@"star_helight"] forState:UIControlStateSelected];
        [btn  addTarget:self action:@selector(starClick:) forControlEvents:UIControlEventTouchUpInside];
        btn.tag=i+1000;
        [self.view addSubview: btn];
    }
    
}
-(void)starClick:(UIButton *)sender{
    
    for(int i=0;i<5 ;i++){
        UIButton *btn =[self.view viewWithTag:i+1000];
        
        if(btn.tag <=sender.tag){
            btn.selected=YES;
        }else{
            btn.selected=NO;
        }
    }
    
}

iOS九宫格布局按钮样式/不规则布局按钮样式/类似淘宝星星布局按钮样式_第3张图片


你可能感兴趣的:(iOS九宫格布局按钮样式/不规则布局按钮样式/类似淘宝星星布局按钮样式)