UIScrollView直接在StoryBoard中拖控件
2016-01-18 16:21
435 查看
转自:How do i use UIScrollView in Storyboard
I'm answering my own question because I just spent 2 hours to find the solution and StackOverflow allows this QA style.
Start to finish here is how to make it work in storyboard.
1: go to you view controller and click on
2: change Size to
3: Go to the main view on that storyboard, not your scrollview but rather the top level view.
4: Click
Now you will see that you storyboard has your view setup so you can see the entire height of your scroll for easy design.
5: Drop on a scrollview and stretch it so it takes up the whole view. You should now have a scrollview with size of 320,1000 sitting on a view in your view controller.
Now we need to make it scroll and need to make it show content correctly.
6: Click on your scrollview and click on
7: Add a
Since we want to see our whole scroll view on the storyboard we stretched it and it has a frame of 320,1000 but in order for this to work in our app we need to change the frame down to what the visible scrollview will be.
8: Add a
Now when we run our app we will have a visible scrollview has a frame of 0,0,320, 416 and can scroll down to 1000. We are able to layout our subviews and images and whatnot in Storyboard just the way we want them to appear. Then our runtime attributes make sure to display it properly. All of this without 1 line of code.
项目地址:https://github.com/a0000/TestScrollView
I'm answering my own question because I just spent 2 hours to find the solution and StackOverflow allows this QA style.
Start to finish here is how to make it work in storyboard.
1: go to you view controller and click on
Attribute Inspector.
2: change Size to
Freeforminstead of Inferred.
3: Go to the main view on that storyboard, not your scrollview but rather the top level view.
4: Click
Size Inspectorand set this view to your desired size. I changed my height to 1000.
Now you will see that you storyboard has your view setup so you can see the entire height of your scroll for easy design.
5: Drop on a scrollview and stretch it so it takes up the whole view. You should now have a scrollview with size of 320,1000 sitting on a view in your view controller.
Now we need to make it scroll and need to make it show content correctly.
6: Click on your scrollview and click on
Identity Inspector.
7: Add a
User Defined runtime attributewith KeyPath of
contentSizethen type of SIZE and put in your content size. For me it is (320, 1000).
Since we want to see our whole scroll view on the storyboard we stretched it and it has a frame of 320,1000 but in order for this to work in our app we need to change the frame down to what the visible scrollview will be.
8: Add a
runtime attributewith KeyPath
framewith Type RECT and 0,0,320,416.
Now when we run our app we will have a visible scrollview has a frame of 0,0,320, 416 and can scroll down to 1000. We are able to layout our subviews and images and whatnot in Storyboard just the way we want them to appear. Then our runtime attributes make sure to display it properly. All of this without 1 line of code.
项目地址:https://github.com/a0000/TestScrollView
相关文章推荐
- java中的String,StringBuilder,StringBuffer
- javax.servlet.ServletException: java.lang.ClassFormatError: Incompatible magic value 0解决方案
- ArcGIS中QueryTask,FindTask,IndentifyTask 之间的区别
- IOS开发UI-------UIView(视图)
- UIImage 注意事项
- 【从零学习经典算法系列】分治策略实例——高速排序(QuickSort)
- 快排Quick Sort到底有多快?
- You attempted an operation that requires PV drivers to be installed on the VM.
- [iOS]关于状态栏(UIStatusBar)的若干问题
- UESTC--1256
- Divide and conquer:Dropping tests(POJ 2976)
- 果冻回弹效果 拉刷新效果 UIBezierPath
- UItableView搜索和全部删除
- UICollectionView的基本使用
- UITableView 分割线贴近左端屏幕开始
- 学习笔记:关于segue
- NGUI 相片循环滚动效果
- UI控件RecyclerView浅析
- 【django】request
- LeetCode Range Sum Query - Mutable