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.
Related
The Apple Documentation has shown me how to place constraints between objects that are apart from each other in the view, like here. However, what if you have a display element that is contained inside of another, as shown below:
Is it possible to set constraints that will "trap" the gray square within the red square?
Make sure you have set the necessary constraints for the red box and place the gray box inside the red box.
Red box constraints:
In my case i want the red box in center of the screen with fixed width and height.
Gray box constraints:
Trapped inside the red box with the distance of 64 all side.
You can make the gray square a subview of the red square, then constrain it to the red square, which will be its superview.
The specific constraints would depend on how you wanted the gray square to size itself in relation to the red square.
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 a custom table view and want it to look like this...
(source: pulsewraps.co.uk)
The image is loaded via async and the two lines come from two different arrays. I can get all the data in fine I just don't know how to lay it out.
I want:
the black gradient to overlay the image
the two lines of text to be within the black gradient box
the image to fill the table row to cover it and keep it's aspect ratio
the black gradient box to be pinned/constrained to the bottom of the image so that is either line of text is larger than two lines it covers more of the image and doesn't drop below it.
I fill the table data in a loop according to the number of records in my array which is populated by json.
I have managed to do the layout in android but can't get my head around ios.
Any help much appreciated.
If you're using autolayout, you'll want to constrain the labels to the bottom and to each other. Then put the gradient view behind the labels and constrain the top of the gradient to the top of the top label.
You'll have to handle drawing the gradient yourself, either use an image in an image view and set it to scale to fill, or subclass UIView and add a little bit of code to drawRect: The first is probably easier, the second will produce a more uniform gradient if it has to be scaled.
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
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;