设置按钮的边框
self.titleBtn.backgroundColor = UIColor.whiteColor;
self.titleBtn.layer.borderColor = [UIColor colorWithHexString:@"#B3B3B3" withAlpha:0.3].CGColor;
self.titleBtn.layer.borderWidth = 0.5;
self.titleBtn.clipsToBounds = YES;
self.titleBtn.height = 48;
self.titleBtn.size = CGSizeMake(CLSCREENWIDTH, 48);
设置按钮的文字样式
self.titleBtn.tintColor = UIColor.clearColor;
[self.titleBtn setTitleColor:[UIColor colorWithHexString:@"#2C2C2C"] forState:UIControlStateNormal];
[self.titleBtn setTitleColor:[UIColor colorWithHexString:@"#7809FF"] forState:UIControlStateSelected];
设置按钮的背景颜色
UIImage *selectImage = [UIImage imageWithColor:[UIColor colorWithHexString:@"#F5F5FF"] andSize:self.titleBtn.size];
[self.titleBtn setBackgroundImage:selectImage forState:UIControlStateSelected];
[self.titleBtn setTitleColor:UIColor.whiteColor forState:UIControlStateDisabled];
UIImage *disableImage = [UIImage imageWithColor:[UIColor colorWithHexString:@"#B3B3B3"] andSize:self.titleBtn.size];
[self.titleBtn setBackgroundImage:disableImage forState:UIControlStateDisabled];
设置按钮的文字内容文章来源:https://www.toymoban.com/news/detail-859774.html
[self.titleBtn setTitle:title forState:UIControlStateNormal];
[self.titleBtn setTitle:title forState:UIControlStateSelected];
附上按钮的各种状态及交互文章来源地址https://www.toymoban.com/news/detail-859774.html
1.UIControlStateNormal
1> 除开UIControlStateHighlighted、UIControlStateDisabled、UIControlStateSelected以外的其他情况,都是normal状态
2> 这种状态下的按钮【可以】接收点击事件
2.UIControlStateHighlighted
1> 【当按住按钮不松开】或者【highlighted = YES】时就能达到这种状态
2> 这种状态下的按钮【可以】接收点击事件
3.UIControlStateDisabled
1> 【button.enabled = NO】时就能达到这种状态
2> 这种状态下的按钮【无法】接收点击事件
4.UIControlStateSelected
1> 【button.selected = YES】时就能达到这种状态
2> 这种状态下的按钮【可以】接收点击事件
二、让按钮无法点击的2种方法
1> button.enabled = NO;
*【会】进入UIControlStateDisabled状态
2> button.userInteractionEnabled = NO;
*【不会】进入UIControlStateDisabled状态,继续保持当前状态
到了这里,关于IOS 设置UIButton按钮的选中状态样式的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!