---------------------------------------------------------UIButton------------------------------------------------------------
1:设置UIButton高亮选中时 模拟改变UIButton 的背景颜色.
思路: 将UIColor转换为UIImage 以后 设置到 高亮时的背景图片
2:设置UIButton 的字体阴影
[[rightButton titleLabel] setShadowColor:[UIColor blackColor]]; [[rightButton titleLabel] setShadowOffset:CGSizeMake(-0.5, -0.5)];
3:UIButton 点击事件触发后同时保持高亮选中的方式:原理:延迟设置 参考: 保持UIButton高亮状态
- (void)Help_setHighlighted:(BOOL)highlighted { [self performSelector:@selector(highlightButton:) withObject:self afterDelay:0.0]; } - (void)highlightButton:(UIButton *)b { [b setHighlighted:YES]; }
4:设置UIButton在点按住时附带高亮效果.
btn.showsTouchWhenHighlighted = YES;
注:如果设置看不到效果,请将背景设置为其他颜色即可.
5:调整Button内部内容的边距(Padding)
[self.userNameButton setContentEdgeInsets:UIEdgeInsetsMake(0, 3, 0, 0)];
6:如何实现UIButton 实现点击以后 保持高亮状态的效果.
首先需要设置:
[button setImage:[UIImage imageNamed:menu.onIconName] forState:UIControlStateSelected];
然后
[self.menuButtons enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { if (obj == aButton) { [obj setSelected:YES]; }else { [obj setSelected:NO]; } }];
---------------------------------------------------------UIButton------------------------------------------------------------
---------------------------------------------------------UIControl------------------------------------------------------------
1:如果自定义类继承了UIControl 那么 完成了一个点击事件时触发如下方法:(来自父类)
//完成一个点击事件时触发的方法,来自继承类UIControl - (void)endTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event { [ShareCode Msg:@"点击了"]; }
---------------------------------------------------------UIControl------------------------------------------------------------