Post

Replies

Boosts

Views

Activity

Reply to Wind Compass swift UI
Something like this? This is what I wrote and use in my own app, so if you use it, please make it look a little different... or I'll sue 😉 import SwiftUI struct ContentView: View { var body: some View { let windDegrees = 255.0 let frameSize = 240.0 ZStack { LinearGradient(gradient: Gradient(colors: [Color.init(red: 91.0/255.0, green: 100.0/255.0, blue: 157.0/255.0), Color.init(red: 125.0/255.0, green: 108.0/255.0, blue: 142.0/255.0)]), startPoint: .top, endPoint: .bottom) ZStack { Circle() .opacity(0.1) Image("compassMarker") .resizable() .scaledToFit() .frame(width: 10, height: 100) .rotationEffect(Angle(degrees: windDegrees - 180)) .shadow(color: .black.opacity(0.6), radius: 1, x: 1, y: 1) Circle() .fill(.black.opacity(0.15)) .frame(width: frameSize/2, height: frameSize/2) VStack { Text(convertWindDirectionToCompassPoint(windDegrees)) .font(.system(size: 18, weight: .bold)) .foregroundStyle(.white) .shadow(color: .black.opacity(0.6), radius: 1, x: 1, y: 1) Text("\(String(format: "%.0f", windDegrees))º") .font(.system(size: 12)) .foregroundStyle(.white) .lineLimit(1) .minimumScaleFactor(0.6) .shadow(color: .black.opacity(0.6), radius: 1, x: 1, y: 1) } ForEach(CompassMarker.markers(), id: \.self) { marker in CompassMarkerView(marker: marker, compassDegress: 0) } } .frame(width: frameSize, height: frameSize) } .ignoresSafeArea() } struct CompassMarker: Hashable { let degrees: Double let label: String init(degrees: Double, label: String = "") { self.degrees = degrees self.label = label } static func markers() -> [CompassMarker] { return [ CompassMarker(degrees: 0, label: "N"), CompassMarker(degrees: 30), CompassMarker(degrees: 60), CompassMarker(degrees: 90, label: "E"), CompassMarker(degrees: 120), CompassMarker(degrees: 150), CompassMarker(degrees: 180, label: "S"), CompassMarker(degrees: 210), CompassMarker(degrees: 240), CompassMarker(degrees: 270, label: "W"), CompassMarker(degrees: 300), CompassMarker(degrees: 330) ] } func degreeText() -> String { return String(format: "%.0f", self.degrees) } } struct CompassMarkerView: View { let marker: CompassMarker let compassDegress: Double var body: some View { VStack { Capsule() .frame(width: 2, height: self.capsuleHeight()) .foregroundStyle(Color.white) .opacity(0.6) .padding(.bottom, self.capsulePadding()) Text(marker.label) .font(.system(size: 16, weight: .bold)) .foregroundStyle(Color.white) .opacity(0.6) .rotationEffect(self.textAngle()) Spacer(minLength: 97) } .rotationEffect(Angle(degrees: marker.degrees)) } private func capsuleHeight() -> CGFloat { return (marker.label != "" ? 8 : 12) } private func capsulePadding() -> CGFloat { return (marker.label != "" ? -12 : -6) } private func textAngle() -> Angle { return Angle(degrees: -self.compassDegress - self.marker.degrees) } } func convertWindDirectionToCompassPoint(_ degrees: Double) -> String { var degrees_: Double = fmod(degrees, 360.0) var point: String = "" if(degrees_ > 360) { degrees_ = degrees_.truncatingRemainder(dividingBy: 360) } if((degrees_ >= 0.0 && degrees_ <= 11.25) || (degrees_ > 348.75 && degrees_ <= 360.0)) { point = "N" } if(degrees_ > 11.25 && degrees_ <= 33.75) { point = "NNE" } if(degrees_ > 33.75 && degrees_ <= 56.25) { point = "NE" } if(degrees_ > 56.25 && degrees_ <= 78.75) { point = "ENE" } if(degrees_ > 78.75 && degrees_ <= 101.25) { point = "E" } if(degrees_ > 101.25 && degrees_ <= 123.75) { point = "ESE" } if(degrees_ > 123.75 && degrees_ <= 146.25) { point = "SE" } if(degrees_ > 146.25 && degrees_ <= 168.75) { point = "SSE" } if(degrees_ > 168.75 && degrees_ <= 191.25) { point = "S" } if(degrees_ > 191.25 && degrees_ <= 213.75) { point = "SSW" } if(degrees_ > 213.75 && degrees_ <= 236.25) { point = "SW" } if(degrees_ > 236.25 && degrees_ <= 258.75) { point = "WSW" } if(degrees_ > 258.75 && degrees_ <= 281.25) { point = "W" } if(degrees_ > 281.25 && degrees_ <= 303.75) { point = "WNW" } if(degrees_ > 303.75 && degrees_ <= 326.25) { point = "NW" } if(degrees_ > 326.25 && degrees_ <= 348.75) { point = "NNW" } return point } } #Preview { ContentView() } Pass in your windDegrees (line 5) as a Double. Oh, and here's an image for the compassMarker arrow: The size of the compass is constrained by the frameSize so if you change it you'll need to alter the arrow image. You also don't need to show the degrees and 'WSW' text (for example), and can easily put your own text in the VStack.
Topic: Design SubTopic: General Tags:
Oct ’24
Reply to Equal width buttons in VStack
SwiftUI draws the button as wide as it needs to be for the title. It's up to you to tell it how wide the button should be. I do this by creating and applying a new ButtonStyle, like this: import SwiftUI struct ContentView: View { var body: some View { VStack(alignment: .center) { Button("Short", action: {}) .buttonStyle(MyButtonStyle(bgColor: .gray, fgColor: .white)) Button("Long title", action: {}) .buttonStyle(MyButtonStyle(bgColor: .yellow, fgColor: .black)) Button("A longer button title", action: {}) .buttonStyle(MyButtonStyle(bgColor: .green, fgColor: .white)) Button("A much, much, much longer button title", action: {}) .buttonStyle(MyButtonStyle(bgColor: .blue, fgColor: .white)) } } } struct MyButtonStyle: ButtonStyle { var bgColor: Color? var fgColor: Color? func makeBody(configuration: Configuration) -> some View { configuration.label .font(.headline) .bold() .allowsTightening(true) .lineLimit(2) .frame(width: 200, height: 60) .background(bgColor ?? .gray) .foregroundStyle(fgColor ?? .white) .clipShape(RoundedRectangle(cornerRadius: 16)) } } #Preview { ContentView() } That example gives you this: Note that you can change the number of lines in the button by changing .lineLimit().
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’24
Reply to IOS18 “updates”
now I just have to have the same lock screen and home screen background? No. Just customise the Lock Screen as usual, and when you see the two screens (the Lock Screen and Home Screen with darkened squares for the app icons), tap the Home Screen one, and at the bottom tap "Photo". I have my phone in darkmode so now I just have to deal with the ugly black thumbnails for the app? I can’t revert them to normal colors while keeping dark mode? Yes, I think you can. Customise the Home Screen by holding a finger down in a space on the screen, then in the top left tap "Edit" then "Customize". In the panel that appears at the bottom of the screen choose "Light", then press the little sun icon in the top left of that panel. That will change the background to dark, but leave the icons light. Does that work for you? By the way, these are the Developer Forums where third party developers of apps for Apple;s operating systems talk about code and ask for help on how to write some code. This isn't the place for product support questions. For that, go to the Apple Support Forums. Thanks.
Topic: Design SubTopic: General Tags:
Oct ’24
Reply to LGBTIQ
You can either pay someone to do it - but, please don't solicit for it here; or you can learn to write it yourself. There are lots of Swift and SwiftUI tutorials, and the Apple Developer pages have sample code that will help you along.
Topic: Community SubTopic: Apple Developers Tags:
Oct ’24
Reply to Wind Compass swift UI
Something like this? This is what I wrote and use in my own app, so if you use it, please make it look a little different... or I'll sue 😉 import SwiftUI struct ContentView: View { var body: some View { let windDegrees = 255.0 let frameSize = 240.0 ZStack { LinearGradient(gradient: Gradient(colors: [Color.init(red: 91.0/255.0, green: 100.0/255.0, blue: 157.0/255.0), Color.init(red: 125.0/255.0, green: 108.0/255.0, blue: 142.0/255.0)]), startPoint: .top, endPoint: .bottom) ZStack { Circle() .opacity(0.1) Image("compassMarker") .resizable() .scaledToFit() .frame(width: 10, height: 100) .rotationEffect(Angle(degrees: windDegrees - 180)) .shadow(color: .black.opacity(0.6), radius: 1, x: 1, y: 1) Circle() .fill(.black.opacity(0.15)) .frame(width: frameSize/2, height: frameSize/2) VStack { Text(convertWindDirectionToCompassPoint(windDegrees)) .font(.system(size: 18, weight: .bold)) .foregroundStyle(.white) .shadow(color: .black.opacity(0.6), radius: 1, x: 1, y: 1) Text("\(String(format: "%.0f", windDegrees))º") .font(.system(size: 12)) .foregroundStyle(.white) .lineLimit(1) .minimumScaleFactor(0.6) .shadow(color: .black.opacity(0.6), radius: 1, x: 1, y: 1) } ForEach(CompassMarker.markers(), id: \.self) { marker in CompassMarkerView(marker: marker, compassDegress: 0) } } .frame(width: frameSize, height: frameSize) } .ignoresSafeArea() } struct CompassMarker: Hashable { let degrees: Double let label: String init(degrees: Double, label: String = "") { self.degrees = degrees self.label = label } static func markers() -> [CompassMarker] { return [ CompassMarker(degrees: 0, label: "N"), CompassMarker(degrees: 30), CompassMarker(degrees: 60), CompassMarker(degrees: 90, label: "E"), CompassMarker(degrees: 120), CompassMarker(degrees: 150), CompassMarker(degrees: 180, label: "S"), CompassMarker(degrees: 210), CompassMarker(degrees: 240), CompassMarker(degrees: 270, label: "W"), CompassMarker(degrees: 300), CompassMarker(degrees: 330) ] } func degreeText() -> String { return String(format: "%.0f", self.degrees) } } struct CompassMarkerView: View { let marker: CompassMarker let compassDegress: Double var body: some View { VStack { Capsule() .frame(width: 2, height: self.capsuleHeight()) .foregroundStyle(Color.white) .opacity(0.6) .padding(.bottom, self.capsulePadding()) Text(marker.label) .font(.system(size: 16, weight: .bold)) .foregroundStyle(Color.white) .opacity(0.6) .rotationEffect(self.textAngle()) Spacer(minLength: 97) } .rotationEffect(Angle(degrees: marker.degrees)) } private func capsuleHeight() -> CGFloat { return (marker.label != "" ? 8 : 12) } private func capsulePadding() -> CGFloat { return (marker.label != "" ? -12 : -6) } private func textAngle() -> Angle { return Angle(degrees: -self.compassDegress - self.marker.degrees) } } func convertWindDirectionToCompassPoint(_ degrees: Double) -> String { var degrees_: Double = fmod(degrees, 360.0) var point: String = "" if(degrees_ > 360) { degrees_ = degrees_.truncatingRemainder(dividingBy: 360) } if((degrees_ >= 0.0 && degrees_ <= 11.25) || (degrees_ > 348.75 && degrees_ <= 360.0)) { point = "N" } if(degrees_ > 11.25 && degrees_ <= 33.75) { point = "NNE" } if(degrees_ > 33.75 && degrees_ <= 56.25) { point = "NE" } if(degrees_ > 56.25 && degrees_ <= 78.75) { point = "ENE" } if(degrees_ > 78.75 && degrees_ <= 101.25) { point = "E" } if(degrees_ > 101.25 && degrees_ <= 123.75) { point = "ESE" } if(degrees_ > 123.75 && degrees_ <= 146.25) { point = "SE" } if(degrees_ > 146.25 && degrees_ <= 168.75) { point = "SSE" } if(degrees_ > 168.75 && degrees_ <= 191.25) { point = "S" } if(degrees_ > 191.25 && degrees_ <= 213.75) { point = "SSW" } if(degrees_ > 213.75 && degrees_ <= 236.25) { point = "SW" } if(degrees_ > 236.25 && degrees_ <= 258.75) { point = "WSW" } if(degrees_ > 258.75 && degrees_ <= 281.25) { point = "W" } if(degrees_ > 281.25 && degrees_ <= 303.75) { point = "WNW" } if(degrees_ > 303.75 && degrees_ <= 326.25) { point = "NW" } if(degrees_ > 326.25 && degrees_ <= 348.75) { point = "NNW" } return point } } #Preview { ContentView() } Pass in your windDegrees (line 5) as a Double. Oh, and here's an image for the compassMarker arrow: The size of the compass is constrained by the frameSize so if you change it you'll need to alter the arrow image. You also don't need to show the degrees and 'WSW' text (for example), and can easily put your own text in the VStack.
Topic: Design SubTopic: General Tags:
Replies
Boosts
Views
Activity
Oct ’24
Reply to I can’t understand this SwiftUI compile error.
I've had this a few times, but the message says the compiler is unable to type-check it in a reasonable time, which AFAIK - is why you can't see where the error is: it took too long to figure it out.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Oct ’24
Reply to Apple Time Machine Sequoia 15.0.1
These are the Developer Forums, where developers of apps for Apple's platforms ask each other for hints and tips on coding. Your question is more of a product support one, so I'd suggest you ask it over at the Apple Support Forums. Thanks.
Topic: Community SubTopic: Apple Developers Tags:
Replies
Boosts
Views
Activity
Oct ’24
Reply to Conditionally compile newer API with older XCode
Hang on, maybe I misunderstood this. Can you use something like the respondsToSelector? I have no idea if it's there in Swift 5/6, but this SO page gives an example of how to use it: https://stackoverflow.com/questions/24167791/what-is-the-swift-equivalent-of-respondstoselector
Replies
Boosts
Views
Activity
Oct ’24
Reply to Critical Bug in iOS 18.1 RC and watchOS 11.1 RC - WidgetKit Complications Not Syncing
Raise this in the usual way, as a Feedback report, then post the FB number here.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Oct ’24
Reply to Equal width buttons in VStack
SwiftUI draws the button as wide as it needs to be for the title. It's up to you to tell it how wide the button should be. I do this by creating and applying a new ButtonStyle, like this: import SwiftUI struct ContentView: View { var body: some View { VStack(alignment: .center) { Button("Short", action: {}) .buttonStyle(MyButtonStyle(bgColor: .gray, fgColor: .white)) Button("Long title", action: {}) .buttonStyle(MyButtonStyle(bgColor: .yellow, fgColor: .black)) Button("A longer button title", action: {}) .buttonStyle(MyButtonStyle(bgColor: .green, fgColor: .white)) Button("A much, much, much longer button title", action: {}) .buttonStyle(MyButtonStyle(bgColor: .blue, fgColor: .white)) } } } struct MyButtonStyle: ButtonStyle { var bgColor: Color? var fgColor: Color? func makeBody(configuration: Configuration) -> some View { configuration.label .font(.headline) .bold() .allowsTightening(true) .lineLimit(2) .frame(width: 200, height: 60) .background(bgColor ?? .gray) .foregroundStyle(fgColor ?? .white) .clipShape(RoundedRectangle(cornerRadius: 16)) } } #Preview { ContentView() } That example gives you this: Note that you can change the number of lines in the button by changing .lineLimit().
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Oct ’24
Reply to XCode & MacOS Version
Sadly, that's the state of things. You're using an almost 10 year old laptop. Do you know anyone with a Mac with macOS 14.5 or later? Or, you can go down the usual route of refurbished machines or an auction site, or a trade-in.
Replies
Boosts
Views
Activity
Oct ’24
Reply to Conditionally compile newer API with older XCode
Xcode 15 doesn't support the iOS 18 SDK, so you cannot build iOS 18 apps with an Xcode earlier than version 16. There is no workaround for that. I suppose you should be asking how to fix the non-trivial issue with building your app in Xcode 16?
Replies
Boosts
Views
Activity
Oct ’24
Reply to macos menu bar color picker not working properly
It would help to see your code as you might be doing something wrong in there.
Replies
Boosts
Views
Activity
Oct ’24
Reply to macos menu bar color picker not working properly
You haven't actually told us why the ColorPicker isn't working properly... Show us your code, and explain exactly what you want to happen, and what it's actually doing. Maybe a screenshot would help too?
Replies
Boosts
Views
Activity
Oct ’24
Reply to Gradient rendering issue with alpha set to something other than one
To write code you need to use three backticks, i.e.: ``` Because you used only one, the code isn't formatted correctly. And, because you didn't edit your post within an hour to correct this, you would now have to add a new reply with the fixed code. You can do this if you like. I doubt many people will reformat your code themselves.
Replies
Boosts
Views
Activity
Oct ’24
Reply to IOS18 “updates”
now I just have to have the same lock screen and home screen background? No. Just customise the Lock Screen as usual, and when you see the two screens (the Lock Screen and Home Screen with darkened squares for the app icons), tap the Home Screen one, and at the bottom tap "Photo". I have my phone in darkmode so now I just have to deal with the ugly black thumbnails for the app? I can’t revert them to normal colors while keeping dark mode? Yes, I think you can. Customise the Home Screen by holding a finger down in a space on the screen, then in the top left tap "Edit" then "Customize". In the panel that appears at the bottom of the screen choose "Light", then press the little sun icon in the top left of that panel. That will change the background to dark, but leave the icons light. Does that work for you? By the way, these are the Developer Forums where third party developers of apps for Apple;s operating systems talk about code and ask for help on how to write some code. This isn't the place for product support questions. For that, go to the Apple Support Forums. Thanks.
Topic: Design SubTopic: General Tags:
Replies
Boosts
Views
Activity
Oct ’24
Reply to WhatsApp iso 18.1
Well, since iOS 18.1 isn't out yet, I'd say you should report any bugs with WhatsApp to the maker of that app. Get in touch with Meta.
Replies
Boosts
Views
Activity
Oct ’24
Reply to LGBTIQ
You can either pay someone to do it - but, please don't solicit for it here; or you can learn to write it yourself. There are lots of Swift and SwiftUI tutorials, and the Apple Developer pages have sample code that will help you along.
Topic: Community SubTopic: Apple Developers Tags:
Replies
Boosts
Views
Activity
Oct ’24
Reply to Ios 18 GPS accuracy
These are the Developer Forums, where developers of apps for Apple's platforms ask each other for hints and tips on coding. Your question is more of a product support one, so I'd suggest you ask it over at the Apple Support Forums. Thanks.
Replies
Boosts
Views
Activity
Oct ’24