当前位置:   article > 正文

IOS 设置UIButton按钮的选中状态样式

IOS 设置UIButton按钮的选中状态样式

设置按钮的边框

  1. self.titleBtn.backgroundColor = UIColor.whiteColor;
  2. self.titleBtn.layer.borderColor = [UIColor colorWithHexString:@"#B3B3B3" withAlpha:0.3].CGColor;
  3. self.titleBtn.layer.borderWidth = 0.5;
  4. self.titleBtn.clipsToBounds = YES;
  5. self.titleBtn.height = 48;
  6. self.titleBtn.size = CGSizeMake(CLSCREENWIDTH, 48);

设置按钮的文字样式

  1. self.titleBtn.tintColor = UIColor.clearColor;
  2. [self.titleBtn setTitleColor:[UIColor colorWithHexString:@"#2C2C2C"] forState:UIControlStateNormal];
  3. [self.titleBtn setTitleColor:[UIColor colorWithHexString:@"#7809FF"] forState:UIControlStateSelected];

设置按钮的背景颜色

  1. UIImage *selectImage = [UIImage imageWithColor:[UIColor colorWithHexString:@"#F5F5FF"] andSize:self.titleBtn.size];
  2. [self.titleBtn setBackgroundImage:selectImage forState:UIControlStateSelected];
  3. [self.titleBtn setTitleColor:UIColor.whiteColor forState:UIControlStateDisabled];
  4. UIImage *disableImage = [UIImage imageWithColor:[UIColor colorWithHexString:@"#B3B3B3"] andSize:self.titleBtn.size];
  5. [self.titleBtn setBackgroundImage:disableImage forState:UIControlStateDisabled];

设置按钮的文字内容

  1. [self.titleBtn setTitle:title forState:UIControlStateNormal];
  2. [self.titleBtn setTitle:title forState:UIControlStateSelected];

附上按钮的各种状态及交互

  1. 1.UIControlStateNormal
  2. 1> 除开UIControlStateHighlightedUIControlStateDisabledUIControlStateSelected以外的其他情况,都是normal状态
  3. 2> 这种状态下的按钮【可以】接收点击事件
  4. 2.UIControlStateHighlighted
  5. 1> 【当按住按钮不松开】或者【highlighted = YES】时就能达到这种状态
  6. 2> 这种状态下的按钮【可以】接收点击事件
  7. 3.UIControlStateDisabled
  8. 1> 【button.enabled = NO】时就能达到这种状态
  9. 2> 这种状态下的按钮【无法】接收点击事件
  10. 4.UIControlStateSelected
  11. 1> 【button.selected = YES】时就能达到这种状态
  12. 2> 这种状态下的按钮【可以】接收点击事件
  13. 二、让按钮无法点击的2种方法
  14. 1> button.enabled = NO;
  15. *【会】进入UIControlStateDisabled状态
  16. 2> button.userInteractionEnabled = NO;
  17. *【不会】进入UIControlStateDisabled状态,继续保持当前状态

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/478208
推荐阅读
相关标签
  

闽ICP备14008679号