c_cpp 方形按钮与背景动画触摸向下和向上(突出显示)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp 方形按钮与背景动画触摸向下和向上(突出显示)相关的知识,希望对你有一定的参考价值。
#import "ARLSquareButton.h"
IB_DESIGNABLE
@interface ARLSquareButton()
@property (nonatomic, strong) UIColor *normalBackgroundColor;
@end
@implementation ARLSquareButton
- (instancetype)initWithCoder:(NSCoder *)coder
{
self = [super initWithCoder:coder];
[self setup];
return self;
}
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
[self setup];
return self;
}
- (void)setup
{
self.highlightedBackgroundColor = [UIColor lightGrayColor];
[self addTarget:self action:@selector(processTouchDown:) forControlEvents:UIControlEventTouchDown];
[self addTarget:self action:@selector(processTouchDown:) forControlEvents:UIControlEventTouchDragEnter];
[self addTarget:self action:@selector(processTouchUp:) forControlEvents:UIControlEventTouchUpInside];
[self addTarget:self action:@selector(processTouchUp:) forControlEvents:UIControlEventTouchDragExit];
}
- (void)setCornerRadius:(CGFloat)cornerRadius
{
self.layer.cornerRadius = cornerRadius;
}
- (CGFloat)cornerRadius
{
return self.layer.cornerRadius;
}
- (void)setBackgroundColor:(UIColor *)backgroundColor
{
[super setBackgroundColor:backgroundColor];
self.normalBackgroundColor = backgroundColor;
}
- (UIColor *)backgroundColor
{
return self.normalBackgroundColor;
}
- (void)processTouchDown:(id)sender
{
[super setBackgroundColor:self.highlightedBackgroundColor];
}
- (void)processTouchUp:(id)sender
{
super.backgroundColor = [self normalBackgroundColor];
}
@end
#import <UIKit/UIKit.h>
@interface ARLSquareButton : UIButton
@property (nonatomic, strong) IBInspectable UIColor *highlightedBackgroundColor;
@property (nonatomic, assign) IBInspectable CGFloat cornerRadius;
@end
以上是关于c_cpp 方形按钮与背景动画触摸向下和向上(突出显示)的主要内容,如果未能解决你的问题,请参考以下文章
在iPhone中禁用UIButton中的触摸动画
向上滚动和向下滚动时导航按钮的颜色变化
按钮背景颜色动画禁用触摸(IOS)
如何在自定义 UIButton 中实现 .isHighlighted 动画?
UIImageView 的向上和向下触摸动作
WPF - 使用标准按钮创建带有向上和向下箭头的按钮