Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 是否要旋转选框标签?_Ios_Swift - Fatal编程技术网

Ios 是否要旋转选框标签?

Ios 是否要旋转选框标签?,ios,swift,Ios,Swift,嘿,我用可可豆在我的项目中实现了选框标签,但没有成功地让它旋转 let newsFeed: MarqueeLabel = MarqueeLabel( frame: CGRect(x:15, y:66, width:28, height:159)) newsFeed.textAlignment = .right newsFeed.text = "TEXT" self.view.addSubview(newsFeed) newsFeed.transform = CG

嘿,我用可可豆在我的项目中实现了选框标签,但没有成功地让它旋转

let newsFeed: MarqueeLabel = MarqueeLabel(
    frame: CGRect(x:15, y:66, width:28, height:159)) 
newsFeed.textAlignment = .right newsFeed.text = "TEXT" 
self.view.addSubview(newsFeed) 
newsFeed.transform = CGAffineTransform(
    rotationAngle: CGFloat(-(Double.pi / 2.0))) 
newsFeed.frame = CGRect(x:15, y:66, width:28, height:159)
你应该:

  • 将字段的高度和宽度设置为未旋转的高度和宽度 创建时的宽度:
  • 更改视图的位置后,不要尝试操纵帧 使改变相反,您应该设置视图的中心:引用苹果的 UIView.transform上的文档:
当此属性的值不是 标识转换时,帧属性中的值未定义且 应该被忽略

我不知道什么是
MarqueeLabel
,但这段代码使用的是普通的
UILabel

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        let startingFrameRect = CGRect(x:15, y:66, width:159, height:28)
        let newsFeed = UILabel(
            //Create the label wide and short as if it is not rotated.
            frame: startingFrameRect)
        newsFeed.text = "Some Text"
        self.view.addSubview(newsFeed)
        newsFeed.transform = CGAffineTransform(
            rotationAngle: CGFloat(-(Double.pi / 2.0)))
        //Add a border so you can see the label's rotated frame
        newsFeed.layer.borderWidth = 1.0
        //Adjust the view's center based on it's origin, but exchanging height and width
        newsFeed.center = CGPoint (x: startingFrameRect.origin.x + startingFrameRect.size.height / 2,
                                   y: startingFrameRect.origin.y + startingFrameRect.size.width / 2)
        
        //Also add a view to show where the unrotated view would land.
        let boxView = UIView(frame: startingFrameRect)
        boxView.layer.borderWidth = 1.0
        boxView.layer.borderColor = UIColor.blue.cgColor
        self.view.addSubview(boxView)
    }
}
你能回答你的问题而不是发表评论吗?