如何渲染旋转的 UIlabel [英] How to Render a rotated UIlabel

查看:69
本文介绍了如何渲染旋转的 UIlabel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在为 iPad 开发一个像 photoshop 这样的应用程序,当我想要展平我的图层阵列时,DrawTextInRect 不会保留我的 UILabelCAAffineTransformMakeRotation)>.有人有什么想法吗?

I'm currently developing an app like photoshop for iPad and when i want flatten my array of layers, DrawTextInRect doesn't preserve the Transform (CAAffineTransformMakeRotation) of my UILabel. Anybody have any idea?

推荐答案

将上下文转换为标签的原点,然后将标签的转换应用于上下文.

Translate the context to the label's origin, and then apply the label's transform to the context.

下面的代码是用 Swift 编写的.

The code below is in Swift.

let context = UIGraphicsGetCurrentContext()!

context.saveGState()

let t = myLabel.transform
let translationPt = CGPoint.init(x: myLabel.frame.origin.x, y: myLabel.frame.origin.y)
context.translateBy(x: translationPt.x, y: translationPt.y)

context.concatenate(t)

myLabel.layer.render(in: context)

context.restoreGState()

这篇关于如何渲染旋转的 UIlabel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆