Tint a UIView with all its subviews

前端 未结 2 2013
太阳男子
太阳男子 2020-12-29 14:31

Any way you can tint a UIView? Not the background color, but the entire UIView with all its subviews.

e.g - A UIView with an animation of a star rotating , i.e The

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-12-29 14:50

    To tint a UIView, add another subview on top of it with the same frame and an alpha transparency set.

    For example let's say your container type view is called containerView, you'd do as follows:

    CGRect overlayFrame = containerView.frame;
    UIView *overlayView = [UIView alloc] initWithFrame:overlayFrame];
    overlayView.alpha = 0.5f;
    overlayView.color = [UIColor blackColor];
    
    [containerView addSubview:overlayView];
    

    This gives you a semi transparent (0.5f) black tint that will give a tint like appearance to all the subviews underneath.

提交回复
热议问题