2016-02-25 153 views
0

我試圖創建使用標籤和按鈕的自定義popopview,像這樣的東西;

custom popop

首先,創建一個帶有opac背景的標籤;
使用標籤和按鈕創建自定義的popuser(swift/ios)

let opacLabel = UILabel(frame:CGRectMake(0,0,self.screenWidth,self.screenHeight)) 
    opacLabel.backgroundColor = UIColor.lightGrayColor().colorWithAlphaComponent(0.9) 
    view.addSubview(opacLabel) 

然後是彈出視圖的圖層;

let categoryMenuLabel = UILabel(frame: CGRectMake(10,40,100,300)) 
    categoryMenuLabel.backgroundColor = UIColor.whiteColor() 
    categoryMenuLabel.clipsToBounds = true 
    categoryMenuLabel.layer.cornerRadius = 7 

,然後按鈕

let saveButton = UIButton(frame: CGRectMake(spaceX,400,150,40)) 
    saveButton.backgroundColor = UIColor.lightGrayColor() 
    saveButton.titleLabel!.font = UIFont(name: "Helvetia", size: 25) 
    saveButton.setTitle("Save", forState: UIControlState.Normal) 
    saveButton.addTarget(self, action: "categorySaveButtonPressed:", forControlEvents: UIControlEvents.TouchUpInside) 
    categoryMenuLabel.addSubview(saveButton) 

最後加入categoryMenuLabel到主要視圖和改變順序;

self.view.addSubview(categoryMenuLabel) 
    self.view.bringSubviewToFront(opacLabel) 
    self.view.bringSubviewToFront(categoryMenuLabel) 

使用此配置時,當我嘗試按下按鈕而不是按鈕時,它按下標籤下的表格單元格。 我也無法設置禁用標籤以外的觸摸操作。

回答

1

只需在標籤上啓用用戶交互。它默認關閉,並且阻止其孩子接收任何用戶交互,以及:

categoryMenuLabel.userInteractionEnabled = true