add cutomer sub image view

This commit is contained in:
2015-06-30 19:55:00 +08:00
parent d4bfe5ba6a
commit bc2f1dd5b8
2 changed files with 26 additions and 5 deletions
+26 -5
View File
@@ -9,19 +9,40 @@
import UIKit
class RatingControl: UIView {
//MARK: properties
var rating = 0
var ratingButtons = [UIButton]()
//MARK: initializaion
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
let button = UIButton(frame: CGRect(x: 0, y: 0, width: 44, height: 44))
button.backgroundColor = UIColor.redColor()
button.addTarget(self, action: "ratingButtonTapped", forControlEvents: .TouchDown)
addSubview(button)
for _ in 1...5 {
let button = UIButton()
button.backgroundColor = UIColor.redColor()
button.addTarget(self, action: "ratingButtonTapped:", forControlEvents: .TouchDown)
ratingButtons += [button]
addSubview(button)
}
}
override func layoutSubviews() {
let buttonSize = Int(frame.size.height)
var buttonFrame = CGRect(x: 0, y: 0, width: buttonSize, height: buttonSize)
for (index, button) in ratingButtons.enumerate() {
buttonFrame.origin.x = CGFloat(index * (buttonSize + 5))
button.frame = buttonFrame
}
}
//MARK: button action
func ratingButtonTapped(button: UIButton){
print("button pressed")
print("button pressed 🎃😀")
}
}