I have some problems with the layout of my core plot graph.
To be more precise, I have created a GraphViewController (.h, .m and associated nib file). In the nib file I have added another UIView. This embedded view will be used to set the graph (as I do not want it to use the whole view). I then need to create a hosting view from this embedded view.
The embedded view is named graphView, I first though I needed to get the frame representing the graphView and create the hostingView so the graph will fit in the graphView. When I use the:
CPHostingLayerView *hostingView = [[CPHostingLayerview alloc] initWithFrame: [graphView frame]]
...
it does not work as expected, the graph does not fit the view (it is bigger than the graphView I created in IB)
Hope I am clear :(
Any idea would be more than welcome.
thanks a lot,
Luc
I finally find an answer :) Instead of adding an UIView within IB and programmatically create a CPLayerHostingView, I directly declared the view as an CPLayerHostingView in IB, that works perfectly.
Regards,
Luc
I was stuck with the same issue. What worked for me is a simpler way :
In super-view (where you are adding the core plot graph as a subview), add this code:
[self.subview.graphHostingView setFrame:self.view.bounds];
where subview is the view with the core-plot graph. And add this code 'after' you have done the graph initialization in the sub-view.
Related
Used CollectionView-Simple sample code from apple. when run their project it works. But when run my project which is exactly same as apple sample code it doesn't shows images with grid layout but shows only navigation bar. Any idea why it is so.
Thanks for suggestions.
Check your dataSource and delegate for the UICollectionView in IB and make sure they are set just like the sample. More than likely you forgot to assign the delegate and dataSource to the UICollectionView.
Data Source and Delegate
You need to make sure that the collection view's dataSource and delegate are set properly.
If you are using Interface Builder, then make sure that you right-click drag* from the collection view to the little orange blob at the bottom of the scene. Repeat twice, once for both the Data Source and the Delegate.
If you are creating the view in code, you just need to say
self.cview.delegate = self;
self.cview.dataSource = self;
* AKA control-click
I am using core plot 1.0 in my iphone app. All works fine, graphs are drawing perfectly, But I am facing a weird problem that All the controls on graph page(CPTPGraphHostingView) are mirrored.
Ie: On that xib file, I set the class in class Identity of top UIView to CPTPGraphHostingView, then problem arises.
Please help me how to solve this. The controls appear correctly in interface builder, but when I run the project all gets messed up.
Even I have tried to add background Image programatically, but that also is mirrored.
References for this answer:
Core plot google group
Related SO question
I came to know that the whole CPTPGraphHostingView is inverted upside down to support both Mac OS and iOS. This is by design and is not a bug.
So the solution from the given links is that:
Add two Views to your xib file, one of type CPTPGraphHostingView(for adding graph) and the other of type UIView(for adding any other ui controls, backgrounds etc). You can modify the type of View by modifying Class field under the heading Class Identity in View Identity tab of File's Owner window.
Now add the graph to CPTPGraphHostingView and add other ui controls to the other view(UIView)
End of story
UPDATE:
If you add CPTPGraphHostinView to interface, no other components will be visible, for that you'll have to set theme, and fill of CPTXYGraph to nil. Ie add following lines after you initialize your CPTXYGraph:
CPTTheme *theme = nil;
[barChart applyTheme:theme]; // barChart is my CPTXYGraph
barChart.fill = nil;
barChart.plotAreaFrame.fill = nil;
NOTE:: Add CPTPGraphHostingView such that it is child of top level UIView, and other components are in top level UIView, and CPTPGraphHostingView is above all other components.
Try self.view = (CPTPGraphHostingView *)view
I have defined a UIView in the header file named rectangle0
I got a question in regards to IB vs coding a view. Please see the following code example:
rectangle0.frame = CGRectMake(0.0, 70.0, 320.0, 190.0);
Now I can re-create the look of the view easy enough in IB except for the coordinates which are greyed out.
So by calling this code in an IBAction after designing the UIView in IB I can display in the app.
[self.view addSubview:rectangle0];
Now the last line of code will call this view to appear at the set coordinates if I code it - but if I build in interface builder I can make it look exactly the same, but it appears from Y coordinate 20 (just under the status bar) and I can't set the coordinate upon calling it - is there a way to do this??
The UIView is being build outside of the ViewController and then linked to it in the connections inspector.
cheers Jeff
I have added an image to show what screen I am using - as you can see the x and y coordinates are greyed out, it would be great if I can set those to something else.
A view inside the NIB is just an object like any other. It is made to be reusable and I believe that is the key point that resulted in the coordinates being greyed out.
Greying out the position makes the developer worry about where is the view going to be placed. I say that because the position is pretty dependent on the container that your view object is going to be added to.
Although it is just my personal opinion and I am looking forward to hearing if there is indeed a way to do that.
You (effectively) said the view is managed by a view controller. Before you can resize the view, you need to change the Size setting in the view controller's Simulated Metrics to "Freeform". (It is probably set to "None" by default.)
just a quick question here.
How can I add an image to my UIViewController. Currently, my view controller has a couple labels and a couple buttons, but I have a file line.jpg that I'd like to add to this view controller as well. And I'd like to add it at a specific location (namely, at the center of the screen). How could I (meaning, what is the code?) initialize some object (that encapsulates my image) and then add it to the screen?
Thanks!
Use UIImageView for that.
http://developer.apple.com/iphone/library/documentation/uikit/reference/UIImageView_Class/Reference/Reference.html
I'm pretty sure I saw an example where the graph wasn't filling the whole iPhone screen, but I can't get that to happen in my app, nor in the Core-Plot Test app from Switch On The Code.
I've added a subview to the original CPLayerHostingView in the sample, then changed the classes – original back to UIView, new subview to CPLayerHostingView, and I've reconnected the File's owner's view outlet to the new subview.
When I create a graph with:
graph = [[CPXYGraph alloc] initWithFrame: theSubviewOutlet.bounds];
… and step through the first stages of building up the layers the bounds are accurate (i.e. the same as in the .xib)
however, when all the initialization is done, and the graph shows up, it fills the whole superview.
Am I missing something obvious?
These types of questions are better asked on the core plot mailing list, because we may miss them over here.
There is nothing special about a CPLayerHostingView. You should be able to add it as a subview to your UIView, and resize it as you wish. You should also be able to set springs and struts in interface builder, or via code.
Perhaps you have your parent UIView setup to resize subviews in some way? In any case, Core Plot should not be doing anything to modify the host view frame.