点击时如何更改UIView的样式? [英] How to change the style of an UIView when it's tapped?
本文介绍了点击时如何更改UIView的样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用以下代码制作了不同的UIView的Tappable(它们不是从UIControl继承的):
I'm making different UIView's tappable (they're not inheriting from UIControl) using the following code:
UITapGestureRecognizer* gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(userTappedOnLink:)];
[labelView setUserInteractionEnabled:YES];
[labelView addGestureRecognizer:gesture];
但是我也想在突出显示它们时更改样式.我该怎么办?
but I'd also like to change the style when they're highlighted. How do I do that?
推荐答案
我设法通过在UIView中添加UIControl作为子视图来解决此问题.具有相同大小的UIControl的透明背景会在突出显示时发生变化.就像魅力一样!
I managed to solve this by adding an UIControl as a subview in the UIView. The UIControl is the same size has a transparent background that changes when it's highlighted. Works like a charm!
这篇关于点击时如何更改UIView的样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文