Is it possible to create custom UICollectionViewCell in circular shape?
Why I need this?
I am trying to create custom color picker. I want to put some default color in each CollectionViewCell. These color are dynamic. That means I will be changing colors filled in cells.
What I have tried
1. I kept circle shaped png images in cells. But will have to change images if i want to change colors.
2. I kept circle shaped image transparent inside (in circle area). Then I changed Background color of cell. Failed as I will be changing Background image of collectionView.
3. I kept circle shaped image completely transparent except the boundary. Then I changed Background color of cell. Failed...
Help me..
Don't use a circular image. You can make any square view circular by adjusting the layer's cornerRadius property to half of the edge. So, if your cell is 100x100, set its corner radius to 50.
You can do this in your collection view data source (cellForItem...) or in the applyLayoutAttributes: method of your cell subclass.
For more flexibility use a CAShapeLayer added to the background view of the cell and change its fill colour. This way the coloured area can be any shape you like, and you can add shadow effects and animations to it.
this worked for me
if you need cell to be in circle remove thumbimageviewcell it the label which i m using and add your image view name
cell.thumbimageviewcell.layer.cornerRadius = cell.thumbimageviewcell.frame.size.width/2;
cell.thumbimageviewcell.layer.borderWidth = 2.0f;
cell.thumbimageviewcell.layer.borderColor = [UIColor whiteColor].CGColor;
cell.thumbimageviewcell.layer.masksToBounds = YES;
Related
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 want to set background color for x-axis and y-axis label. How to set the background color of CPTAxisLabel.
Create custom axis labels. The CPTTextLayer class commonly used to create text labels is a subclass of CPTBorderedLayer so you can give it a border and/or background fill, too. Use the layer padding to adjust the margin space around the text inside the border.
Either use the CPTAxisLabelingPolicyNone labeling policy or use an axis delegate and implement the -axis:shouldUpdateAxisLabelsAtLocations: method. In the delegate method, create labels for each tick location and return NO to tell the axis that the delegate took care of updating the labels.
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.
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.