Created
January 15, 2024 12:34
-
-
Save mariosaputra/2bc84e312a34c62e3ba20f34ea2ee78c to your computer and use it in GitHub Desktop.
Ruby Annotations in SwiftUI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// HomeView.swift | |
// SwiftlyBase | |
// | |
// Created by Mario Saputra on 2024/01/09. | |
// | |
import SwiftUI | |
import SwiftUIKitView | |
import RubyAttribute | |
struct HomeView: View { | |
var body: some View { | |
UIViewContainer(createCustomLabel(), layout: .intrinsic) | |
} | |
func createCustomLabel() -> UILabel { | |
let label = UILabel() | |
label.attributedText = try! NSAttributedString(AttributedString(localized: | |
""" | |
^[猫](CTRubyAnnotation: {before: 'ねこ'})は^[窓辺](CTRubyAnnotation: {before: 'まどべ'})で^[日向](CTRubyAnnotation: {before: 'ひなた'})ぼっこしています。 | |
AAA | |
""", including: \.coreText), including: \.coreText) | |
label.textAlignment = .center | |
label.font = .preferredFont(forTextStyle: .title2) | |
label.frame = CGRect(x: 0, y: 0, width: 400, height: 100) // Set a frame for the label | |
return label | |
} | |
} | |
#Preview { | |
HomeView() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment