2015-05-13 83 views
0

我試着在我的標籤Button上應用一個面具。麻煩的是我的標籤發生了變化,我不知道如何解決這個問題。面具標題UIButton ios swift

var view : UIImageView = UIImageView(image: im) 
view.frame = CGRect(x: 0, y: 0, width: view.bounds.width, height: view.bounds.height) 
self.view.addSubview(view); 
view.layer.mask = btn.titleLabel!.layer 
view.layer.masksToBounds = true 

結果看起來是這樣的:

Screenshot of the result

所以,我的標籤的按鈕位置x:0 y:0(白色方塊是我的背景按鈕,這樣我的原始位置)

+0

這不是一個客觀的c問題.... – Magoo

+0

superview是什麼標籤?你想達到什麼目的? – Magoo

+0

標籤Superview是UIButton –

回答

0

只需創建一個按鈕來執行你的任務。

var button = UIButton.buttonWithType(UIButtonType.System) as UIButton 

    button.frame = CGRectMake(100, 100, 100, 50) 
    button.backgroundColor = UIColor.greenColor() 
    button.setTitle("Button", forState: UIControlState.Normal) 
    button.addTarget(self, action: "Action:", forControlEvents: UIControlEvents.TouchUpInside) 
    self.view.addSubview(button) 

通過這個,你會在特定標題特定位置設置按鈕。

+0

我的按鈕位於正確的位置,它是我的標籤,在掩碼後面移動 –

+0

您能否解釋標籤的需求,或者通過按鈕可以設置文本。 – Nikunj

+0

我沒有其他標籤,我使用的標籤按鈕 –