Post

Replies

Boosts

Views

Activity

CAShapeLayer and CAText Layer question/help
All, I got the code to create a pie chart based on a number entered. The pie segments of CAShapeLayers are equal segments of the pie. that all gets laid out correctly. Now I'm trying to get the number of the segment into the center of the pie segment. For example a circle equally divided into 4 segments, and each segment is numbered 1, 2, 3 and 4. Yet the text never displays or shows. I've commented out the CATextLayer code as it's not working. I can't figure out what is wrong or why the text number isn't being displayed. here's the code: As always any help is appreciated.  var CircleEndAngle = (CGFloat.pi*2)/CGFloat(Number) var circlePath = UIBezierPath(arcCenter: Center, radius: CGFloat(DeviceRadius), startAngle: CircleStartAngle, endAngle: CircleEndAngle, clockwise: true) circlePath.addLine(to: view.center) circlePath.close()             //let TextNum = CATextLayer()             while i < Number {                 circlePath = UIBezierPath(arcCenter: Center, radius: CGFloat(DeviceRadius), startAngle: CircleStartAngle, endAngle: CircleEndAngle, clockwise: true)                 circlePath.addLine(to: view.center)                 circlePath.close()                 let shapeLayer = CAShapeLayer()                 //let TextNum = CATextLayer()                                  shapeLayer.lineWidth = 3.0                 if Number > 50 {                         shapeLayer.strokeColor = UIColor.black.cgColor                 }                 else {                         shapeLayer.strokeColor = UIColor.white.cgColor                 }                 if LoopCounter > 10 {                     LoopCounter = 0                     CycleColorArrayIndex = 1                 }                 switch CycleColorArrayIndex {                 case 0:                     shapeLayer.fillColor = UIColor.red.cgColor                 case 1:                     shapeLayer.fillColor = UIColor.blue.cgColor                 case 2:                     shapeLayer.fillColor = UIColor.green.cgColor                 case 3:                     shapeLayer.fillColor = UIColor.purple.cgColor                 case 4:                     shapeLayer.fillColor = UIColor.cyan.cgColor                 case 5:                     shapeLayer.fillColor = UIColor.black.cgColor                 case 6:                     shapeLayer.fillColor = UIColor.magenta.cgColor                 case 7:                     shapeLayer.fillColor = UIColor.brown.cgColor                 case 8:                     shapeLayer.fillColor = UIColor.yellow.cgColor                 case 9:                     shapeLayer.fillColor = UIColor.orange.cgColor                 case 10:                     shapeLayer.fillColor = UIColor.darkGray.cgColor                 default:                     shapeLayer.fillColor = UIColor.gray.cgColor                 }                 shapeLayer.path = circlePath.cgPath                 //TextNum.string = "\(i)"                 //shapeLayer.addSublayer(TextNum)                 ShapeLayers.append(shapeLayer)                 i = i+1                 CircleStartAngle = CircleEndAngle                 CircleEndAngle = CircleStartAngle + ((CGFloat.pi*2)/(CGFloat(Number)))                 circlePath = UIBezierPath(arcCenter: Center, radius: CGFloat(DeviceRadius), startAngle: CircleStartAngle, endAngle: CircleEndAngle, clockwise: true)                 LoopCounter = LoopCounter + 1                 CycleColorArrayIndex = CycleColorArrayIndex + 1             }             for S in ShapeLayers {                 //TextNum.string = "\(S)"                 //view.layer.addSublayer(TextNum)                 view.layer.addSublayer(S)             }         }     } } Thanks for any suggestions/help Matt P.
0
0
184
Aug ’20
How do I change an image in a button
All, I've got the ability to select images figured out. As well as set images in a button statcally.However, I want to be able to change an image in a button after an image is selected.I have been at this for days and can't seem to figure it out, or find any answers to my question.Any help is appreciatedThe code I have is:Button(action: { if(self.ImageSelectedFlag == false) { self.showImages.toggle() } else { ????????????? } }) { Image(systemName: "question") } .sheet(isPresented: $IsShowingImages, content: { ImagePicker(isPresented: self.$IsShowingImages, ImageSelected: self.ButtonImage, ImageSelectedFlag: self.$ImageSelectedFlag) })
2
0
454
Mar ’20
How can I have a CGFloat only display 2 decimal points in Text
Ok, even though I am EXTREMELY frustrated with this at this point.I figured I would ask:How can I get a CGFloat to display (in a text field) with only 2 decimal points.So:@State var PercentageValue : CGFloat = 15.338876Text("\(PercentageValue)"--&gt;displays: 15.338876I want Text("\(PercentageValue)" to display 15.33I've tried converting it with the String(NSString) and that gave me errorsI've tried using NumberFormatting and that gave me errors when I was tring to definenumberFormat.maximumFractionDigits = 2 --&gt;Error: Cannot convert value of type '()' to closure result type '_' (what ever that means...)Any help is appreciated.
1
0
442
Feb ’20
Apparently CGFloat is no longer a value in SWiftUI
simply trying to define a published variable of type CGFloat...import Combineimport Foundationclass Percentage:ObservableObject {@Published var percentage : CGFloat = 0}yields the error: Use of undeclared type 'CGFloat'YAAAAA! another basic error that should NEVER occurwhat a piece of junk.Long gone are the days of Steve Jobs and quality products that worked with apple.Now, it's problem after problem, error after error.The people at apple need to get back to basics, and build quality products that work.They need a hard lesson in TIME IS MONEY! I don't have the money or the time to fight with editors or basic things that should just work!
2
0
5.2k
Feb ’20
Back menu Item not displaying or working
Hello allMy first SwiftUI program..and I have to say I'm not really impressed with this...Issue is when I open the second View, the blue "&lt; Back" menu item never shows up.I have a NavigationLink to open a seperate View.Yet when the secondary view opens, the "&lt; Back" menu item never displays.From ContentView.swift:HStack { NavigationLink(destination: DetailView()) { Text("Summary") }.navigationBarTitle(" ").navigationBarHidden(false)From the DetailView.swift file:var body: some View { NavigationView { Group { VStack { Text("Detail View") } } }.navigationBarHidden(false).navigationBarBackButtonHidden(false)}I have been fighting with this for over 12 hours now. Quite frankly it is giving me the impression that SwiftUI is not worth the time or effort, and it is not designed to work at all. As this was something that could be done with storyboards in 20 minutes. This is extremely frustrating.So any help at this point would be appreciated.
2
0
560
Feb ’20