<tfoot id='cpgSH'></tfoot>

      <small id='cpgSH'></small><noframes id='cpgSH'>

      • <bdo id='cpgSH'></bdo><ul id='cpgSH'></ul>
    1. <i id='cpgSH'><tr id='cpgSH'><dt id='cpgSH'><q id='cpgSH'><span id='cpgSH'><b id='cpgSH'><form id='cpgSH'><ins id='cpgSH'></ins><ul id='cpgSH'></ul><sub id='cpgSH'></sub></form><legend id='cpgSH'></legend><bdo id='cpgSH'><pre id='cpgSH'><center id='cpgSH'></center></pre></bdo></b><th id='cpgSH'></th></span></q></dt></tr></i><div id='cpgSH'><tfoot id='cpgSH'></tfoot><dl id='cpgSH'><fieldset id='cpgSH'></fieldset></dl></div>

    2. <legend id='cpgSH'><style id='cpgSH'><dir id='cpgSH'><q id='cpgSH'></q></dir></style></legend>

      如何在 Swift 中旋转 UIButton 和 UILabel 的文本?

      How can you rotate text for UIButton and UILabel in Swift?(如何在 Swift 中旋转 UIButton 和 UILabel 的文本?)
      <i id='e4riO'><tr id='e4riO'><dt id='e4riO'><q id='e4riO'><span id='e4riO'><b id='e4riO'><form id='e4riO'><ins id='e4riO'></ins><ul id='e4riO'></ul><sub id='e4riO'></sub></form><legend id='e4riO'></legend><bdo id='e4riO'><pre id='e4riO'><center id='e4riO'></center></pre></bdo></b><th id='e4riO'></th></span></q></dt></tr></i><div id='e4riO'><tfoot id='e4riO'></tfoot><dl id='e4riO'><fieldset id='e4riO'></fieldset></dl></div>
        <bdo id='e4riO'></bdo><ul id='e4riO'></ul>

        <tfoot id='e4riO'></tfoot>
      • <small id='e4riO'></small><noframes id='e4riO'>

          <tbody id='e4riO'></tbody>

          <legend id='e4riO'><style id='e4riO'><dir id='e4riO'><q id='e4riO'></q></dir></style></legend>

              • 本文介绍了如何在 Swift 中旋转 UIButton 和 UILabel 的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                如何旋转 UIButtonUILabel 的文本?90度,180度.

                注意:在将其标记为重复之前,我有意将我的问题建模为该问题的 Swift 版本:

                的文档

                基本格式是 CGAffineTransform(rotationAngle: CGFloat) 其中 rotationAngle 是弧度,而不是度数.

                一个完整的圆(360 度)有 2π 弧度.Swift 包含有用的常量 CGFloat.pi.

                • CGFloat.pi = π = 180 度
                • CGFloat.pi/2 = π/2 = 90 度

                自动布局:

                自动布局不适用于旋转视图.(有关原因,请参阅 Frame vs Bounds.)这个问题可以通过创建自定义视图来解决.This answer 展示了如何为 UITextView 执行此操作,但对于标签或按钮.(请注意,您必须删除该答案中的 CGAffineTransformScale 行,因为您不需要镜像文本.)

                相关

                • 如何在 CALayer 上进行转换?
                • 如何在 Swift 中应用多个转换
                • iOS 中的 CTM 变换与仿射变换(用于平移、旋转、缩放)

                How can you rotate text for UIButton and UILabel? 90 degrees, 180 degrees.

                Note: Before you mark this as a duplicate, I am intentionally modelling my question as a Swift version of this one: How can you rotate text for UIButton and UILabel in Objective-C?

                解决方案

                I am putting my answer in a similar format to this answer.

                Here is the original label:

                Rotate 90 degrees clockwise:

                yourLabelName.transform = CGAffineTransform(rotationAngle: CGFloat.pi / 2)
                

                Rotate 180 degrees:

                yourLabelName.transform = CGAffineTransform(rotationAngle: CGFloat.pi)
                

                Rotate 90 degrees counterclockwise:

                yourLabelName.transform = CGAffineTransform(rotationAngle: -CGFloat.pi / 2)
                

                Do the same thing to rotate a button. Thankfully the touch events also get rotated so the button is still clickable in its new bounds without having to do anything extra.

                yourButtonName.transform = CGAffineTransform(rotationAngle: CGFloat.pi / 2)
                

                Notes:

                Documentation for CGAffineTransform

                The basic format is CGAffineTransform(rotationAngle: CGFloat) where rotationAngle is in radians, not degrees.

                There are 2π radians in a full circle (360 degrees). Swift includes the useful constant CGFloat.pi.

                • CGFloat.pi = π = 180 degrees
                • CGFloat.pi / 2 = π/2 = 90 degrees

                Auto Layout:

                Auto layout does not work with rotated views. (See Frame vs Bounds for an explanation why.) This problem can be solved by creating a custom view. This answer shows how to do it for a UITextView, but it is the same basic concept for a label or button. (Note that you will have to remove the CGAffineTransformScale line in that answer since you don't need to mirror the text.)

                Related

                • How to do transforms on a CALayer?
                • How to apply multiple transforms in Swift
                • CTM transforms vs Affine Transforms in iOS (for translate, rotate, scale)

                这篇关于如何在 Swift 中旋转 UIButton 和 UILabel 的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                iOS 6 rotations: supportedInterfaceOrientations doesn#180;t work?(iOS 6 旋转:supportedInterfaceOrientations 不起作用?)
                CABasicAnimation rotate returns to original position(CABasicAnimation 旋转返回原始位置)
                UITabBarController Rotation Issues in ios 6(ios 6 中的 UITabBarController 旋转问题)
                iOS: How to run a function after Device has Rotated (Swift)(iOS:设备旋转后如何运行函数(Swift))
                How to rotate an image 90 degrees on iOS?(如何在 iOS 上将图像旋转 90 度?)
                iOS 8 Rotation Methods Deprecation - Backwards Compatibility(iOS 8 旋转方法弃用 - 向后兼容性)

                <small id='kS2yF'></small><noframes id='kS2yF'>

                  <tbody id='kS2yF'></tbody>

                • <tfoot id='kS2yF'></tfoot>

                    <i id='kS2yF'><tr id='kS2yF'><dt id='kS2yF'><q id='kS2yF'><span id='kS2yF'><b id='kS2yF'><form id='kS2yF'><ins id='kS2yF'></ins><ul id='kS2yF'></ul><sub id='kS2yF'></sub></form><legend id='kS2yF'></legend><bdo id='kS2yF'><pre id='kS2yF'><center id='kS2yF'></center></pre></bdo></b><th id='kS2yF'></th></span></q></dt></tr></i><div id='kS2yF'><tfoot id='kS2yF'></tfoot><dl id='kS2yF'><fieldset id='kS2yF'></fieldset></dl></div>
                          <bdo id='kS2yF'></bdo><ul id='kS2yF'></ul>
                          <legend id='kS2yF'><style id='kS2yF'><dir id='kS2yF'><q id='kS2yF'></q></dir></style></legend>