作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如果我的TextField为空,则应禁用该按钮,并且该按钮的textColor和borderColor应该为灰色。但是,启用按钮后,颜色应为蓝色。
更改textColor很容易:
button.SetTitleColor(UIColor.Black, UIControlState.Normal);
button.SetTitleColor (UIColor.Gray, UIControlState.Disabled);
最佳答案
在您的ViewDidLoad ()
的ViewController
方法中:
MyButton.SetTitleColor(UIColor.Black, UIControlState.Normal);
MyButton.SetTitleColor (UIColor.Gray, UIControlState.Disabled);
MyButton.Layer.BorderWidth = 2;
MyButton.Layer.CornerRadius = 2;
UpdateButton();
MyEntryField.AllEditingEvents += (object sender, EventArgs e) => {
UpdateButton();
};
public void UpdateButton() {
if (MyEntryField.HasText) {
MyButton.Enabled = false;
MyButton.Layer.BorderColor = UIColor.Blue.CGColor;
} else {
MyButton.Enabled = true;
MyButton.Layer.BorderColor = UIColor.DarkGray.CGColor;
}
}
关于ios - 启用/禁用时从TextColor之类的按钮更改BorderColor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36664368/
我是一名优秀的程序员,十分优秀!