Git Product home page Git Product logo

mfsubtractmask's Introduction

MFSubtractMask

一种实现 UIView 镂空效果的方案,可以快速实现任意形状的镂空、文字的镂空、带镂空的毛玻璃效果等。本质上是 UIViewmaskView 效果的「取反」。

下面是最终实现的效果:

可以很方便地生成毛玻璃的镂空效果:

如何导入

手动导入

将 MFSubtractMask 文件夹拖入工程中。

如何使用

1. 引入头文件

#import "UIView+MFSubtractMask.h"

2. 设置 subtractMaskView 属性

用法类似于 UIViewmaskView 属性,但是能获得完全相反的效果。

self.blackView.subtractMaskView = imageView;

局限性

1. subtractMaskView 不会自动刷新

我们知道,当 UIViewmaskView 的内容动态修改时,会实时反映到 UIView 中。但在本项目中, subtractMaskView 属性会生成一张全新的图片来作为遮罩图,因为不会根据 subtractMaskView 的内容实时来刷新视图。如果需要更新,必须手动调用 setSubtractMaskView: 方法来重新生成遮罩图。

2. setSubtractMaskView: 不宜被频繁调用

setSubtractMaskView: 本质上是生成一个新的遮罩图的过程,该过程涉及图片像素的遍历转换,较为耗时,不宜频繁调用。

本项目更适合只生成一次遮罩图的场景。

mfsubtractmask's People

Contributors

lmf12 avatar

Watchers

James Cloos avatar Persona avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.