swiftui alert type 'CGFloat' has no member 'main'

Asked 1 years ago, Updated 1 years ago, 420 views

In swiftui

TextEditor(text:$text)
.frame (width:.main.bounds.width*0.8, height:200)

If so,

Type 'CGFloat' has no member 'main'

The alert appears.

Before that, I had UISscreen.

I also got an alert with UIKit.

Is .main not supported?

swift swiftui

2022-11-11 06:56

1 Answers

The frame(width:?) contains CGFloat, so . can start CGFloat init, static, etc., but in this case CGFloat does not have main, so . cannot start.

.frame (width: UISscreen.main.bounds.width*0.8, height:200)
.frame (width:.zero)

You can force yourself to do it, but it doesn't make sense.

struct ContentView:View {
  @State var text: String="Hello"
  
  varbody:someView {
    TextEditor (text:$text)
      .frame (width:.main.bounds.width*0.8, height:200)
  }
}

extension CGFloat {
  static let main —UISscreen=.main
}


2022-11-11 06:59

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.