Custom Card View design in Table View Cell in XCode - ios

Is it possible to create interaction enabled sidebar solely in the utility area of the storyboard, or does it need any custom UI class?
Related question: How to give shadow like card in iOS

Try this
Create two UIView like this
- Set corner radius to the backView
- Set corner radius to the frontView, only for rightBottom and rightTop portions by using below method
extension UIView {
func roundCorners(_ corners: UIRectCorner, radius: CGFloat) {
let path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
let mask = CAShapeLayer()
mask.path = path.cgPath
self.layer.mask = mask
}
}
Refer my code
https://github.com/leninsmannath/CardViewSample.git

Related

UIHostingController in share extension does not resize it's root view

I used swiftUI in share extension, using UIHostingController. When user changes device orientation when share extension is open, UIHostingController rootView does not change it's width
So the actual problem was this function
func roundCorners(corners: UIRectCorner, radius: CGFloat) {
let path = UIBezierPath(roundedRect: bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
let mask = CAShapeLayer()
mask.path = path.cgPath
layer.mask = mask
}
It caused the container it was applied to never change it's width and height, which caused the effect, consequently making the container look horrible when changing device orientation from portrait to landspace

Bezierpath button width issue

func roundCorners(_ corners: UIRectCorner, radius: CGFloat) {
let path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
let mask = CAShapeLayer()
mask.path = path.cgPath
self.layer.mask = mask
}
I am using this function to give corner radius from particular side for UIButton. I am calling this function into UITableViewCell but I am having issue like I gave constraint to button like its width is changing as per device width change for exa if device is iPhone 5 then its width is 159.5 acoordingly half of screen width. but it is not changing and button is cutting from its width.
I am calling this function in TableviewCell
override func layoutSubviews() {
super.layoutSubviews()
self.btnWithdraw.roundCorners([.bottomRight], radius: 4.0)
self.btnAddFund.roundCorners([.bottomLeft], radius: 4.0)
}
But here issue is like It is taking original frame as per given in storyboard viewcontroller and button is not taking width as per constraints.
Any help would appreciated.
Thank you
Perhaps the problem is that you are assuming that layoutSubviews will be called on the cell under all circumstances where the button is being laid out afresh. That might not be true.
To avoid that assumption, implement your entire masking in the button itself, along these lines:
class MyButton : UIButton {
var whatCorners : UIRectCorner = [.bottomRight]
var whatRadius : CGFloat = 4.0
func roundCorners(_ corners: UIRectCorner, radius: CGFloat) {
let path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
let mask = CAShapeLayer()
mask.path = path.cgPath
self.layer.mask = mask
}
override func layoutSubviews() {
super.layoutSubviews()
self.roundCorners(self.whatCorners, radius: self.whatRadius)
}
}
That way, you can give each button the desired values for whatCorners and whatRadius and the button will round itself.

Only top left corner is rounded instead of topLeft and bottomLeft

I am trying to make UIView topLeft and bottomLeft corners rounded however for some reason only topLeft has border radius. What can cause this?
This is What I am doing:
I have Extension:
extension UIView {
func roundCorners(_ corners: UIRectCorner, radius: CGFloat) {
let path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
let mask = CAShapeLayer()
mask.path = path.cgPath
self.layer.mask = mask
}
}
And I apply it to view like this:
myView.roundCorners([.topLeft, .bottomLeft], radius: 10.0)
I am using it inside cell and I am also using auto-layout.
At the moment it looks like this(green is the view I am talking about) but I want the bottomLeft to have corner radius also:
The problem is your timing. Your extension relies on self.bounds. But if you call this extension too early, such as viewDidLoad, those bounds have not yet been determined. Your view is sized by auto layout; that means you don't have bounds until your view's layoutSubviews or your view controller's viewDidLayoutSubviews has been called.

How to round corners on specific sides of UIImages?

I currently have three images next to each other. I combined them into a stack view and would like them to have rounded corners like so:
Instead, after setting the corner radius to each image to 5 I have this:
So my question is how I can make the second picture look like the first one? Keep in mind all three stars are in one stack view.
You can pick corners you want to round with this method for UIView:
extension UIView {
func roundCorners(corners: UIRectCorner, radius: CGFloat) {
let mask = CAShapeLayer()
mask.frame = bounds
mask.path = UIBezierPath(roundedRect: bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height:radius)).cgPath
self.layer.mask = mask
}
}
Usage:
star1.roundCorners(corners: [.topLeft, .bottomLeft], radius: 10)
star3.roundCorners(corners: [.topRight, .bottomRight], radius: 10)
Try out this solution
let path2 = UIBezierPath(roundedRect:view1.bounds, byRoundingCorners:[.TopLeft, .BottomLeft, .TopRight, .BottomRight], cornerRadii: CGSizeMake(20, 20))
let maskLayer2 = CAShapeLayer()
maskLayer2.path = path2.CGPath
view2.layer.mask = maskLayer2
Hope this helps you out.
I put the images behind a view and set the background color to my liking. Then I got rid of any background color for my images. After that, I just rounded the corners of my view.

Applying corner radius to top part of UIView using AutoLayout

I extended UIView to add a round() method to apply corner radius to specific corners:
extension UIView {
func round(corners: UIRectCorner, radius: CGFloat) -> CAShapeLayer {
let path = UIBezierPath(roundedRect: bounds, byRoundingCorners: corners, cornerRadii: CGSizeMake(radius, radius))
let mask = CAShapeLayer()
mask.path = path.CGPath
self.layer.mask = mask
return mask
}
}
In one view controller I have the following hierarchy:
StackView
UIView
Constraint are set to both for top, leading, trailing as 0.
My issue is when I run (only) 5.5 inch screen, the UIView is not stretched all the way as it should be when I apply the corner radius to it:
override func viewDidLayoutSubviews() {
self.greenview.round([.TopLeft, .TopRight], radius: CGFloat(10))
}
If I remove this line it works correctly. Am I not calling this method in the right place ?
Here is a screen shot of the problem:
Try putting it in 'layoutSubviews' after calling the super method. It's more appropriate for bounds-dependent UI changes.

Resources