I think im missing something fundamental here because everyone seems to be able to do this simple task. Im trying to create an app that is very similar in presentation to the iPhone home screen (paging). I plan to have several pages that each have their own unique content. My understanding is that I can use UIScrollview to display and animate these pages/xib's but I have tried what seems like everything and am frustrated by the lack of instructions for newbs like me.
What I understand so far:
Declare IBOutlet UIScrollView *scroller
Set options in .m or in scrollview object via IB
connect fileowner of main .xib to *scroller
connect fileowner of main .xib to delegate
then somehow call in the other xib to load as the pages for the scrollview.
One thing i have found is that most of the tutorials and source codes i get are outdated or look different. Im using xcode 4.2. ANY HELP is greatly appreciated. Thanks!
I'm also a newbie so may be I don't understand your problem exactly but if you want to represent your scroll view in pages you should enable paging for it:
yourCoolScrollView.pagingEnabled = YES;
Related
Ok, so I will apologize in advance, but I am a complete noob to Swift and iOS development, but I really want to learn to code. I have followed quite a few tutorials and so forth online, but cannot seem to find an answer for this problem I am having. There has to be a simple solution to this because it doesn't seem like a very hard issue but the googles are not being my friend in finding an answer. I do not want to use storyboards because I want to learn the real meat and potatoes. I am using OS X 10.11, Xcode 7, writing the app for iOS 9, universal.
So, I designed a calendar app with quite a unique display, UI, and functionality than the other grid based calendars out there. I have a UIView that I want to be a container to hold the other views I need and pull them into the container view. The files I have are the included ViewController.swift and my custom files ContainerView.swift HeaderView.swift, CalView.swift, and CalDetailView.swift. I set classes for each file, the HeaderView is a basic UIView, CalView is a horizontal UIScrollView that enables pagination for the different calendar views like week, month, day, year, and so on. The CalDetailView is also a horizontal UIScrollView that will display event details to the user and also be the primary action area for the user for editing, adding events, etc.
Currently the ContainerView loads just fine and I can do whatever I want there and can create these other subviews without a problem but only in the ContainerView file. I want to keep these areas separated out into different files for my sanity and add them into ContainerView UIView as subViews with AutoLayout and everything, just like I am able to do inside the ContainerView file, but it would be enormous and I don't want that.
I believe the proper way to do this is to add these subViews under the viewDidLoad() method of the main VC and create my AutoLayout constraints in the VC file, then I just want to load my subViews in the ContainerView file and build the screen. The separate subView files will contain all of my drawing code and touch events and so forth for the views.
Here's a simple wireframe of what I am trying to accomplish...
The whole window is ContainerView.swift the rest, subViews of ContainerView.
WireFrame
This question is a little open ended and non specific, but let's ignore this for now (it is your first time), in future please be more specific, this is the kind of response a tutorial might be better providing. You will have enough to do, without avoiding Storyboards - feel free to use them.
In any case it is fine.
Given a UIView subclass MyView, in your main view controller:
override func viewDidLoad() {
super.viewDidLoad()
....
let myView = MyView()
self.view.addSubView(myView)
myView.frame = ... OR <SET CONSTRAINTS>
....
}
Essentially you will initialise those view subclasses and add them as appropriate.
Im really confused because my problem may sound silly, i try to explain it clear - when i add anything on storyboard view controller it has no effect. And obvious, my viewController set properly to a controller, that manage storyboard scene. I adding anything - buttons, imageViews, it doesn't appear on a screen at all.
Also i want to add, i never seen such problem before recent Xcode update, when storyboard scene's become "large" and there is single scene for any device (600x600).
That issue literally drive me crazy, i can manage interface objects programmatically but i don't want to, because i use to work with Storyboard. Could you please write some advice or solution?
Thanks!
You need to add positioning constraints. By default, it will leave elements where they are, so they might be cut off. Also make sure what should be in the background is Sent to Back.
You can check if the auto layout this interfirindo or even if you this in the right view.
I want to use a custom control in my project, specifically a horizontal picker view I found on cocoacontrols.com (http://cocoacontrols.com/platforms/ios/controls/cppickerview). I've been able to include it into my project, load data and it works very nicely.
The pickerView is setted up programatically on viewDidLoad but I'd really like to be able to use it via storyboards because I'm a using static tableView. I tried to add a UIView, set the class to the PickerView class and then set up the outlet. I builds without errors or warnings but the picker view does not appear. It only shows a white rectangle.
Anyone with experience in this? Is it possible at all or should I keep it programatically?
Thanks in advance!
Well, that's normal. CPPickerView does not seem to implement initWithCoder:... I only see an initWithFrame: in the source code, which obviously means you can only instantiate that custom UIView from code. Or you can change CPPickerView's implementation to support what you want. It's open source.
I have an iPad application and in one of my views i use UIScrollView and UIPageControl together to navigate between views array. when my simulator is on Portrait mode there is no problem but when i rotate it to Landscape just down side of the scrollview appears and i can see just about 30 per 100 of the whole view. How can i fix this situation can anyone help?
EDIT : I dynamically add some buttons-subviews on the subview that i have added to Scrollview, can some one give any idea about how to detect the orientation of the device and decide the frames. I need something like the pseudo below:
if(device_orientation == landscape){
subButton.frame=....;
textfield.frame=...;
}
else{
subButton.frame=....;
textfield.frame=...;}
}
i tried but i got black screen..
EDIT-2
I used Interface builder for some views and there are some dynamically created views.I played a little with Autoresizing properties on the .xib file and now it looks perfect but the dynamic ones(they are all objects of a subclass of UIButton) dont response to any code(resizing, bacground color-photo ect..)
Are you using interface builder or creating your view programmatically?
It would be helpful if you could post some more of your source or some screenshots so that we can see a bit more clearly what's going on. As a stab in the dark, you might want to try setting the 'autoresizingMask' property of the views which you want to resize to '~UIViewAutoresizingNone' (not-none/flexible). If you can provide some more details, I'll try to help you some more :)
I've been banging my head with this issue for the last two days. Googled a lot but wasn't able to find the answer yet, so I decided to request some help here. Let's see if I get any luck.
I'm coding a reusable control that consists of an UIView with a variable number of customized UIButtons. I implemented initWithFrame:, initWithCoder: and drawRect: where the buttons (which are built prior to drawing) are actually added to the view. Everything is done programmatically since the UIButton content should be supplied when using the control, so there's no XIB for this UIView.
This UIView, let's call it CustomizableBarButton is then used in an UIViewController, let's call it MyTestViewController with a view on it, let's call it customizableBarButtonView.
MyTestViewController's GUI was set on IB where an UIView was tied to customizableBarButtonView (the class was matching accordingly).
MyTestViewController's is a pretty standard class except for the viewWillAppear: that initializes the buttons and passes them to the CustomizableBarButton along with some other options.
The issue is that everything works perfectly...except for the first time!
I mean, when I run the app on the simulator (I haven't tried it on the iPhone yet but I strongly believe that it's not an hardware issue) the MyTestViewController shows the customizableBarButtonView background but not the buttons. Now when you click on the place where a button should be all the buttons suddenly appear!
I'm puzzled since the CustomizablebarButton drawRect: runs before the strange "click n'appear" effect and the buttons are actually added to the subview.
Another hint that my help: if you don't click on the buttons (so you still got no buttons yet) but rotate the device they will also appear as if by magic!
It is probably something very simple but I'm missing it and I'm going nuts...
Can someone lend a hand on this, please?
Thanks in advance!
You said you're adding the buttons in drawRect:. Don't do that. You need to add the buttons in your init methods.