我使用[myButton set
Image:forState:]为UIButton设置了一个UIImage;
我设置它的contentMode使用[[myButton imageView] setContentMode:UIViewContentModeScaleAspectFit];
但是当您点击按钮时,它将返回到UIViewContentModeScaleToFill并将我的图像拉出.
我设置它的contentMode使用[[myButton imageView] setContentMode:UIViewContentModeScaleAspectFit];
但是当您点击按钮时,它将返回到UIViewContentModeScaleToFill并将我的图像拉出.
使用adjustImageWhenHighlighted修复这个,但是然后我放宽了变暗的效果,我想保留.
有什么建议如何应付这个?
解决方法
UIButton *imageBtn = [UIButton ... imageBtn.adjustsImageWhenHighlighted = NO; [imageBtn addTarget:self action:@selector(doSomething:) forControlEvents:UIControlEventTouchUpInside]; [imageBtn addTarget:self action:@selector(doHighlighted:) forControlEvents:UIControlEventTouchDown]; [imageBtn addTarget:self action:@selector(doHighlighted:) forControlEvents:UIControlEventTouchDragEnter]; [imageBtn addTarget:self action:@selector(doCancelHighlighted:) forControlEvents:UIControlEventTouchDragExit]; -(void)doSomething:(UIButton *)button{ ... [self performSelector:@selector(doCancelHighlighted:) withObject:button afterDelay:0.2f]; } -(void)doHighlighted:(UIButton *)button{ UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(5,5,300,300)]; imageView.backgroundColor = [UIColor blackColor]; imageView.alpha = 0.7; imageView.tag = 1000; [button addSubview:imageView]; } -(void)doCancelHighlighted:(UIButton *)button{ UIView *view = [button subviewWithTag:1000]; [UIView animateWithDuration:0.2f animations:^{ view.alpha = 0; } completion:^(BOOL finished) { [view removeFromSuperview]; }]; }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。