How do I make a semi-transparent view layer above a current view?

后端 未结 5 383
一生所求
一生所求 2021-02-01 19:28

You\'ve likely seen this before, its become exceedingly popular in consumery chic apps like ScoutMob. I\'m trying to implement a 60% transparent view on launch that will cover m

5条回答
  •  星月不相逢
    2021-02-01 20:20

    1. create UIView, name it what you want (dimBackgroundUIView) then set the backgroundcolor as Black and set alpha to 0.1 or 0.2 or....
    2. add these 2 lines of code when you need to dim the background: [self.view addSubview:dimBackgroundUIView]; [self addConstraintsForDimView];
    3. and add these 2 lines of code when you want to remove the dimming background: if(dimBackgroundUIView) [dimBackgroundUIView removeFromSuperview];
    4. do not forgot to add the constraints(layouts) for dimBackgroundUIView.

    check this: iOS Dim background when a view is shown

    and do not forget to read the note below the code to understand what you have to do.

提交回复
热议问题