发布于 2016-06-23 23:46:53 | 159 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的Swift教程,程序狗速度看过来!

Swift编程语言

SWIFT,苹果于2014年WWDC(苹果开发者大会)发布的新开发语言,可与Objective-C*共同运行于Mac OS和iOS平台,用于搭建基于苹果平台的应用程序。


这篇文章主要为大家详细介绍了swift实现自定义圆环进度提示效果,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了swift圆环进度提示效果的实现代码,供大家参考,具体内容如下

效果图:

实现代码:


/
// ViewController.swift
// PureSwiftAuto
//
// Created by 王木木 on 16/5/17.
// Copyright © 2016年 王木木. All rights reserved.
//
 
import UIKit
 
class ViewController: UIViewController {
   
  let cireView = cireview.newAutoLayoutView()
   
  override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    creatCire()
  }
   
  func creatCire(){
    self.view.addSubview(cireView)
    self.cireView.value = 2
    self.cireView.maximumValue = 100
    self.cireView.backgroundColor = UIColor.yellowColor()
    self.cireView.frame = CGRectMake(100, 100, 100, 100)
    wangmumu()
  }
   
  func wangmumu(){
     
    self.cireView.value += 2
     
    if self.cireView.value == 90 {return}
     
    self.performSelector("wangmumu", withObject: self, afterDelay: 0.2)
     
  }
   
}
 
 
class cireview: UIView{
   
  var value: CGFloat = 0 {
    didSet {
      self.setNeedsDisplay()
    }
  }
   
  var maximumValue: CGFloat = 0 {
    didSet { self.setNeedsDisplay() }
  }
  override init(frame: CGRect) {
    super.init(frame: frame)
    self.opaque = false
  }
   
   
  override func drawRect(rect: CGRect) {
    super.drawRect(rect)
     
    //线宽度
    let lineWidth: CGFloat = 10.0
    //半径
    let radius = CGRectGetWidth(rect) / 2.0 - lineWidth
    //中心点x
    let centerX = CGRectGetMidX(rect)
    //中心点y
    let centerY = CGRectGetMidY(rect)
    //弧度起点
    let startAngle = CGFloat(-90 * M_PI / 180)
    //弧度终点
    let endAngle = CGFloat(((self.value / self.maximumValue) * 360 - 90) ) * CGFloat(M_PI) / 180
     
    //创建一个画布
    let context = UIGraphicsGetCurrentContext()
     
    //画笔颜色
    CGContextSetStrokeColorWithColor(context, UIColor.blueColor().CGColor)
     
    //画笔宽度
    CGContextSetLineWidth(context, lineWidth)
     
    //(1)画布 (2)中心点x(3)中心点y(4)圆弧起点(5)圆弧结束点(6) 0顺时针 1逆时针
    CGContextAddArc(context, centerX, centerY, radius, startAngle, endAngle, 0)
     
    //绘制路径
    CGContextStrokePath(context)
     
    //画笔颜色
    CGContextSetStrokeColorWithColor(context, UIColor.darkGrayColor().CGColor)
     
    //(1)画布 (2)中心点x(3)中心点y(4)圆弧起点(5)圆弧结束点(6) 0顺时针 1逆时针
    CGContextAddArc(context, centerX, centerY, radius, startAngle, endAngle, 1)
     
    //绘制路径
    CGContextStrokePath(context)
     
  }
   
  required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
  }
   
}

以上就是本文的全部内容,希望对大家的学习有所帮助。



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务