swift3.0 code to create a nine diagram of the classic interface--optimization chapter

Source: Internet
Author: User

In the previous article just simple implementation of the nine chart effect, this chapter needs to form an app interface nine graph effect

Override Func Viewdidload () {

Super.viewdidload ()

Createnine ()

}

Nine graph algorithm

Func Createnine () {

High

Let kappviewh:cgfloat=80

Wide

Let kappvieww:cgfloat=80

Number of rows

Let kcolcount:int=3

Interval

Let kstart:int=20

Let marginx:cgfloat= (Self.view.frame.size.width-cgfloat (kcolcount) *kappvieww)/cgfloat (kColCount+1)

Let marginy:cgfloat=10

For i in 0.. < 12 {

Let Row:int=i/kcolcount;

Let Col:int=i%kcolcount;

Let Colf:cgfloat=cgfloat (COL);

Let X=marginx+cgfloat (COL) * (Kappvieww+marginx);

Let Y=cgfloat (Kstart) +marginy+cgfloat (Row) * (Kappviewh+marginy);

var Imageview=uiimageview (Image:uiimage (named: ""))

Imageview.frame=cgrect (x:0, y:0, width:60, height:60)

Increase lable

var Namelabel=uilabel (Frame:cgrect (x:0, y:60, Width:int (KAPPVIEWW), height:20))

Namelabel.text= "Features"

Namelabel.textalignment=nstextalignment.center

Namelabel.backgroundcolor=uicolor.blue

var Btnbuuton=uibutton.button

Add button

Let Btnbutton=uibutton (Frame:cgrect (x:0, y:20, width:60, height:60))

Btnbutton.tag=i

Btnbutton.settitle ("button", For:UIControlState.normal)

Btnbutton.addtarget (Self, Action: #selector (Btnclick (sender:)), for:

. Touchupinside)

Let View=uiview (Frame:cgrect (x:x, Y:y, Width:kappvieww, HEIGHT:KAPPVIEWH))

View.backgroundcolor=uicolor.red

View.addsubview (ImageView)

View.addsubview (Namelabel)

View.addsubview (Btnbutton)

Join view

Self.view.addSubview (view)

}

}

The effect is as follows

swift3.0 code to create a nine diagram of the classic interface--optimization chapter

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.