2016-03-04 45 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) 

您可以相应地改变阿尔法。或使用隐藏属性,停止/启动动画等。