1.去掉高亮状态(selected状态和normal状态切换时候出现)
button.adjustsImageWhenHighlighted = NO;
2.禁止触摸事件的2种方式
//会改变按钮的状态,颜色会变灰
button.enabled = NO;
//保持按钮原来的状态,颜色不会变
button.userInteractionEnabled = NO;
3.KVO来监控button的大小
//注册KVO方法
[btn addObserver:self forKeyPath:@"bounds" options:NSKeyValueObservingOptionNew |NSKeyValueObservingOptionInitial context:nil];
//KVO回调
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
if (object == btn && [keyPath isEqualToString:@"bounds"]){
[btn setTitle:NSStringFromCGSize(btn.bounds.size) forState:UIControlStateNormal];
}
}
网友评论