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).
Related
I have a problem of the implementation of UITableViewCell's separator.
As you can see from the screenshot, there is a white gap visible before the separator, I think that is because I set the bg colour of the cell as light grey and also I put the inset of the separator as 53.
My first attempt was instead of using the separator, I was trying to draw the lines at the end of the cell by my self. But since on selection of the row the content of the row get updated, and there is a lot of issue regarding the calculation of the height of the cell.
So basically it is really hard for me to draw the line pixel precise at the end of the cell.
This left me the option to access the cell's separator's view, which currently not aware of any easy way, and fill the gap with my default background colour of the table.
My question is, how can I access the separator view
Or
Do I have any other alternatives to implement what I want?
Thank you very much.
UITableView doesn't provide APIs to access or modify the cells separator view directly. However, it has methods to change it's color, style, etc. Most of the times, though, the only solution for a custom separator is to draw it yourself, or better, to set the cell's backgroundView property to a simple view with a line subview or layer in it (a subview, although has some overhead, gives you the flexibility of autoresizing automatically using autoresizing masks or auto layout).
e.g.
UIView *backgroundView = [[UIView alloc] initWithFrame:cell.bounds];
UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(backgroundView.bounds) - 1, CGRectGetWidth(backgroundView.bounds), 1.0f];
[lineView setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin)];
[backgroundView addSubview:lineView];
cell.backgroundView = backgroundView;
Use this workaround:
Put UIImageView at bottom edge of cell and you can set image as per your requirement
STEP 1: Set divider as per image
STEP 2: Set Separator style to none
Since iOS 7 you can use this
cell.separatorInset = UIEdgeInsetsZero;
I have a custom UICollectionViewCell, I have few views in its contentView.
I have an UIImageView with image (1 pixel colored) and I use it to fill my view.
I also cut the corners like this -
self.myBackground.layer.cornerRadius = 8.0;
self.myBackground.layer.masksToBounds = YES;
Color of my view and all collectionViewCells and their contentViews is [UIColor whiteColor]
But I am getting weird grey line below it. I am not setting it anywhere and I don't need it.
How can I remove it?
I have found the answer, it is separator. After setting separator view to nil it disappeared.
Upon changing the highlight color of the cell when selected, the box drawn around the top and bottom of the table no longer clips within the table's borders.
I have tried clipsToBounds with both tableView and the cells, but with no luck.
Any solutions?
Thanks!
image of the problem >
I have a idea how to make the effect you need work, may not be the best way but you can have a try.
first check if the cell is the last cell; if so:
UIBezierPath *lastCellMask;
lastCellMask = [UIBezierPath bezierPathWithRoundedRect:cell.bounds byRoundingCorners:(UIRectCornerBottomLeft | UIRectCornerBottomRight) cornerRadii:CGSizeMake(3.0, 3.0)];
CAShapeLayer *cellMaskLayer = [[CAShapeLayer alloc] init];
cellMaskLayer.frame = cell.bounds;
cellMaskLayer.path = lastCellMask.CGPath;
cell.layer.mask = cellMaskLayer;
and do the reverse for the first cell
This works for me, check if this can help u
looking at the image, try
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
The problem is that you are using grouped style for your table view. The grouped table view doesn't have the margins that you are seeing in the UI, and using clipToBounds won't help because the cells bounds are exactly the ones you are seeing when you are selecting the cell. What you could do is use the cornerRadius layer property for your cell (only the first and last cell in the section) in order to round the corners and create the desired result.
How can I style the borders of my UITableView? I would like them rounded and a little bit beveled.
In the screenshot you can see the table view Tags and the UITextField Format (with the correct style).
UITableView background:
- (void)viewDidLoad
{
[super viewDidLoad];
[tagsTableView setBackgroundColor:[UIColor clearColor]];
}
thanks
#Patrick if you want corners of UITableView rounded as UITextField then you can use group table view by changing style of UITableView Plain to Group.
Either use the UITableViewStyleGrouped or, if you need to customize a bit more, you can use each the cell's CALayer (or their contentView's CALayer?) to add rounded corners:
view.layer.borderWidth = 1.f;
view.layer.borderColor = [UIColor grayColor].CGColor;
view.layer.cornerRadius = 10.f;
...
Of course, don't forget to add QuartzCore.framework to your project if you choose this solution.
Note that you can apply the exact same principle for your UITextField to add rounded corners to it (instead of the solution you have used for your UITextField already, whatever it is)
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.