Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Threema/Threema/Utilities/   (Social Medium ©)  Datei vom 26.9.2026 mit Größe 1 kB image not shown  

Quelle  UILabel+Truncation.swift   Sprache: JAVA

 

import UIKit

extension UILabel {
    /// Returns true if the label's text would exceed `maxLines` lines at the given width.
    /// Safe to call before layout — does not depend on the label's frame.
    func exceeds(lines maxLines: Int, availableWidth: CGFloat) -> Bool {
        guard let text, let font else {
            return false
        }
        
        let measured = (text as NSString).boundingRect(
            with: CGSize(width: availableWidth, height: .greatestFiniteMagnitude),
            options: .usesLineFragmentOrigin,
            attributes: [.font: font],
            context: nil
        )
        
        // Convert back to a line count and round to the nearest integer.
        // boundingRect can accumulate per-line pixel-snapping errors (up to
        // 1/scale pt per line) that push the raw height fractionally above
        // maxLines × lineHeight and produce a false positive. Rounding absorbs
        // that noise without masking genuine overflow — a real extra line adds a
        // full lineHeight, so it always rounds up correctly.
        let measuredLines = (measured.height / font.lineHeight).rounded(.toNearestOrAwayFromZero)
        return Int(measuredLines) > maxLines
    }
}

Messung
CHZG
869310092

¤ Dauer der Verarbeitung: 0.0 Sekunden  (vorverarbeitet am  2026-11-04) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover


Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.