Swift-for loop create button

This afternoon it is simple to write a login interface:

Swift-for loop create button
0.0.png

In the middle of the three buttons I was created with the for loop (fit looks a little ink – = live to see it), the code is as follows:

/ * * * three button * AppWidth: = UIScreen.mainScreen (CGFloat).Bounds.size.width * AppHeight: (CGFloat = UIScreen.mainScreen).Bounds.size.height / for index in 0..< 3 let shareBtn = {/ / button UIButton.init (frame: (CGRectMake (AppWidth / 3) * CGFloat (index) + AppWidth / 3 / 3, 20 / 3 / 3, AppWidth, AppWidth / 3 / 3)) / / picture splicing let imageStr = "share_" let imageName = imageStr + String (index) shareBtn.setImage (UIImage.init (named: imageName), forState:, UIControlState.Normal) / / I first created a backView to button on the top, easy to fit backView.addSubview (shareBtn The text pictures) / / let shareLabel = UILabel.init (frame: (CGRectMake (AppWidth / 3) * CGFloat (index) + AppWidth / 3 / 3, 30 + shareBtn.frame.size.height, shareBtn.frame.size.width, 10) shareLabel.textAlignment) = NSTextAlignment.Center shareLabel.font = UIFont.systemFontOfSize (10) shareLabel.adjustsFontSizeToFitWidth = true / / respectively set the picture text and click switch {index case 0: shareLabel.text = "WeChat login" shareBtn.addTarget (self, action:, #selector (tapped1) forControlEvents: UIControlEvents.TouchUpInside) case 1: shareLabel.text = "micro-blog login" shar EBtn.addTarget (self, action:, #selector (tapped2) forControlEvents: UIControlEvents.TouchUpInside) default: shareLabel.text = "QQ log" shareBtn.addTarget (self, action:, forControlEvents: UIControlEvents.TouchUpInside #selector (tapped3))}

I changed the name of the picture into the order, more convenient to create

Swift-for loop create button
picture name.Png

Button click event response:

Func tapped1 () {print ("111")} func tapped2 () {print ("")} func tapped3 () {print ("}")}

0 ~ ah ~ ~ ~ ~ ~ ~ ~ ~ ~ I think it is quite convenient ~ ~ if there is any more convenient way to hope that under the guidance of ha ~ ~ ~ ~ ~ ~