iOS project development-Custom circular progress tip control

Source: Internet
Author: User

The default progress bar in iOS is the horizontal progress bar, which often does not meet our needs. But we can customize a similar circular progress hint control, mainly using the drawing mechanism in iOS. Here we are going to implement a continuous increase in the effect of a button click and then a circular progress hint.

(1) Create a new cocoa Touch Class, and note that you want to inherit from UIView. This is the drawing class that draws a circular background and a scalloped progress. The specific implementation is as follows:

Import Uikitclass Progresscontrol:uiview {override init (Frame:cgrect) {super.init (frame:frame) Self.backgroundcolor = Uicolor (white:1, alpha:0)//Initialize the drawing background as white;} Required init (coder Adecoder:nscoder) {Super.init (Coder:adecoder)} private var _progressvalue:cgfloat = 0//This is the current progress; Func Getprogressval UE ()->cgfloat{return _progressvalue} func setprogressvalue (value:cgfloat) {//Set progress; _PR                Ogressvalue = value Setneedsdisplay ()} override func DrawRect (rect:cgrect) {//Draw circular background and sector progress; var context = Uigraphicsgetcurrentcontext () var r = Rect.width/2 Cgcontextaddarc ( Context, R, R, r, 0, 3.1415926 * 2, 0) cgcontextsetrgbfillcolor (context, 0.5, 0.5, 0.5, 1) cgcontextfillpat H (context) Cgcontextaddarc (context, R, R, r, 0, 3.1415926 * 2 * _progressvalue, 0) cgcontextaddlinet   Opoint (Context, R, R)     Cgcontextsetrgbfillcolor (context, 0, 0, 1, 1) cgcontextfillpath (context)}} 

(2) Drag a button in the interface to drag the action event. The following are implemented in Viewcontroller:

Import Uikitclass Viewcontroller:uiviewcontroller {    var progresscontrol:progresscontrol!        Override Func Viewdidload () {        super.viewdidload ()                Progresscontrol = Progresscontrol (Frame:cgrect (x:100, y: (width:100, height:100))        Self.view.addSubview (Progresscontrol)            }        //Click the button to increase the progress    @IBAction func Addprogressvaluepressed (Sender:uibutton) {                Progresscontrol.setprogressvalue ( Progresscontrol.getprogressvalue () +0.1)            }            override Func didreceivememorywarning () {        Super.didreceivememorywarning ()        //Dispose of any resources, can be recreated.    }}

(3) The result of the final implementation is as follows:

。


。


For other triggering events, you can also use the custom circular progress control to prompt.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

iOS project development-Custom circular progress tip control

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.