This is a skeleton iOS application that displays DICOM medical images using the cornerstone.js web framework embedded in a WKWebView using Swift, SwiftUI, Cornerstone.js JavaScript.
As an observation - a simple example illustrating integration of Cornerstone.js into iOS application with Swift was not available when I was looking for one on the project website, so here is one. It is clear in last years, Cornerstone.js has evolved and improved over time and a reasonable ingredient for a mobile application vertical. I am well versed in bringing up image viewers including on iOS (Swift, Objective-C, C++) but have tracked Cornerstone.js over time.
NOTE: The name lapis angularis is in effect, a variation on the Latin translation for "cornerstone". This is a combination of lapis (stone) and angularis term to convey the corner/angle characteristic, so "stone corner".
The user interface under construction is illustrated below.
| DICOM Viewer |
|---|
![]() |
- Tap Load DICOM to open the file picker
- Select a
.dcmfile from Files, iCloud, or connected sources - The image will render with default window/level
| Gesture | Action |
|---|---|
| Single-finger drag | Adjust window/level |
| Two-finger pinch | Zoom in/out |
| Two-finger drag | Pan image |
- WW/WL Sliders: Fine-tune window width and window level
- Reset: Return to default viewport
- Application and View System
ContentView
> DicomViewModel
>> CornerstoneWebView (UIViewRepresentable + WKWebView + Coordinator)
NOTE: JavaScript Bridge between CornerstoneWebView and WKWebView
>>> Web Layer (WKWebView)
┌─────────────────────────────────────────────────────┐
│ cornerstone.html │
│ • cornerstone-core (rendering) │
│ • cornerstone-tools (pan/zoom/window-level) │
│ • cornerstone-wado-image-loader (DICOM parsing) │
│ • dicom-parser (tag extraction) │
└─────────────────────────────────────────────────────┘
<root source code directory>/
├── DicomViewerApp.swift # App entry point
├── ContentView.swift # Main UI with file picker & controls
├── DicomViewModel.swift # State management & WebView bridge
├── CornerstoneWebView.swift # WKWebView wrapper for SwiftUI
├── CornerstoneHTML.swift # Inline HTML/JS (fallback)
├── Info.plist # App configuration & permissions
└── Resources/
└── cornerstone.html # Bundled HTML file (preferred)
Resourcesfolder contains the actual HTML web pages- As needed, add more pages as additional web page transitions needed based on Cornerstone.js usage.
- NOTE: For new files added, verify the file(s) appear in Build Phases → Copy Bundle Resources
These are the key Info.plist entries in the Info.plist.
Key configurations:
NSAppTransportSecurity- allows CDN script loadingUTImportedTypeDeclarations- DICOM file type supportUISupportsDocumentBrowser- Files app integration
The app requires network access to load cornerstone.js from CDN on first launch.
For offline support, download cornerstone.js libraries and bundle them:
// In cornerstone.html, replace CDN URLs with local paths:
<script src="cornerstone.min.js"></script>
<script src="cornerstoneTools.min.js"></script>
// etc.In cornerstone.html, add additional cornerstone-tools:
const LengthTool = cornerstoneTools.LengthTool;
cornerstoneTools.addTool(LengthTool);
cornerstoneTools.setToolActive('Length', { mouseButtonMask: 1 });The viewer already parses basic tags. Add more in updateOverlays():
const seriesDesc = getDicomTagValue(dataSet, 'x0008103e'); // Series Description
const sliceThickness = getDicomTagValue(dataSet, 'x00180050');For multi-frame DICOM or series navigation, you'll need to:
- Parse the NumberOfFrames tag (x00280008)
- Create multiple imageIds
- Add navigation controls in Swift
- Call
cornerstone.displayImage()with different frames
All loaded via CDN (unpkg.com):
- cornerstone-core@2.6.1
- cornerstone-tools@6.0.10
- cornerstone-wado-image-loader@4.13.2
- cornerstone-math@0.1.10
- dicom-parser@1.8.21
- hammerjs@2.0.8
- Single-frame images only (skeleton doesn't include series navigation)
- Requires network for CDN scripts (unless bundled)
- No DICOM networking (C-FIND, C-MOVE, DICOMweb)
- Basic toolset (extend cornerstone-tools as needed)
- Does not contain advanced features (3D MPR, volume rendering). That would require migration to Cornerstone3D:
// Cornerstone3D uses a different API
import { RenderingEngine, Enums } from '@cornerstonejs/core';The source code is published under the MIT License as per below. See also the top level LICENSE text file.
NOTE: Cornerstone.js is also MIT licensed.
MIT License
Copyright (c) 2025-2026 John Matthew Weston
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
