How Do I Take a Screen Shot of a UIView?

后端 未结 15 2578
-上瘾入骨i
-上瘾入骨i 2020-11-22 09:28

I am wondering how my iPhone app can take a screen shot of a specific UIView as a UIImage.

I tried this code but all I get is a blank image

15条回答
  •  盖世英雄少女心
    2020-11-22 09:40

    iOS7 onwards, we have below default methods :

    - (UIView *)snapshotViewAfterScreenUpdates:(BOOL)afterUpdates
    

    Calling above method is faster than trying to render the contents of the current view into a bitmap image yourself.

    If you want to apply a graphical effect, such as blur, to a snapshot, use the drawViewHierarchyInRect:afterScreenUpdates: method instead.

    https://developer.apple.com/library/ios/documentation/uikit/reference/uiview_class/uiview/uiview.html

提交回复
热议问题