iOS 快速解决~倒计时button闪烁的问题

//联系人:石虎 QQ:1224614774 昵称:嗡嘛呢叭咪哄

              QQ群:807236138  群称:iOS 技术交流学习群


一、概念


UIButton 样式 :ButtonWithType:

    UIButtonTypeCustom:       自定义风格

    UIButtonTypeRoundedRect : 圆角矩形

    UIButtonTypeDetailDisclosure:蓝色小箭头,主要做详细说明用

    UIButtonTypeInfoLight:    亮色感叹号

    UIButtonTypeInfoDark:     暗色感叹号

    UIButtonTypeContactAdd:   十字加号按钮




二、解决倒计时button title闪烁问题


button title闪烁GIF图:




方式一:

    1.只要把button的类型改成custom即可。

    2.代码:

        UIButton *countBtn = [UIButton buttonWithType:UIButtonTypeCustom];

    3.xib:

                     


    4.原因:因为默认的button类型是system的自定义有些属性会导致问题。



方式二:

    1.如果不修改类型那就先设button.titleLabel.text,再设button setTitle: forState: 就可以解决倒计时闪烁问题


    2.代码:

    _countBtn.titleLabel.text = [NSString stringWithFormat:@"%zd 跳过",_count];

    [_countBtn setTitle:[NSString stringWithFormat:@"%zd 跳过",_count] forState:UIControlStateNormal];



button title正常GIF图:




注意:推荐使用方式二,如果是老项目可以考虑使用方式一



谢谢!!!


猜你喜欢

转载自blog.csdn.net/shihuboke/article/details/80786021