# Mac development series: NSImageView

Language: en
Canonical: [Mac development series: NSImageView](<https://allluckly.cn/en/journal/2015-11-23-mac-development-series-nsimageview/>)
中文：[中文 HTML](<https://allluckly.cn/mac/Mac-OS01>)
English: [English HTML](<https://allluckly.cn/en/journal/2015-11-23-mac-development-series-nsimageview/>)
Published: 2015-11-23T00:00:00+08:00
Modified: 2026-10-23T10:34:10+08:00
Author: [Bison](<https://allluckly.cn/about/>)

Demonstrates creating an NSImageView, assigning an image and adding it to a macOS interface. Enabling its backing layer and configuring corner radius and border then produces a circular avatar style.

Originally credited to Bison. Content is retained as published.

English translation of the [Chinese original](<https://allluckly.cn/mac/Mac-OS01>), translated on 2026-10-23. The article body uses automated translation; app descriptions, historical reading notes and video subtitles receive separate editorial checks. Original publication dates, attribution, code and version notes are retained.

**Before you read** This technical note dates from 2015–2017. The examples have not been rerun as part of this archive update. Read API, dependency and tool details in the context of the original publication date.

> "iOS technical sharing, iOS development, iOS development tips, iOS development blog" Bison

I have recently been exploring some Mac development techniques. Follow along if you are interested! I hope to get to grips with Mac development in my spare time.

```css
//初始化NSImageView并设置它的大小
NSImageView *imgView = [[NSImageView alloc]initWithFrame:CGRectMake(self.view.frame.size.width/2-35, 100, 70, 70)];
//给图片赋值和iOS开发是一样的
imgView.image = [NSImage imageNamed:@"1"];

[self.view addSubview:imgView];

//设置圆角
imgView.wantsLayer = YES;
imgView.layer.cornerRadius = 35.0f;
imgView.layer.borderWidth = 2;
imgView.layer.borderColor = [NSColor greenColor].CGColor;
imgView.layer.masksToBounds = YES;
```

The final result is shown below.

![2](<https://allluckly.cn/images/NSimgView.png>)

> [An ongoing series—stay tuned.](<https://allluckly.cn/en/>)

Recommended reading: [An illustrated guide to implementing iOS in-app purchases](<http://www.jianshu.com/p/05a3087cd796>)

Original article: https://allluckly.cn/

Copyright © Bison. Please retain a hyperlink to the original article when reproducing it.

