0

I am trying to dynamically add buttons in UIScollView so that it becomes scrollable when the buttons overflow than its size but its not happening.

for data in result as! [NSManagedObject] {
    let magButton=UIButton(frame: CGRect(x: Int(newScroll.frame.origin.x), y: verti, width: Int(newScroll.frame.width), height: 25))
    magButton.addTarget(self, action: #selector(imageTapped), for: UIControlEvents.touchUpInside)
    magButton.backgroundColor=UIColor.gray
    magButton.tag=count
    magButton.contentMode = .left
    magButton.setTitle(data.value(forKey: "name") as! String, for: UIControlState.normal)

    myScrollVew.addSubview(magButton)

    verti+=26
}
1
  • 1
    Where do you update the scroll view's contentSize? Commented Jun 28, 2018 at 7:28

1 Answer 1

1

Add last line which update the scroll view content size.

myScrollVew.addSubview(magButton)

verti+=26
myScrollVew.contentSize = CGSize(width: myScrollVew.contentSize.width, height: magButton.frame.maxY)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.