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

Asked 2 years ago, Updated 2 years ago, 438 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.