kazimunshimun / RoundedCornerView

iOS Rounded Corner UIView which can be rounded in any side
5 stars 4 forks source link

Not worked for me . I have made some changes and it's working fine now. #1

Open rebink opened 5 years ago

rebink commented 5 years ago

// // RoundedCornerView.swift // DSC // // Created by Mohamed Rebin on 26/08/19. // Copyright © 2019 Rebin. All rights reserved. //

import UIKit

@IBDesignable class RoundedCornerView: UIView {

var cornerRadiusValue : CGFloat = 0
var corners : UIRectCorner = []

@IBInspectable public var cornerRadiusForSelectedSide : CGFloat {
    get {
        return cornerRadiusValue
    }
    set {
        cornerRadiusValue = newValue
    }
}

override func draw(_ rect: CGRect) {
    super.draw(rect)
    if topLeft {
        corners.insert(.topLeft)
    }
    if topRight {
        corners.insert(.topRight)
    }
    if bottomLeft {
        corners.insert(.bottomLeft)
    }
    if bottomRight {
        corners.insert(.bottomRight)
    }
    self.roundCorners(corners: corners, radius: cornerRadiusForSelectedSide)
}

@IBInspectable public var topLeft : Bool {
    get {
        return corners.contains(.topLeft)
    }
    set {
        setCorner(newValue: newValue, for: .topLeft)
    }
}

@IBInspectable public var topRight : Bool {
    get {
        return corners.contains(.topRight)
    }
    set {
        setCorner(newValue: newValue, for: .topRight)
    }
}

@IBInspectable public var bottomLeft : Bool {
    get {
        return corners.contains(.bottomLeft)
    }
    set {
        setCorner(newValue: newValue, for: .bottomLeft)
    }
}

@IBInspectable public var bottomRight : Bool {
    get {
        return corners.contains(.bottomRight)
    }
    set {
        setCorner(newValue: newValue, for: .bottomRight)
    }
}

func setCorner(newValue: Bool, for corner: UIRectCorner) {
    if newValue {
        addRectCorner(corner: corner)
    } else {
        removeRectCorner(corner: corner)
    }
}

func addRectCorner(corner: UIRectCorner) {
    corners.insert(corner)
}

func removeRectCorner(corner: UIRectCorner) {
    if corners.contains(corner) {
        corners.remove(corner)
    }
}

// // func updateCorners() { // self.roundCorners(corners: corners, radius: cornerRadiusValue) // }

}

kazimunshimun commented 5 years ago

can you please share for which circumstance code did not work?

pratik76 commented 4 years ago

it is not working with swift 5 can you please update this code

Anugrahchaturvedi commented 1 year ago

// // RoundedCornerView.swift // DSC // // Created by Mohamed Rebin on 26/08/19. // Copyright © 2019 Rebin. All rights reserved. //

import UIKit

@IBDesignable class RoundedCornerView: UIView {

var cornerRadiusValue : CGFloat = 0
var corners : UIRectCorner = []

@IBInspectable public var cornerRadiusForSelectedSide : CGFloat {
    get {
        return cornerRadiusValue
    }
    set {
        cornerRadiusValue = newValue
    }
}

override func draw(_ rect: CGRect) {
    super.draw(rect)
    if topLeft {
        corners.insert(.topLeft)
    }
    if topRight {
        corners.insert(.topRight)
    }
    if bottomLeft {
        corners.insert(.bottomLeft)
    }
    if bottomRight {
        corners.insert(.bottomRight)
    }
    self.roundCorners(corners: corners, radius: cornerRadiusForSelectedSide)
}

@IBInspectable public var topLeft : Bool {
    get {
        return corners.contains(.topLeft)
    }
    set {
        setCorner(newValue: newValue, for: .topLeft)
    }
}

@IBInspectable public var topRight : Bool {
    get {
        return corners.contains(.topRight)
    }
    set {
        setCorner(newValue: newValue, for: .topRight)
    }
}

@IBInspectable public var bottomLeft : Bool {
    get {
        return corners.contains(.bottomLeft)
    }
    set {
        setCorner(newValue: newValue, for: .bottomLeft)
    }
}

@IBInspectable public var bottomRight : Bool {
    get {
        return corners.contains(.bottomRight)
    }
    set {
        setCorner(newValue: newValue, for: .bottomRight)
    }
}

func setCorner(newValue: Bool, for corner: UIRectCorner) {
    if newValue {
        addRectCorner(corner: corner)
    } else {
        removeRectCorner(corner: corner)
    }
}

func addRectCorner(corner: UIRectCorner) {
    corners.insert(corner)
}

func removeRectCorner(corner: UIRectCorner) {
    if corners.contains(corner) {
        corners.remove(corner)
    }
}

// // func updateCorners() { // self.roundCorners(corners: corners, radius: cornerRadiusValue) // }

}

this code is not working for me Error: - Value of type 'RoundedCornerView' has no member 'roundCorners'