Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/102.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何将一个UIView设置为另一个UIView的掩码_Ios_Swift_Uiview_Swift4_Cagradientlayer - Fatal编程技术网

Ios 如何将一个UIView设置为另一个UIView的掩码

Ios 如何将一个UIView设置为另一个UIView的掩码,ios,swift,uiview,swift4,cagradientlayer,Ios,Swift,Uiview,Swift4,Cagradientlayer,我有 gradientView这只是一个渐变视图 带有anImageView和aUILabel的视图容器视图 现在当我试着 gradientView.mask = containerView 它不显示任何内容UIImageView和UILabel都有固有的内容大小,但没有UIView。视图的遮罩必须正确设置边框。确保设置了containerView.frame: containerView.frame = gradientView.bounds 另外,请确保将containerView.ba

我有

  • gradientView这只是一个渐变视图
  • 带有anImageView和aUILabel的视图容器视图
  • 现在当我试着

    gradientView.mask = containerView
    

    它不显示任何内容
    UIImageView
    UILabel
    都有固有的内容大小,但没有
    UIView
    。视图的遮罩必须正确设置边框。确保设置了
    containerView.frame

    containerView.frame = gradientView.bounds
    

    另外,请确保将
    containerView.backgroundColor
    设置为
    UIColor.clear

    我只想添加视图背景颜色应为的其他内容clearColor@AsadullahAli那么它不起作用了?或者,视图的背景色应该是clearColor是什么意思?这是正确的一半。我必须添加containerView.backgroundColor=UIColor。clear@AsadullahAli哦,好的,我会更新答案。。我希望
    containerView
    的背景色是clearColor,因为这是
    UIView
    的默认背景色,当我们从故事板添加它时,默认颜色是白色,这会浪费我数小时的时间,所以最好让其他人知道。