我创建了一个自定义视图,该视图接受背景色resid和阴影色resId。但是,当我转换资源ID以便将它们存储在int变量中时。它给出错误为
Expected a color resource id (R.color.) but received an RGB integer
以下是我的setter方法
@Override
public void setBackgroundColor(@ColorRes int backgroundResId) {
this.backgroundColor = ContextCompat.getColor(context, backgroundResId);
}
public void setShadowColor(@ColorRes int shadowColorId) {
this.shadowColor = ContextCompat.getColor(context, shadowColorId);
}
使用时显示相同的错误
public void setBackgroundColor(@ColorRes int backgroundResId) {
this.backgroundColor = context.getResources().getColor(backgroundResId);
}
答案 0 :(得分:0)
我想您在方法 fadeView.frame = view.frame
fadeView.center = view.center
fadeView.alpha = 0.0
fadeView.layer.zPosition = 1
fadeView.isOpaque = true
view.addSubview(fadeView)
UIView.animate(withDuration: 0.3, animations: {self.fadeView.alpha = 1.0})
中传递了错误的参数。您应该以这种方式使用它:
setBackgroundColor