UIButton在滚动时丢失cornerRadius(当设置其他属性时)

时间:2017-04-22 17:44:26

标签: swift uibutton uikit

我有一个UIButton需要在用户滚动时更改背景颜色和文本,具体取决于它们在UIScrollView中的位置。

当他们达到阈值时,我会调用以下函数:

public void gaNaarNext(View view){
    setContentView(R.layout.activity_main2);

    // For example: If your activity_main2 contains radio_button then do this
    RadioButton radioButton = (RadioButton) findViewById(R.id.radio_button);

    radioButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            // Do something
        }
    });
}

我已尝试同时设置fileprivate func setFinalizeButton(format: FinalizeButtonFormat) { switch format { case ._continue: let grey = UIColor(red: 189, green: 189, blue: 189) finalizeButton?.setTitle("Continue", for: .normal) finalizeButton?.setBackgroundColor(color: grey, forState: .normal) finalizeButton?.setBackgroundColor(color: grey.darkerColor(percent: 0.2), forState: .highlighted) case .buyNow: finalizeButton?.setTitle("Buy Now", for: .normal) finalizeButton?.setBackgroundColor(color: .black, forState: .normal) finalizeButton?.setBackgroundColor(color: .black, forState: .highlighted) } } finalizeButton?.cornerRadius,但都无法正常工作。两次cornerRadius都回到0.(对于cornerRadius,该按钮初始化为值为5)

知道为什么会这样或如何解决它?

谢谢!

编辑:按钮设置

finalizeButton?.layer.cornerRadius

1 个答案:

答案 0 :(得分:1)

您是否尝试过设置按钮的地方?: finalizeButton.clipsToBounds = true 如果有效,请告诉我。