mirror of
https://github.com/wahyd4/FoodTracker.git
synced 2026-08-09 04:46:38 +10:00
can show rating images and tap actions works fine.
This commit is contained in:
BIN
Binary file not shown.
+5
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Bucket
|
||||
type = "1"
|
||||
version = "2.0">
|
||||
</Bucket>
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "2-110H12040500-L.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "2-110H12040500-L-1.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "star-o.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "star-o-1.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.9 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.9 KiB |
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "star.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "star-1.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
@@ -18,9 +18,16 @@ class RatingControl: UIView {
|
||||
required init(coder aDecoder: NSCoder) {
|
||||
super.init(coder: aDecoder)
|
||||
|
||||
let emptyStar = UIImage(named: "emptyStar")
|
||||
let filledStar = UIImage(named: "star")
|
||||
|
||||
for _ in 1...5 {
|
||||
let button = UIButton()
|
||||
button.backgroundColor = UIColor.redColor()
|
||||
button.setImage(emptyStar, forState: .Normal)
|
||||
button.setImage(filledStar, forState: .Selected)
|
||||
button.setImage(filledStar, forState: [.Selected, .Highlighted])
|
||||
|
||||
button.adjustsImageWhenHighlighted = false
|
||||
button.addTarget(self, action: "ratingButtonTapped:", forControlEvents: .TouchDown)
|
||||
ratingButtons += [button]
|
||||
addSubview(button)
|
||||
@@ -37,12 +44,19 @@ class RatingControl: UIView {
|
||||
buttonFrame.origin.x = CGFloat(index * (buttonSize + 5))
|
||||
button.frame = buttonFrame
|
||||
}
|
||||
|
||||
updateButtonSelectionStates()
|
||||
}
|
||||
|
||||
//MARK: button action
|
||||
func ratingButtonTapped(button: UIButton){
|
||||
print("button pressed 🎃😀")
|
||||
|
||||
rating = ratingButtons.indexOf(button)! + 1
|
||||
updateButtonSelectionStates()
|
||||
}
|
||||
|
||||
func updateButtonSelectionStates(){
|
||||
for(index, button) in ratingButtons.enumerate() {
|
||||
button.selected = index < rating
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user