Using TVPosterImage in TVUIKit for tvOS 12

前端 未结 1 327
隐瞒了意图╮
隐瞒了意图╮ 2021-01-24 03:02

tvOS 12 has a new framework TVUIKit, which introduces the lockup views. The class I am interested in is TVPosterView, which is basically designed as such:

Swift

相关标签:
1条回答
  • 2021-01-24 03:55

    Eventually I managed to make it working programmatically. I tested both TVPosterView and TVMonogramView (basically a round button). The following code works with Xcode 10 beta 5, on tvOS 12 beta 5:

    Swift 4.2

    import UIKit
    import TVUIKit
    
    class SecondViewController: UIViewController {
    
        var myPoster = TVPosterView()
        var myMonogram = TVMonogramView()
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
            myPoster.frame = CGRect(x: 100, y: 100, width: 550, height: 625)
            myPoster.image = UIImage(named: "image1.png")
            myPoster.imageView.masksFocusEffectToContents = true
            myPoster.title = "Poster"
            myPoster.subtitle = "This is the poster subtitle"
    
            self.view.addSubview(myPoster)
    
            var myName = PersonNameComponents()
            myName.givenName = "Michele"
            myName.familyName = "Dall'Agata"
    
            myMonogram.frame = CGRect(x: 700, y: 100, width: 500, height: 475)
            myMonogram.image = UIImage(named: "image2.png")
            myMonogram.title = "Monogram"
            myMonogram.subtitle = "This is the Monogram subtitle"
            myMonogram.personNameComponents = myName
    
            self.view.addSubview(myMonogram)
    
            print(myMonogram.personNameComponents)
        }
    }
    

    I didn't manage to scale the poster's image with scaleAspectFit, though. Also my first image was rounded with a transparency, and only choosing a frame size that perfectly fit the squared image plus the titles (so no aspect fit needed), the glowing effect became transparent on the corners. Otherwise the whole image was opaque, using its own (quite small) rounded corners.

    0 讨论(0)
提交回复
热议问题