我制作了一个带有2个按钮的自定义视图Xib
文件,我在我的视图控制器中调用它,但是当我按下按钮时,只有当我按下图像中的顶部时,底部才能点击。我该如何解决?
//this class of Xib file
class AddCart: UIView {
@IBOutlet weak var cartImage: UIImageView!
@IBOutlet weak var btnYes: UIButton!
@IBOutlet weak var btnNo: UIButton!
var view:UIView!
var index = 0
override init(frame: CGRect) {
super.init(frame: frame)
setup()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setup()
}
func setup() {
view = loadViewFromNib()
view.roundedCorners()
btnNo.roundedCorners()
btnYes.roundedCorners()
//make rounded image and add border to it
view.autoresizingMask = [UIViewAutoresizing.FlexibleWidth, UIViewAutoresizing.FlexibleHeight]; addSubview(view)
}
func loadViewFromNib() -> UIView {
let bundle = NSBundle(forClass:self.dynamicType)
let nib = UINib(nibName: "AddCart", bundle: bundle)
let view = nib.instantiateWithOwner(self, options: nil)[0] as! UIView
return view
}
override func willRemoveSubview(subview: UIView) {
self.removeFromSuperview()
}
}
//here where i call it
if(addCart != nil && !addCart.view.hidden)
{
addCart.view.removeFromSuperview()
}
addCart = AddCart(frame: CGRect(x:((width)/2)-((600)/2), y:((height)/2)-(133/2), width:600, height:133))
addCart.btnYes.addTarget(self, action: #selector(ProductContentVC.addToCart(_:)), forControlEvents: .TouchUpInside)
addCart.btnNo.addTarget(self, action: #selector(ProductContentVC.addToCart(_:)), forControlEvents: .TouchUpInside)
addCart.btnYes.backgroundColor = appColor
addCart.btnNo.backgroundColor = appColor
self.addView.frame = CGRect(x:0, y:0, width:self.width, height:self.height)
self.addCart.frame = CGRect(x:(self.width/2)-((self.width - 10)/2), y:(self.height/2)-((133)/2), width:(self.width - 10), height:(133))
self.view.addSubview(addView)
self.addCart.alpha = 1
self.addView.addSubview(self.addCart)
答案 0 :(得分:1)
这是自定义视图的高度问题..这是172高度,但在代码我给它高度133这就是为什么按钮在超级视图之外..但我在代码中将其更改为172我的问题已解决alhamdulillah