关于btn
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了关于btn相关的知识,希望对你有一定的参考价值。
适配图片
UIImage *buttonImage = [UIImage imageNamed:@"go_work_green"];
UIImage *stretchableButtonImage = [buttonImage stretchableImageWithLeftCapWidth:0 topCapHeight:0];
[goBtn setBackgroundImage:stretchableButtonImage forState:UIControlStateNormal];
圆角
goBtn.layer.cornerRadius = kScreenW/6;
点击缩放
[self.ordersBtn addTarget:self action:@selector(unpressedEvent:) forControlEvents:UIControlEventTouchUpInside | UIControlEventTouchUpOutside];
[self.ordersBtn addTarget:self action:@selector(pressedEvent:) forControlEvents:UIControlEventTouchDown];
[self.ordersBtn addTarget:self action:@selector(cancelEvent:) forControlEvents:UIControlEventTouchUpOutside];
//按钮的压下事件 按钮缩小
- (void)pressedEvent:(UIButton *)btn{
//缩放比例必须大于0,且小于等于1
CGFloat scale = (_buttonScale && _buttonScale <=1.0) ? _buttonScale : defaultScale;
[UIView animateWithDuration:animateDelay animations:^{
btn.transform = CGAffineTransformMakeScale(scale, scale);
}];
}
//点击手势拖出按钮frame区域松开,响应取消
- (void)cancelEvent:(UIButton *)btn{
[UIView animateWithDuration:animateDelay animations:^{
btn.transform = CGAffineTransformMakeScale(1.0, 1.0);
} completion:^(BOOL finished) {
}];
}
//按钮的松开事件 按钮复原 执行响应
- (void)unpressedEvent:(UIButton *)btn{
[UIView animateWithDuration:animateDelay animations:^{
btn.transform = CGAffineTransformMakeScale(1.0, 1.0);
} completion:^(BOOL finished) {
NSLog(@">>>>>>Abcdef");
}];
}
字体大小
btnOpenAppURL.titleLabel.font = [UIFont systemFontOfSize: 12];
以上是关于关于btn的主要内容,如果未能解决你的问题,请参考以下文章