Coreplot annotation clipped - core-plot

My annotations are clipped as one can see on the picture:
I've set up the custom paddings and set the masksToBorder flag:
graph.plotAreaFrame.masksToBorder = NO;
What should I do, not to clip the annotation or how can I get the frame of annotation to move it appropriately?
Thanks.

Add the annotation to the graph instead of the plot. The plots and any sublayers like annotations are clipped to the plot area.

Related

Corner radius and shadow on a view suddenly not working

Multiple placed in my app, I have views with both shadows and corner radii. I tried adding a new view, and suddenly the code I was reusing doesn't work anymore. I can only set a corner radius or a shadow, depending on what I put for masksToBounds. Here's the code I use for both the faulty view and my other views:
itemCountLabel.layer.masksToBounds = false
itemCountLabel.layer.cornerRadius = itemCountLabelSize / 2.0
itemCountLabel.layer.shadowColor = UIColor.black.cgColor
itemCountLabel.layer.shadowOpacity = 0.25
itemCountLabel.layer.shadowRadius = 5
itemCountLabel.layer.shadowOffset = CGSize(width: 4, height: 4)
contentView.addSubview(itemCountLabel)
It's not possible to implement as you've tried. Shadow is always applied outside the bounds of the UIView and the cornerRadius will not be visible without masking the bounds of UIView. So, better add a UIView behind the UILabel and to reuse the function write an extension of UIView that returns a UIView contains the view you want to apply the shadow.
Here you need to use two different views one to round the corners and the other behind it to show the shadow, As both these properties don’t work together because of the Mask To Bounds and Clip To Bounds features. As corner radius needs to clip the edges which might can contain the shadow.
So to have both of the things use a shadow view behind the view which you want to have rounded corners.

How can I access the layer so I can flip it?

I implemented corePlot into my xcode project. I'm trying to flip the legend of the graph.
Here is the code:
CPTGraph *graph = self.hostView.hostedGraph;
CPTLegend *theLegend = [CPTLegend legendWithGraph:graph];
graph.legend = theLegend;
This is what I tried:
theLegend.sublayerTransform = CATransform3DMakeScale( CPTFloat(1.0), CPTFloat(-1.0), CPTFloat(1.0) );
That didn't do anything. So I tryied replacing theLegend.sublayerTransform with theLegend.transform and that didn't do anything either. How can I access the legend layer so I can flip it?
Update
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:2 inSection:0]];
[cell.layer addSublayer:graph.legend];
The short answer to your question is that you need to flip the layer of the view which contains your legend layer.
[[viewWithLegendSublayer layer] setTransform:CATransform3DMakeScale(1.0f, -1.0f, 1.0f)];
This will do the trick, but if you add any other subviews to that view, they'll be upside down.
N.B.: There may be better ways to address this issue, which work within the intended design of the API (e.g., CPTLegend expects to be a sublayer of a CPTGraph).
Here's the approach we discussed in chat. Since you want to put your legend into a UITableView, why not just skip the CPTLegend completely, and use several table view cells as your legend items? You'd probably have to set up your own colors, but once that's done, you can just create standard table view cells, and set their text using the titles from your legend. Then create a small square UIView (you can round its layer's corners for visual appeal), set its background color to match, and set it as your cell's accessoryView (or do the same with a UIImageView and the cell's imageView).

Why adding sublayer overlaps subviews?

For example I have a view with UILabel as subview. If at some time I add sublayer with some background color to this view's layer, then this label will disappear. Can someone explain this behavior?
When you add your UILabel as a subview of your view it is adding your UILabel's layer as a sublayer of your view's layer. So when you add another sublayer to your view's layer it will be on top of your UILabel's layer.
You can either add your background layer before you add the UILabel or do:
Swift
view.layer.insertSublayer(backgroundLayer, below: yourLabel.layer)
Objective C
[view.layer insertSublayer:backgroundLayer below:yourLabel.layer]
and it should put the background behind the label.
What worked for me was to insert the layer at a specific index like this:
view.layer.insertSublayer(backgroundLayer, at: 0)

Move the coordinates of a map, by the size of a frame

I have situation where I have an MKMapView that takes up the full view of my xib file. Over the top of this (at the left hand side of the xib) I have a tableView.
I'm adding a number of annotations to my map, which is fine, and then the map is centered so these are all in view. The problem I have is that the map is centered based on the size of the whole view. What I would like to do is center the region in the visible part of the map - so basically add an offset that is the size of the tableView's frame. The reason the mapView takes up the whole size of the view is that the tableView can be dismissed so the user views the map full screen. The tableView doesn't start at 0,0 and take up the whole height so you can see the map behind it (which is why I don't just make the map's frame larger when dismissing the table view).
I've been trying to use
[mapView convertPoint:point toCoordinateFromView:mapView]
and then try and work out the difference between my currently selected region but this doesn't seem to be working.
Any help appreciated
CGPoint offset = CGPointMake(tableView.frame.size.width,self.tableView.frame.size.height);
CLLocationCoordinate2D movedLocation =[self.mapView convertPoint:offset toCoordinateFromView:self.mapView];
// Not sure what I should do here
// hardCodedLocation.latitude = hardCodedLocation.latitude - (hardCodedLocation.latitude - movedLocation.latitude);
CLLocationDistance zoom = 900000;
[self.mapView setRegion:MKCoordinateRegionMakeWithDistance(hardCodedLocation, zoom, zoom) animated:YES ];

Changing corner radius of the cells insie a grouped UITableView

After hours of googling I am wondering if it is possible to change the corner radius of a grouped UITableView.
I tried
hoursTable.layer.cornerRadius = 5.0;
but nothing seems to change.
Make sure clip sub views of table view alon with ur code
hoursTable.layer.cornerRadius = 5.0;
by code [hoursTable setClipsToBounds:YES];
hoursTable.layer.cornerRadius = 5.0;
[hoursTable setClipsToBounds:YES];
Are you sure use <QuartzCore/QuartzCore.h> framework in your app
your method (hoursTable.layer.cornerRadius = 5.0; ) only give you rounded corners without having to add your tableview to a superView or clipping it.
also use
[hoursTable setClipsToBounds:YES];
this is work only ios 3....if you work ios 4 or ios 5x then see SO answer
I would recommend to
1) make a subclass of UITableViewCell and set the background color clear
2) make a subclass of UITableView and set the separator color clear
3) use this cells in the tableview
now here is an important method t be implemented in UITableViewCell subclass
in
- (void)drawRect:(CGRect)rect method try to make a bezier path accordingly to fill and stroke path as far your corner radius and background color...
the content rect you can get by self.contentView.frame in what you have to draw your new bezier path.

Resources