Latest 0.1.0
License MIT
Platforms ios 7.0

CI Status
Carthage compatible

Why layer based masking ?

Using YJLayerBasedMasking to get circular or rounded corner image is simple, light-weight, without extra cost for blended layer and offscreen-rendering.

Here is a demo using a JPEG format image without alpha channel. To display it as circular or rounded corner effect, we can set layer’s properties directly or using YJLayerBasedMasking.

Get same results by setting layer.masksToBounds (middle row) or using YJLayerBasedMasking (last row)


Color blended layers testing (Green color means good, red color means layer-blending cost)

blended layer

Color offscreen-rendering testing (Yellow color means offscreen-rendering cost)


How to use it ?

To display a circular UIImageView instance, just call this.

// circular imageView
[imageView yj_addCircularShapeLayerWithColor:backgroundColor];
// circular imageView with border
[imageView yj_addCircularShapeLayerWithColor:backgroundColor borderWidth:borderWidth borderColor:borderColor];

To display a rounded corner UIImageView instance, just call this.

// rounded corner imageView
[imageView yj_addRoundedCornerShapeLayerWithColor:backgroundColor cornerRadius:cornerRadius];
// rounded corner imageView with border
[imageView yj_addRoundedCornerShapeLayerWithColor:backgroundColor cornerRadius:cornerRadius borderWidth:borderWidth borderColor:borderColor];


  1. This is not good for display rounded corner with transparency background.
  2. This is not good for any view with its size changing constantly.
  3. This is not good for any view with superview’s background color changing constantly. (e.g. When user tap on UITableViewCell, it’s background color becomes gray. To make the YJLayerBasedMasking working, either you can set cell’s property to UITableViewCellSelectionStyleNone or change shape layer’s color to match the new background color)

If you need to display a circular image effect with a good performance (e.g. display user’s avatar image), then try YJLayerBasedMasking.


iOS 7+


YJLayerBasedMasking is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "YJLayerBasedMasking"

For iOS 8+, it also support Carthage. To install, add the following line to your Cartfile:

github "huang-kun/YJLayerBasedMasking"


huang-kun, [email protected]


YJLayerBasedMasking is available under the MIT license. See the LICENSE file for more info.

Latest podspec

    "name": "YJLayerBasedMasking",
    "version": "0.1.0",
    "summary": "A light-weight and high-performance approach to get circular or rounded corner UIImageView.",
    "description": "Getting circular or rounded corner image to display on UIImageView is easy by using YJLayerBasedMasking.",
    "homepage": "",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "authors": {
        "huang-kun": "[email protected]"
    "source": {
        "git": "",
        "tag": "0.1.0"
    "platforms": {
        "ios": "7.0"
    "source_files": "YJLayerBasedMasking/Classes/**/*"

Pin It on Pinterest

Share This