CPTGraphHostingView in a UIView - iphone

I was really impressed, and really grateful about the answers I recived last time I asked here.
I have this problem with Core Plot.
I want to have a CPTGraphHostingView inside my UIView so I can have things like labels and scroll views below it.
I am using XCode 3.2 by the way.
How do I do this programmatically? Or with the Interface builder if possible.(I need the instructions to be detailed as im I bit new to this sort of thing)
Thanks for your support.

If you want to add a core plot graph to a UIView you have to add a CPTGraphHostingView as a subview to the UIView. In the example below, hostingView is a UIView and graphObject is a CPTXYGraph.
CPTGraphHostingView *graphHostingView = [[CPTGraphHostingView alloc] initWithFrame:hostingView.bounds];
[hostingView addSubview:graphHostingView];
graphHostingView.hostedGraph = graphObject;

Simple adding CPTGraphHostingView as a subView of UIView [programatically] didn't work for me.
I have searched through many threads and at the end I tried the simplest way to do this - I have created new UIView in interface builder and in this view I have created another UIView and change it to CPTGraphHostingView. Now I can simply create chart [like in tutorials] and link its main UIView anywhere I want.
I don't know why this didn't work programatically but it works from Interface Builder.
I use Xcode 4.2 and Core plot 1.0

Related

How to show Pie Chart , Bar Chart and Line graph in single view in ios

I want to show Graph Charts in iPad ,which is some thing like below image.Please suggest me some idea how to do this ?
I have taken reference from the tutorial How To Draw Graphs with Core Plot, Part 1 & 2.
here i can see it has used different view controller to perform all three graph.I want it in single view controller only.
Create new Project of SingleView Application, drag and drop whats necessary to use core plot also drag these three view controllers in your project.
You got Three View controllers
1. CPDPieChartViewController
2. CPDBarGraphViewController
3. CPDScatterPlotViewConntroller
make them subclass of of UIView like in .h of them instead of <UIViewController> use <UIView>
1. CPDPieChartView
2. CPDBarGraphView
3. CPDScatterPlotView
and inside their implementation file remove code related to UIViewController like method -(void)viewDidAppear and unwanted synthesized objects and add initwithframe method instead.
now inside ur projects main viewcontroller import these three views classes.
-(void)viewDidLoad
{
CPDPieChartView *CPDPieChartViewObj=[[CPDPieChartView alloc]initWithFrame:CGRectmake(give proper frame)];
[CPDPieChartViewObj initPlot];
CPDBarGraphView *CPDBarGraphViewObj=[[CPDBarGraphView alloc]initWithFrame:CGRectmake(give proper frame)];
[CPDBarGraphViewObj initPlot];
CPDScatterPlotView *CPDScatterPlotViewObj=[[CPDScatterPlotView alloc]initWithFrame:CGRectmake(give proper frame)];
[CPDScatterPlotViewObj initPlot];
[self.view addSubview:CPDPieChartViewObj];
[self.view addSubview:CPDBarGraphViewObj];
[self.view addSubview:CPDScatterPlotViewObj];
}
Here is an example :
CompositePlot in CorePlotGallary

Objective C - addobserver for UIView adding subviews?

Is there an easy way for listening for when a child or subview has been added to a UIView?
I've gone through the addobserver options and haven't found an obvious option anyway. There may be another option that would be affected though when content is added to a view or am I wrong in saying that? i.e. content width or height, positions, etc.?
Edit
This is accomplished easily using the advice of #Alkimake below (TextHolderClass).
I created a custom UIView subclass and set the UIView's class in Interface Builder to be equal to TextHolderClass
Thanks for your help, I know it should have been obvious :)
UIView methods may help you:
- (void)willMoveToSuperview:(UIView *)newSuperview
UIView has 2 methods to call after subview interactions. Simply create your custom UIView class and implement these methods which is pretty for you. And use your own CustomView
- (void)didAddSubview:(UIView *)subview;
- (void)willRemoveSubview:(UIView *)subview;

Fixed Background for iPhone app using Storyboard

Can't seem to find a way to fix a graphic - a light graphic that would remain static as the user navigates from scene to scene. Have been combing forums for a few days, but most answers point to MainWindow.xib, which isn't generated for a storyboard project. Would appreciate any advice.
Here’s what I was able to cobble together thanks to advice from #Max. Like I said, very new to this, so if this code needs tuning please leave a comment so I don’t lead others astray.
Add the image to the app’s main window in the AppDelegate’s didFinishLaunchingWithOptions method :
UIImageView *myGraphic = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"myGraphic.png"]];
[self.window.rootViewController.view addSubview: myGraphic];
[self.window.rootViewController.view sendSubviewToBack: myGraphic];
Then, to make your views transparent so the background shows through - in your viewController class/es, add to viewDidLoad method:
self.view.backgroundColor = [UIColor clearColor];
(And note if you try to decrease the transparency through the alpha property for the view via the Attributes Inspector, it will make everything transparent on that view -buttons, etc - that’s why it needs to be done programmatically.)
Sure, it’s not thoroughly tested. But for now it’s working and it’s a thing of beauty. Thanks all.
You can try to manually add UIImageView to your window and then set 0 background transparency
for all other views.
One way to do it -- it may not be the best -- can be that you subclass a UIView, and set the UIView instance in all of your viewControllers in the storyboard an instance of your cutomized UIView class, which contains your graphic as a background.
If you're going to tackle this programmatically, within each view controller, set:
[[self view] setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"background.png"]]];
in viewDidLoad
I'm sure some tweaking would allow you to apply this principle throughout the program from the app delegate, or by using a singleton.
Using this solution, though, you're still going to have to make some method call within each view controller where you want this style applied.

Displaying CAEAGLLayer in a UIView or CALayer

Rather new to trying to get OpenGL ES working on the iPhone, but I've created a working demo from an OpenGL template and wanted to add it to another App which is a standard UIViewController App. After searching around it seems that I can't addSubview a CAEAGLLayer to a CALayer aka UIView. How would I go about doing this? Or am I completely wrong in what I'm doing.
Cheers for any help
Simply use a UIView and add:
+ (Class)layerClass {
return [CAEAGLLayer class];
}
That UIView is now a CAEAGLLayer, so you can add that view as a subview of another UIView like normal.
What I actually had to do was change in the EAGLView -initWithCoder to -initWithFrame and make the appropriate changes to the method to handle the frame. Once I did that and initialised the view with initWithFrame it worked.
I believe you are looking for CALayer's insertSublayer methods or the addSublayer method.

Core-Plot graph in a UIViewController

im trying to put a Coreplot graph in a UIView.
Some questions, should i do it in XIB? or should i do it programmically ?
If so how should i write the codes? etc.
I actually have two Classes. one called GraphView which is supposed to hold the Coreplot graph.
Another called CorePlotViewController.
Thx for looking guys.
hmm i guess i must be some real newb to ask even this type of question :/
but i guess i solved it .
CorePlotViewController *aCorePlotViewController = [[CorePlotViewController alloc] initWithNibName:#"CorePlotViewController" bundle:nil];
[self.view addSubview :aCorePlotViewController.view];