我想讓一個按鈕以編程方式填充scrollview的寬度。我也編程按鈕。 scrollView.width不起作用,我將使用什麼scrollView的寬度?謝謝。如何以編程方式填充scrollview的寬度
class ViewController: UIViewController {
@IBOutlet weak var scrollView: UIScrollView!
let screenSize: CGRect = UIScreen.mainScreen().bounds
let btn1 = UIButton(frame: CGRect(x: 100, y: 100, width:200, height: 50))
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
btn1.backgroundColor = UIColor.clearColor()
btn1.layer.cornerRadius = 5
btn1.layer.borderWidth = 1
btn1.layer.borderColor = UIColor.redColor().CGColor
btn1.setTitle("1", forState: .Normal)
scrollView.addSubview(btn1)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
嘗試'scrollView.frame.size.width' –