适配图片
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];