Post

Replies

Boosts

Views

Activity

Reply to `focusable()` broken for views that are not already focusable
Your code modified to use a TextField instead of a Text view. import SwiftUI struct ContentView: View {     @FocusState private var focusedItem: Optional<FocusedItem>     @State var inputname: String = ""          var body: some View {         VStack {                          TextField("Test", text: $inputname)             #if os(macOS)                 .focusable(true)             #endif                 .focused($focusedItem, equals: .two)             Button("Toggle Focus") {                 self.focusedItem=(self.focusedItem == nil) ? .two : nil             }.onChange(of: focusedItem) { newValue in                 // Always prints `nil`.                 print(newValue as Any)             }         }     }          enum FocusedItem: Equatable {         case one, two         func other() -> FocusedItem {             switch self {             case .one: return .two             case .two: return .one             }         }     } } struct ContentView_Previews: PreviewProvider {     static var previews: some View {         ContentView()     } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’23
Reply to [__NSCFType set]: unrecognized selector with NSAttributedString:draw() gets called, based on width of position
The foregroundColor in attributes doesn't take a cgColor context.cgContext.setFillColor(UIColor.black.cgColor) not needed use UIColor.black.setFill() instead. Final changes let imageSize = CGSize(width: 400, height: 100) let testRenderer = UIGraphicsImageRenderer(size: imageSize) let testImage = testRenderer.image { context in     UIColor.black.setFill()     context.fill(CGRect(origin: .zero, size: imageSize))     let paragraphStyle = NSMutableParagraphStyle()     paragraphStyle.alignment = .left     let attributes: [NSAttributedString.Key: Any] = [         .font: UIFont.systemFont(ofSize: 8.0),         .paragraphStyle: paragraphStyle,         .foregroundColor: UIColor.white]     var attributedString = NSAttributedString(string: "This is some text",                                               attributes: attributes)     let drawContext = NSStringDrawingContext()     drawContext.minimumScaleFactor = 0.5     attributedString.draw(with: testRenderer.format.bounds, options: .usesLineFragmentOrigin,                           context: drawContext) } -enjoy!
Topic: App & System Services SubTopic: Core OS Tags:
Jan ’23