preface

Recently, I was learning SwiftUI, and I remembered that my designer friend had a design drawing for an Apple widget, and the widget -WigetKit can only be developed in SwiftUI, so it’s just a good place to practice.

Download at OneDay

Practical effect

The pieces are refreshed every 10 minutes or so and come in three sizes: small, medium and large.

The effect of personal feeling is very good, very suitable for decorative desktop 😆

The data source

  • The copywriting is provided by Hitokoto, with lots of good jokes and chicken soup. The interface is v1.hitokoto.cn

  • The images are from LoremPicsum, a site that offers a variety of exquisite images that can be pieced together with custom parameters to get different sizes and filters.

The current progress

At present, it is just a widget to decorate the desktop. The main interface of the App is not ready yet, only the widget function.

Since it’s not long since I started learning SwiftUI, many of the grammar is still in the exploration, and will be gradually improved in the future, the next plan:

1. Fit the size of iPad; 2. You can edit background images (such as photos); 3. Can edit copy; 4. Customize text position; 5. More content.Copy the code

confusion

I don’t understand the refresh time of the widget, I set it like this:

func getTimeline(for configuration: ConfigurationIntent.in context: Context.completion: @escaping (Timeline<Entry>) - > ()) {
    // Request data
    OneDayModel.fetch(family: context.family) { model in
        // Set the next refresh time to 10 minutes later
        let refreshDate = Calendar.current.date(byAdding: .minute, value: 10, to: Date())!
        
        Entries provide data for the next update
        let entry = OneDayEntry(date: refreshDate, model: model)
        
        // Refresh the data and control the next refresh time
        let timeline = Timeline(entries: [entry], policy: .atEnd)
        completion(timeline)
    }
}
Copy the code

The code is set to refresh after 10 minutes, but in fact is 15~20 minutes to refresh once, I do not know whether I made a mistake, to be solved…

The last

Thanks for the design drawing provided by the design brother, and also thanks for the advice and Logo given by the design sister of the company.

If the effect is good, you can download the installation experience, like it might as well give a Star, in the future will continue to improve other functions ~😊

Download at OneDay