can show rating images and tap actions works fine.

This commit is contained in:
2015-06-30 20:12:09 +08:00
parent bc2f1dd5b8
commit 5237bb877b
11 changed files with 95 additions and 4 deletions
@@ -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 -4
View File
@@ -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
}
}
}