如何使视图高亮显示 table 视图单元格
How to make view highlight like table view cell
我有一个包含很多子视图的视图。我希望在用户点击时突出显示所有视图。我知道我可以遍历子视图并突出显示它们。但这并不优雅。那么我实现这一目标的最佳方式是什么。有什么想法吗?
创建一个数组,其中包含应突出显示的所有视图。然后遍历数组以在需要时突出显示它们。
子视图的颜色是否与父视图的颜色不同?如果不是,那么宁愿让子视图背景透明,然后当你需要突出它时,只需突出显示父视图。
创建自定义 class UIView 并按照代码进行操作:
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
self.backgroundColor=[UIColor YourColor];
}
-(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
self.backgroundColor=[UIColor PreviousColor];
}
我有一个包含很多子视图的视图。我希望在用户点击时突出显示所有视图。我知道我可以遍历子视图并突出显示它们。但这并不优雅。那么我实现这一目标的最佳方式是什么。有什么想法吗?
创建一个数组,其中包含应突出显示的所有视图。然后遍历数组以在需要时突出显示它们。
子视图的颜色是否与父视图的颜色不同?如果不是,那么宁愿让子视图背景透明,然后当你需要突出它时,只需突出显示父视图。
创建自定义 class UIView 并按照代码进行操作:
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
self.backgroundColor=[UIColor YourColor];
}
-(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
self.backgroundColor=[UIColor PreviousColor];
}