2

私の TVML アプリでは、tv-text-style:none を使用して font-size や font-weight などのフォント スタイル プロパティを設定できますが、font-family プロパティを設定することはできず、無視されているようです。

var Template = function() { return `<?xml version="1.0"    encoding="UTF-8" ?>  
<document>  
    <head>  
        <style>  
            .customText {  
                tv-text-style: none;  
                tv-position: center;  
                color: white;  
                font-size: 40px;  
                font-weight: bold;  
                font-family: Courier;  
            }  
        </style>  
    </head>  
    <paradeTemplate>  
...  
                <listItemLockup>  
                    <title>Title</title>  
                    <relatedContent>  
                         <divTemplate>  
                             <title class="customText">abcABC</title>  
                         </divTemplate>  
                    </relatedContent>  
                </listItemLockup>  
...

システムフォントファミリーとは異なるフォントファミリーを設定できますか?

ご協力いただきありがとうございます、

ルカ

4

2 に答える 2

1

タイトルにカスタム フォントを使用する場合は、任意のフォントを使用するカスタムTVViewElementを実装する必要があります。まず、独自の を実装する必要があります。TVInterfaceFactoryそのように実行できます (tvOS 9 の Swift 2 ソリューション)。

import UIKit
import TVMLKit

class MyFactory: TVInterfaceFactory {

    override func viewForElement(element: TVViewElement, existingView: UIView?) -> UIView? {

        switch element {

        case let element as MyText where element.elementName == "myCustomText":
            let view = MyTextView(frame: CGRectMake(0,0,100,50))
            view.text = "my text"
            return view

        default:

            break
        }
        return nil
    }
}

その後、カスタム TVML アイテムを実装する必要があります。

class MyText: TVTextElement {

    override var elementName: String {

        return "myCustomText"
    }

    var text: String? {

        guard let textValue = attributes?["text"] else { return nil }
        return textValue
    }
}

次に、TVTextElement の UIView を実装する必要があります。

class MyTextView: UIView {

    var label: UILabel!

    override init(frame: CGRect) {

        super.init(frame: frame)
    }

    var text : String {
        get {

            return self.text
        }
        set(value) {

            self.label = UILabel(frame: self.frame)
            self.label.text = value
            self.label.textColor = UIColor.whiteColor()
            self.label.font = UIFont(name: "Your custom font", size: 20.0)
            self.addSubview(self.label)
        }
    }

    required init?(coder aDecoder: NSCoder) {

        fatalError("init(coder:) has not been implemented")
    }
}

これで、次のように TVML でカスタム アイテムを使用できます。

<myCustomText text="hello world"></myCustomText>

また、メソッドにカスタム項目を登録することを忘れないでくださいdidFinishLaunchingWithOptions:

TVInterfaceFactory.sharedInterfaceFactory().extendedInterfaceCreator = MyFactory()
TVElementFactory.registerViewElementClass(MyText.self, forElementName: "myCustomText")
于 2016-08-01T06:54:59.777 に答える