簡體   English   中英

添加了文本編輯器 / SwiftUi

[英]TextEditor added / SwiftUi

我無法調整我創建的文本編輯器的外觀。文本將有邊距。 我試着自己做,但我搞砸了,我做不到。我希望它像圖片一樣。

在此處輸入圖像描述

  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))

                })
            }

首先,為了更改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() 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM