2016-03-04 59 views
1

你好我已經創建了動態按鈕,在我的靜態的TableView這樣如何添加微調指數在編程創建按鈕

override func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? { 
     let footerView = UIView(frame: CGRectMake(0, 0, tableView.frame.size.width, tableView.frame.size.height)) 

    let button = UIButton(type: UIButtonType.System) as UIButton 
     button.frame = CGRectMake(0, 0, 414, 65) 

     button.setTitle(buttonTitle, forState: UIControlState.Normal) 
     button.addTarget(self, action:buttonAction, forControlEvents: UIControlEvents.TouchUpInside) 
     button.setTitleColor(UIColor.whiteColor(), forState:UIControlState.Normal) 
     button.titleLabel?.font = UIFont(name: Variables.MONTESERRAT_REGULAR, size: 20.0) 
    button.backgroundColor = UIColor().blueColor()  //top 
     footerView.addSubview(button!) 


     return footerView 
} 

我想在按鈕的頂部顯示微調它的點擊時。我知道如何使點擊功能或如何創建一個微調。我只是不知道如何將旋鈕放在按鈕頂部以代替標題,以便當用戶單擊按鈕時,標題隱藏和微調控件在標題位置移動。我希望你明白我的意思

+0

將微調器添加爲按鈕的子視圖。設置微調中心爲button.center和: [button addSubview:yourspinner]; – 2016-03-04 13:26:59

回答

2
UIActivityIndicatorView *myspinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; 
    [myspinner setCenter:button.center]; 
    [button addSubview:myspinner]; 
+0

非常感謝 – user1hjgjhgjhggjhg

0
  1. 您創建一個微調(UIActivityIndicatorView),也使其自動隱藏(setHidesWhenStopped:
  2. 你作爲子視圖添加到您的按鈕(addSubview
  3. 你把它放在你的按鈕中心(setCenter:
  4. 在按鈕按下你要的setTitle空字符串(setTitle:forControlState:)並運行微調(startAnimating
0

以下是我常做,還有,你可以利用一些不同的行爲:

let spinner = UIActivityIndicatorView(activityIndicatorStyle: .White) 

spinner.frame = CGRect(x: -20.0, y: 6.0, width: 20.0, height: 20.0) // (or wherever you want it in the button) 
spinner.startAnimating() 
spinner.alpha = 0.0 

button.addSubview(spinner) 

您可以相應地改變阿爾法。或使用隱藏屬性,停止/啓動動畫等。

相關問題