如何让文本适合圆形/图像 SwiftUI 的边界

问题描述

我似乎无法理解如何确保我的文本覆盖并适合圆形图像的边界。这是我目前所拥有的。

const jwt = "abc123";
const expiresIn = 60 * 60 * 24 * 5 * 1000;
const options = { secure: true,sameSite: 'none',httpOnly: true,maxAge: expiresIn };
res.cookie('jwt',jwt,options );

Text overlayed on top of circle

SwiftUI 有没有办法让它工作?我将如何实现这一目标?

解决方法

struct ClippedCircleView: View {
    @State var text: String = "Reaaaallllllyyyyyy Looooooongggggg"
    // Make this any number you are comfortable with
    @State var letterLimit: Int = 12
    var body: some View {
        
        Circle()
            .frame(width: 100,height: 100)
            .overlay(
                Text(text)
                    //Limit to 1 line until your letterLimit
                    .lineLimit(text.count <= letterLimit ? 1 : nil)
                    //Clips it to shape
                    .clipShape(ContainerRelativeShape()).padding()
                    .foregroundColor(Color.red)
                    //This makes super tiny letters so adjust to your use case
                    .minimumScaleFactor(0.1)
                
            )
    }
}

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...