mirror of
https://github.com/wahyd4/FoodTracker.git
synced 2026-08-09 04:46:38 +10:00
add cutomer sub image view
This commit is contained in:
BIN
Binary file not shown.
@@ -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 🎃😀")
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user