Developing dashboard controls with Swift (i)

Source: Internet
Author: User

Shortly after Apple Swift was introduced, it was an accidental opportunity to come into contact with the language, and to look at its syntax casually:


Instantly was moved, switch in incredibly boldly eliminated the break, is completely anti-human practices, other languages are not so bold and smart, basically switch, you have to match a lot of break (no developer considered cumbersome). Because the break was used at 99%, Apple simply omitted it. Of course, if you want to cross, you can use Fallthrough. The advantages of Swift are also very much omitted here 1000 words ...

You can download the control at the following address (no reservation, use it casually)

http://download.csdn.net/detail/ynmaoyong/8091225

To the bottom of this, here's a look at the control "Meterswift" instrumentation controls developed with Swift. This control runs on ios7+ and has the following features:

1, the dial size is flexible, can be used under the conditions of 100x100 to 350x350.

2, scale flexibility can be customized to display the maximum value, the degree of value.

3, flexible, replace the dial PNG, the hands PNG is completely your own control (no guilt, my graphics are down online).

4, easy to use, on a file, 2 graphics, including in your project on the line.

First, the use of controls

Effects used by the control:



Drag the slider to find that the needle is turning.

The following 2 libraries are used in this control:


Open the interface below Xcode 6.1 and add it.


Let's talk about how to use this control in a project, code to speak:

@IBAction func Sliderchange (sender:uislider) {

Setting Display values

Panel.setcurrgaugevalue (CGFloat (sender.value), Animation:false)

Dislable.text = "Speed: \ (Int (sender.value)) km/h"

}

Override Func Viewdidload () {

Super.viewdidload ()

Initializing drawing range Parameters

Let frame = CGRectMake (10, 10, 151, 151)

Initializing the control

Panel = Gaugepanel (frame:frame)

Self.slider.maximumValue = MAXVALUE

Self.view.addSubview (panel)

Containview.addsubview (panel)

}

1. First put a view container on the interface.

2. Initialize the drawing scope of the control within the container.

3. Set the display value.

The following explains the configuration of the parameters in the Gauge.swift file

Maximum deflection angle

Letmaxoffsetangle:float = 120.0

Initialize pointer offset

Letpointeroffset:float = 90.0

Maximum display value

Letmaxvalue:float = 200.0

The number of degrees between large squares

Letcellmarknum:int = 5

Number of large squares

Letcellnum:int = 5

Text displayed in the center of the Dial

letgaugestring:string = "unit: km/h"

Default dial Size (square)

Letdefluatsize:int = 300

Load dial and pointer png

Self.pointer = Uiimageview (Image:uiimage (named: "Pointer2.png"))

Self.gaugeview = UIImage (named: "Gaugeback.png")



Developing dashboard controls with Swift (i)

Related Article

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.