-
-
Save cedared/c8f3cb321add7b57e5a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CategoryView: UIView { | |
var categoryButtonArray: Array<UIButton> = [] | |
let buttonHeight = 35.0 | |
let buttonWidth = Double(screenWidth / 5) | |
var buttonLeft = 0.0 | |
var httpHelper = HttpHelper() | |
init(categoryInfos: NSMutableOrderedSet) { | |
super.init(frame: CGRect(x: 0.0, y: 0.0, width: Double(screenWidth), height: buttonHeight * 2)) | |
for each in 0...9 { | |
let categoryButton = UIButton() | |
categoryButton.titleLabel?.font = UIFont(name: "Helvetica Neue", size: 17) | |
categoryButton.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal) | |
categoryButton.setTitle((categoryInfos.objectAtIndex(each) as! CategoryItem).name, forState: UIControlState.Normal) | |
categoryButton.tag = (categoryInfos.objectAtIndex(each) as! CategoryItem).id | |
self.categoryButtonArray.append(categoryButton) | |
self.addSubview(self.categoryButtonArray[each]) | |
} | |
for each in 1...8 { | |
self.categoryButtonArray[each].setTitle((categoryInfos.objectAtIndex(each+1) as! CategoryItem).name, forState: UIControlState.Normal) | |
self.categoryButtonArray[each].tag = (categoryInfos.objectAtIndex(each+1) as! CategoryItem).id | |
} | |
for each in 0...4 { | |
categoryButtonArray[each].frame = CGRect(x: self.buttonLeft, y: 0.0, width: self.buttonWidth, height: self.buttonHeight) | |
self.buttonLeft = self.buttonLeft + self.buttonWidth | |
} | |
self.buttonLeft = 0 | |
for each in 5...8{ | |
categoryButtonArray[each].frame = CGRect(x: self.buttonLeft, y: self.buttonHeight, width: self.buttonWidth, height: self.buttonHeight) | |
self.buttonLeft = self.buttonLeft + self.buttonWidth | |
} | |
categoryButtonArray[0].setTitle("广场舞", forState: UIControlState.Normal) | |
categoryButtonArray[0].tag = 8 | |
categoryButtonArray[9].frame = CGRect(x: self.buttonLeft, y: self.buttonHeight, width: self.buttonWidth, height: self.buttonHeight) | |
categoryButtonArray[9].setTitle("全部", forState: UIControlState.Normal) | |
} | |
required init?(coder aDecoder: NSCoder) { | |
fatalError("init(coder:) has not been implemented") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
class CategoryView: UIView {
}