Files
divkit/client/ios/Core/BaseUI/BackgroundAttribute.swift
T
morevsavva 3ed0abbc30 add background for text ranges
Добавил возможность задавать фоны в ренджах.
2022-11-21 13:54:44 +03:00

24 lines
541 B
Swift

// Copyright 2021 Yandex LLC. All rights reserved.
import CoreGraphics
import Foundation
public final class BackgroundAttribute {
public static let Key = NSAttributedString.Key("RangeBackground")
public let color: CGColor
public let range: CFRange
public init(
color: CGColor,
range: CFRange
) {
self.color = color
self.range = range
}
public func apply(to str: CFMutableAttributedString, at range: CFRange) {
CFAttributedStringSetAttribute(str, range, BackgroundAttribute.Key as CFString, self)
}
}