gpt4 book ai didi

ios - 启用/禁用时从TextColor之类的按钮更改BorderColor

转载 作者:行者123 更新时间:2023-12-01 20:16:31 26 4
gpt4 key购买 nike

如果我的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;
}
}

禁用:

enter image description here

已启用:

enter image description here

关于ios - 启用/禁用时从TextColor之类的按钮更改BorderColor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36664368/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com