apple-text-measurement

Measure text dimensions with NSString and TextKit APIs for layout decisions.

Updated Mar 19, 2026
One-click install
npx skills add https://github.com/sitapix/apple-text --skill apple-text-measurement
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: apple-text-measurement
Source: https://github.com/sitapix/apple-text/tree/main/skills/apple-text-measurement
Command: npx skills add https://github.com/sitapix/apple-text --skill apple-text-measurement

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Text rendering and layout often require precise measurement to size views and ensure correct line-wrapping. This skill provides guidance and patterns for measuring text dimensions using NSString/NSAttributedString APIs and TextKit.

Core Features & Use Cases

  • Single-line and multi-line measurement patterns
  • Per-line metrics with TextKit 1 and TextKit 2
  • Guidance for proper options, rounding, and layout validations
  • Use cases include sizing UILabels, UITextView, and custom text views

Quick Start

Ask me to measure text size for a given font, width, and attributes to determine layout height.

Frequently Asked Questions about apple-text-measurement

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I measure NSAttributedString bounding rect for multi-line layout height?

To measure NSAttributedString dimensions, apply TextKit measurement APIs with proper options like .usesLineFragmentOrigin and .usesFontLeading, then apply ceil() rounding to the bounding rect for reliable multi-line layout height calculations.

Why does my text measurement return incorrect height for UILabel sizing?

Incorrect text measurement height often results from missing layout-before-measure validations or omitting .usesLineFragmentOrigin options, which are required for proper NSString and NSAttributedString sizing across TextKit 1 and TextKit 2.

What's the best way to get per-line text metrics using TextKit 2?

Per-line text metrics with TextKit 2 require using TextKit measurement APIs to evaluate each line fragment origin, applying font and paragraph style constraints within a specified container width to produce accurate per-line dimensions.

Does NSString sizing work for both single-line and multi-line text layout scenarios?

NSString sizing works for both single-line and multi-line text layout scenarios by applying appropriate measurement options and container width constraints, ensuring accurate dimensions for UILabels, UITextView, and custom text views.

When do I need to use ceil() rounding for attributed string measurement?

You need ceil() rounding for attributed string measurement when converting fractional text dimensions to integer pixel values for view layout, preventing visual clipping caused by floating-point truncation in bounding rect calculations.