What I want is to draw a small rectangle inside an CPTAxisLabel to display a colour, what I have all ready tried is to draw a rectangle in a layer and add it as sublayer, but it stretches the small sublayer all over the label and the text isn`t visible anymore, I also tried to make an CPTLegend and add it to the label but I did not found any method to position it in the right side of the label, it just sits in the center, I tried changing the legends position, frame, bounds, padding and nothing. Does anyone know a better way of adding a rectangle shape in an CPTAxisLabel and also keep the text in the label ?
I assume you're using a CPTTextLayer for the label's contentLayer. Use an image fill on the text layer that contains your rectangle. Make it a stretchable image and set the stretchable area to the right of the rectangle. Set the paddingLeft on the text layer to leave room for the rectangle to the left of the label text.
After some long researches I found issue 266 in core-plot and it seems to be the problem I have with positioning a sublayer inside a CPTAxisLabel... I will keep waiting for a fix, but I don`t know if it will be solved soon.
Related
I have a custom renderer that is attempting to create a white square with rounded corners containing a single font image at the top and text under it. I have been able to do something similar with the ImageRenderer, but am looking to support font images with this version.
In LayoutSubviews I set the frame to the requested size, set the corner radius, and set Clip to Bounds to true. At theis point in time Bounds are still (0,0,0,0) but setting there here has no effect.
Control.Layer.CornerRadius = 10;
Control.Layer.MasksToBounds = false;
Control.Layer.Frame = new CGRect(0, 0, element.WidthRequest, element.HeightRequest);
Control.Layer.BackgroundColor = HelperUtilities.GetColor(element.Item.BackgroundColor, Color.White).ToCGColor();
Control.ClipsToBounds = true;
I have also checked the value of Bounds in Draw both before and after calling the base code, and they are as expected - (0,0,126,126). Yet when the screen is drawn the white background is too short - it's a rectangle the proper width, but the height of the font icon, not the given height. I can change the font icon's placement within the square area by changing the VerticalTextAlignment from Start to End which moves it from the top to the bottom of the square.
Next, I add the UIView for the additional text and anchor it to the BottomAnchor of the Control, it anchors to the bottom of the white area rather than the bottom of the square which tells me the Control's Bounds have been changed so the height is no longer 126 but is the actual height of the Font and FontSize being used.
What do I need to set and/or override to get the control to have the given height instead of the font height?
This is what is displayed:
This is what I want it to display:
I was able to solve this by adding padding to the bottom of the object that inherits from Label in my forms app to account for the expanded area. I only add the padding if iOS as Android didn't have the issue. This was a much easier solution than adding it into the custom renderer.
I want to color my UILabel border. But I want to do it part by part,, not the whole border. This is the thing that I want to do.
According to the percentage, I want to color my UILabel border.
How can I achieve this?
Create a custom subclass of UILabel.
In the initWithCoder method of your custom label, add 2 CAShapeLayer objects to your label.
Set one to draw in your dark blue and the other to draw in your light blue.
Install a CGPath in each one which is a full circle.
Manipulate the strokeStart and strokeEnd of each shape layer to draw the desired parts of each circle.
I have UIView's alpha set at .5, and its border color alpha is .5 as well, they are a similar shade of gray, but it shows up as a thicker gray on the outside. I am guessing this is because the two colors are being mixed together. Is there a way that instead of just adding a border on top, I can add a border that will displace the pixels underneath it?
You're correct, the only way around this would be to place your 0.5 alpha view inside a container view and inset it slightly and add the border to the container.
I decided to post this as an answer rather than a comment:
An alternate approach would be to subclass UIView to add a CALayer that is one pixel bigger than it's view's layer, and has a borderColor and borderWidth as desired. For a one-off you could add code to your view controller that would add a layer to the view through code rather than subclassing UIView. I doubt if a single pixel increase in width would necessitate adjusting the corner radius, unless the view is VERY small. – Duncan C 37 secs ago edit
I'm trying to make a semi-transparent border around a UIView. The idea is to show a picture but have the border cover the edge of the picture yet still allow you to see what is behind the border. I want the border to have different border-widths for the different sides. On the top i would like to have a border of 80 pts, on the bottom I want a border of 60 pts, and on the sides I want a border of 10 pts. I know that using the code :
UIView.layer.borderColor = [UIColor blueColor].CGcolor;
UIView.layer.borderWidth = 10;
will give you a uniform border of width 10 all around the inside of the UIView, but how do I set different border widths for different sides of the UIView?
To my knowledge, its not possible to get what you want just by using the properties of a UIView or its backing layer. You may have to use another UIView(s) which contain the specific border you want (maybe as a custom graphic) and overlay it on top of your image.
There are some work around to do this.
1. Add an image view at bottom of every thing else, or index 0. And add image with border. Add rest of views top of that by leaving boarder edges. Image can be on the top but than only Boarders should be solid, rest of image should be transparent.
2. Add your view in a view and add boarder on the super view. your view frame should be in that boarder.
I'm learning my way through UIBezierPaths by creating a table from scratch, and having individual cells filled with different colours.
This is a custom object I'm building which is contained in a subclassed UIView.
At the moment, I'm constructing this in this order:
'Cell' fill colours
Column lines
Row lines
Outer box (rounded rect)
As the picture suggests, I'm having trouble getting rid of the sharp corner of the cell fill outside the orange rounded rectangle.
Can anyone point me in the right direction to get rid of these?
Cheers! :)
At the beginning of your drawing code you should add the outer rounded rect path to the clipping path using its addClip method. That way nothing will get drawn that is outside this path.