Creating progress circle as WKInterfaceImage in Watch App

前端 未结 6 1889
余生分开走
余生分开走 2020-12-14 11:17

I am trying to create a progress circle for the Apple Watch version of my app. I know that we aren\'t able to use UIViews (which would make things so much easier!) so I am l

6条回答
  •  无人及你
    2020-12-14 11:37

    Nobody posts code??? Here it is! enjoy:

    1) Create the images here: http://hmaidasani.github.io/RadialChartImageGenerator/

    2) Drag n Drop a picker into your View Controller, and link it to some viewController.swift file. Set the Picker style to "Sequence" on the menu that appears on the right.

    3) Add this code to the viewController.swift , and connect the picker to the IBOutlet and the IBAction:

    import WatchKit
    import Foundation
    
    class PickerViewController: WKInterfaceController {
    
        override func awakeWithContext(context: AnyObject?) {
            super.awakeWithContext(context)
        }
    
        @IBOutlet var itemPicker: WKInterfacePicker!
    
        override func willActivate() {
            super.willActivate()
    
            let pickerItems: [WKPickerItem] = (0...100).map {
                let pickerItem = WKPickerItem()
                pickerItem.contentImage = WKImage(imageName: "singleArc\($0).png")
                return pickerItem
            }
            itemPicker.setItems(pickerItems)
        }
    
        @IBAction func pickerSelectedItemChanged(value: Int) {
            NSLog("Sequence Picker: \(value) selected.")
        }
    
        override func didDeactivate() {
            super.didDeactivate()
        }
    
    }
    

提交回复
热议问题