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