add accessoryImageView for BorderButton

This commit is contained in:
nixzhu
2015-08-20 17:55:38 +08:00
parent d29c05d26d
commit b1aaed01a9
3 changed files with 34 additions and 2 deletions
+2 -2
View File
@@ -26,9 +26,9 @@
<rect key="frame" x="168" y="570" width="39" height="37"/>
</pageControl>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="c1Z-F1-RQr" customClass="BorderButton" customModule="Yep" customModuleProvider="target">
<rect key="frame" x="134" y="607" width="107" height="40"/>
<rect key="frame" x="124" y="607" width="127" height="40"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<inset key="contentEdgeInsets" minX="20" minY="10" maxX="20" maxY="10"/>
<inset key="contentEdgeInsets" minX="30" minY="10" maxX="30" maxY="10"/>
<state key="normal" title="Start Yep">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
@@ -25,6 +25,8 @@ class ShowViewController: UIViewController {
super.viewDidLoad()
finishButton.tintColor = UIColor.yepTintColor()
finishButton.needShowAccessory = true
pageControlBottomConstraint.constant = Ruler.match(.iPhoneHeights(0, 10, 20, 30))
finishButtonBottomConstraint.constant = Ruler.match(.iPhoneHeights(20, 30, 40, 50))
+30
View File
@@ -15,6 +15,23 @@ class BorderButton: UIButton {
@IBInspectable var borderColor: UIColor = UIColor.yepTintColor()
@IBInspectable var borderWidth: CGFloat = 1
var needShowAccessory: Bool = false {
willSet {
if newValue != needShowAccessory {
if newValue {
showAccessory()
} else {
accessoryImageView.removeFromSuperview()
}
}
}
}
lazy var accessoryImageView: UIImageView = {
let imageView = UIImageView(image: UIImage(named: "icon_accessory_mini"))
return imageView
}()
override func didMoveToSuperview() {
super.didMoveToSuperview()
@@ -23,4 +40,17 @@ class BorderButton: UIButton {
layer.borderWidth = borderWidth
}
func showAccessory() {
accessoryImageView.tintColor = borderColor
addSubview(accessoryImageView)
accessoryImageView.setTranslatesAutoresizingMaskIntoConstraints(false)
let accessoryImageViewTrailing = NSLayoutConstraint(item: accessoryImageView, attribute: .Trailing, relatedBy: .Equal, toItem: self, attribute: .Trailing, multiplier: 1, constant: -10)
let accessoryImageViewCenterY = NSLayoutConstraint(item: accessoryImageView, attribute: .CenterY, relatedBy: .Equal, toItem: self, attribute: .CenterY, multiplier: 1, constant: 0)
NSLayoutConstraint.activateConstraints([accessoryImageViewTrailing, accessoryImageViewCenterY])
}
}