1,多整frame,
忘了配色吧。UIColor,吃撑了一样。
想起Color,就想起Frame,LayOut
FRAME
init(frame: CGRect, index: Int) {
super.init(frame: frame)
titleLabel = UILabel.createLabel("\(index)", font: UIFont.systemFontOfSize(12), textAligment: .Center, textColor: UIColor.blackColor())
titleLabel?.frame = self.bounds
addSubview(titleLabel!)
backgroundColor = UIColor.init(white: 0.8, alpha: 1)
}
2,
oldView
Remove
//MARK:- func showData(){
func showData(){
for oldSub in contentView.subviews{
oldSub.removeFromSuperview()
}
var cnt = number!
3,ContainerView
Cell的 ContainerView,不要 忘记。
for i in 0..<cnt{
let row = i/rowNum
let col = i%rowNum
let frame = CGRectMake(margin + (btnW+spaceX)*CGFloat(col), spaceY+(btnH+spaceY)*CGFloat(row), btnW, btnH)
let btn = FCSerialBtn(frame: frame, index: i+1)
btn.tag = 500+i
btn.addTarget(self, action: #selector(clickBtn(_:)), forControlEvents: .TouchUpInside)
contentView.addSubview(btn)
}