iOS 禁用按钮高亮状态下的阴影效果

 _collectionBtn.adjustsImageWhenHighlighted = NO;

  • 高亮状态下有有阴影
iOS 禁用按钮高亮状态下的阴影效果_第1张图片
101.175513.gif
  • 加上_collectionBtn.adjustsImageWhenHighlighted = NO;这句代码,高亮状态下阴影消失
    iOS 禁用按钮高亮状态下的阴影效果_第2张图片
    101.175511.gif
  • 完整代码
-(UIButton *)collectionBtn{
    if(!_collectionBtn){
        // 默认状态下的图片不要设置在封装的ZBFunction里面,有些问题。
        _collectionBtn = [ZBFunction btnInit:23 title:@"" bgColor:[UIColor clearColor] titleColor:[UIColor clearColor] imageNamed:nil Font:nil];
        [_collectionBtn setImage:[UIImage imageNamed:@"dtqd_ic_collect"] forState:UIControlStateNormal];
        [_collectionBtn setImage:[UIImage imageNamed:@"dtqd_ic_collected"] forState:UIControlStateSelected];
        _collectionBtn.frame = CGRectMake(APP_SCREEN_WIDTH - autoScaleW(12) - autoScaleW(44), self.bottomV.zb_Y - autoScaleH(8) - autoScaleH(44), autoScaleW(44), autoScaleH(44));
        _collectionBtn.adjustsImageWhenHighlighted = NO;
        [_collectionBtn addTarget:self action:@selector(collectionBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _collectionBtn;
}

-(void)collectionBtnClick:(UIButton *)btn{
    btn.selected = !btn.selected;
    NSLog(@"点击了收藏");
   
    
}

-(void)createRightCollection{
    [self.view addSubview:self.collectionBtn];
}

你可能感兴趣的:(iOS 禁用按钮高亮状态下的阴影效果)