Home>
I used UIViewRepresentable to wrap UITextView so that it can be used on Swift UI as shown below.
struct CustomTextView: UIViewRepresentable {
func makeUIView (context: UIViewRepresentableContext<CustomTextView>)->UITextView {
let textView = UITextView ()
textView.backgroundColor = UIColor.clear
textView.isScrollEnabled = false
textView.textColor = UIColor.black
textView.font = UIFont (name: "ArialMT", size: 20)
// textView.text = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
return textView
}
func updateUIView (_ uiView: UITextView, context: Context) {
}
}
extension UIApplication {
func closeKeyboard () {
sendAction (#selector (UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
}
}
The above is CustomTextView
I am using it as follows.
import SwiftUI
struct ContentView: View {
var body: some View {
ZStack {
CustomTextView ()
.frame (width: 300, height: 300, alignment: .topLeading)
.border (Color.red, width: 1)
} .onTapGesture {
UIApplication.shared.closeKeyboard ()
}
}
}
If i enter a value from the keyboard with this, it will wrap in a frame with a red frame as shown below.
However, if you uncomment the above CustomTextView and put the character string directly in textView.text, the frame will be out of the frame as shown below.
I want to make the line break at the frame even if I enter characters directly.
If i understand, I would appreciate it if you could answer.
-
Answer # 1
Related articles
- ios - about management and profitability of apps developed by receiving orders
- vba - about division using \
- python - about errors when using the camera module of raspberry pie
- ios - application implementation using realm and swift
- about object synchronization using unity photon rpc
- ios - about processing when data could not be obtained by api
- about replacement using regular expressions
- about the operation of excel using python
- ios - i get an error when trying to add ads using google admob in unity
- ios - about tap judgment of reality kit
- about symbolicate (restore) of crash log due to rejection when applying for swift iosapp
- about encryption at the time of output in php using form input tyle = "password"
- php - about the version when developing using the framework
- nodejs - about communication using express and socketio
- php - about passing value to form using tag
- about os version upgrade support in ios apps
- about cors support in web applications using vuejs
- html - [ruby on rails] about the problem that line breaks are not reflected in the text data acquired by innertext of mechanize
- ios - about farebase user registration
Related questions
- ios - swift5 video playback
- ios - i want to get only 0 from the array of 0s and 1s
- ios - [xcode] regarding the screen transition, it became a strange screen display
- ios - [xcode] the cause that the application under development does not start after a while after building it on the actual mach
- ios - i want to draw like swift when creating an array
- ios - transition screen in authentication with firebase
- whether or not a small screen like picture-in-picture can be realized on the screen of a self-made ios application
- ios - [swift] how to get all the values in the tableview cell and pass them to the transition destination
- ios - duplicate save is executed in coredata
- ios - core bluetooth data exchange
I was able to add the above