赞
踩
设置按钮的边框
- 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];
设置按钮的文字内容
- [self.titleBtn setTitle:title forState:UIControlStateNormal];
- [self.titleBtn setTitle:title forState:UIControlStateSelected];
附上按钮的各种状态及交互
- 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状态,继续保持当前状态

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。