0

I'm trying to create simple application (for testing purpose) with NSScrollView and 2 multi-line labels inside it (title and document). I can't use integrated TextView because I need 1 general scroller to scroll all content, not just for one selected TextView.

So generally I need fixed one-line title and document text with shared scroller.

I have no mind how to make this.

I've attached my sample project (only Storyboards) with scoller, you can take a look here: scroller.zip

Vasily
  • 3,740
  • 3
  • 27
  • 61
  • What have you achieved so far? Didn't google help? Perhaps https://www.youtube.com/watch?v=UnQsFlMGDsI could bring you closer to the solution – ULazdins Sep 16 '15 at 14:09
  • @ULazdins, i've tried to use that guide for my application, but scrollView isn't scrolling. That guide is for iOS, but I think Mac OS' scroll view is little different. – Vasily Sep 16 '15 at 14:53
  • what is the heigth of your scrollview content? It will scroll only if the content height is larger than the containing element's height. – ULazdins Sep 17 '15 at 11:18
  • @ULazdins, I've added attachment with simple scroller made for you, can you take a look? I think problem in constraint: "equal heights", but if I remove that constraint I can't position label inside scrollView (no Y axis for scroller). – Vasily Sep 18 '15 at 12:32

1 Answers1

1

I'm not sure if this is possible in the designer, but it is possible to set correct constraints in the runtime. Follow the steps:

  1. In the storyboard select your text field
  2. Set bottom margin constraint (28 in your example)
  3. Set height constraint (242 in your example)
  4. Connect the height constraint to an outlet in the viewcontroller (for example @IBOutlet weak var labelHeightConstraint: NSLayoutConstraint!)
  5. In the viewcontroller's viewDidLoad method set constraints height to expected height (for example
    labelHeightConstraint.constant = 1000)
  6. Run :)

Hope it helps!

ULazdins
  • 1,975
  • 4
  • 25
  • 31
  • Nice, it's worked! But now my label is attached to bottom of ScrollView if I label is short (e.g.: "123"). How can I attach it to top of View? – Vasily Sep 18 '15 at 20:40
  • I guess that you have to change the constraint ScrollView-to-it's_parentView from being '=x' to '=>x'. This will ensure that scrollview always sticks to the top – ULazdins Sep 19 '15 at 19:12
  • ULazdins, can u say more exactly what I need to change, please? If i'm changing any constraint to => x, I'm getting multiple constraint errors :( – Vasily Sep 20 '15 at 17:12
  • You have to change Text Field's Bottom Space constraint to >=28 (or any other number). – ULazdins Sep 22 '15 at 13:27
  • ULazdins, sorry it doesn't work, I'm getting constraint errors that no Y coordinates are specified. Here my last iteration of sample project: https://dl.dropboxusercontent.com/u/42855950/scoller_2.zip, if I'm changing bottom constraint here I'm getting that Y-axis error. – Vasily Sep 24 '15 at 10:45
  • Take a look at my sample, based on your project: https://www.dropbox.com/s/xa64ik7nnpj5o5q/Scroller.zip?dl=0 – ULazdins Sep 25 '15 at 06:43
  • ULazdins, in your sample scrolling is not working :), try to set height constraint to 800 or input some more text. – Vasily Sep 25 '15 at 10:16
  • Finally fixed problem. If you're adding Align to Y-center constraint all is working. – Vasily Sep 25 '15 at 15:00