【问题标题】:TextEditor added / SwiftUi添加了文本编辑器 / SwiftUi
【发布时间】:2020-12-27 04:15:50
【问题描述】:

我无法调整我创建的文本编辑器的外观。文本会有边距。 我试着自己做,但我搞砸了,我做不到。我希望它像图片一样。

  VStack {
            TextEditor(text: $inputText)
                .background(Color.black)
                .frame(height:geometry.size.height / 3, alignment: .center)
                .cornerRadius(25)
                .border(Color.yellow, width: 5)
                .lineSpacing(10)
                .autocapitalization(.words)
                .disableAutocorrection(true)
                .padding()  
            }

            Spacer().frame(height: geometry.size.height / 15)

            VStack {
                Button(action: {}, label: {
                    Text("Gönder")
                        .frame(width: geometry.size.width / 3, height: 50)
                        .padding(10)
                        .font(Font.system(size: 30, weight: .medium, design: .serif))
                        .foregroundColor(.white)
                        .background(RoundedRectangle(cornerRadius: 30))
                        .foregroundColor(.init(red: 45 / 255, green: 0 / 255, blue: 112 / 255))

                })
            }

【问题讨论】:

  • 到底是什么问题?你能解释一下你想要什么吗?
  • 我正在尝试和图片中的一样,但是文本编辑器无法设置圆角半径和边框颜色
  • 我无法调整文本和编辑器@Quail Bellal 之间的间距

标签: ios swift swiftui


【解决方案1】:

首先,用于更改 TextEditor 背景颜色 我找不到SwiftUI 100% 的解决方案(也许苹果将来会支持这个),所以你需要在应用程序中更改每个UITextView.appearance().backgroundColor

init() {
    UITextView.appearance().backgroundColor = UIColor.black
}

不要错过import UIKit

那么对于圆角半径,你需要使用overlay修饰符来修饰圆角

VStack {
   TextEditor(text: $inputText)
     .frame(height:geometry.size.height / 3, alignment: .center)
     .lineSpacing(10)
     .autocapitalization(.words)
     .disableAutocorrection(true)
     .padding()
                        
}.overlay(
         RoundedRectangle(cornerRadius: 25)
           .stroke(Color.yellow, lineWidth: 5)
         )
.padding() 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-15
    • 2023-02-22
    • 1970-01-01
    • 2013-02-26
    相关资源
    最近更新 更多