gpt4 book ai didi

ios - 如何在包含 View 的旋转变换期间保持文本水平

转载 作者:行者123 更新时间:2023-11-30 10:53:03 24 4
gpt4 key购买 nike

制作自定义 UI 控件(例如旋转轮),如下所示: enter image description here

正如您所看到的,标签定位在“半径上”,但我需要水平放置所有标签,并在旋转容器 View 时保持相同的方式

最佳答案

你可以这样做:

    let font = UIFont.systemFont(ofSize: 12)
let attributes = [
NSAttributedString.Key.font: UIConstants.CaptionFont,
NSAttributedString.Key.foregroundColor: UIColor.accent
]

for path in pathsForIndicators {
let cgPath = path.cgPath
let layer = CATextLayer()
layer.frame = CGRect(x: cgPath.boundingBox.midX + offset + 22,
y: cgPath.boundingBox.midX + 10, width: 40, height: 40)
layer.position = CGPoint(x: cgPath.boundingBox.midX + offset + 22,
y: cgPath.boundingBox.midY + 10)
layer.font = font
let value = 0 // TODO
let title = String(describing: value)
let attributedString = NSAttributedString(string: title, attributes: attributes)
layer.string = attributedString
layer.isWrapped = false
layer.alignmentMode = CATextLayerAlignmentMode.center
layer.foregroundColor = indicatorColor.cgColor
layer.shouldRasterize = true
layer.needsDisplayOnBoundsChange = false
layer.needsDisplay()
layer.displayIfNeeded()
textLayer.addSublayer(layer)
}
textLayer.backgroundColor = UIColor.clear.cgColor
textLayer.bounds = bounds
textLayer.position = centerPoint
layer.addSublayer(textLayer)

关于ios - 如何在包含 View 的旋转变换期间保持文本水平,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54260405/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com