The iOS sdk already has a wide collection of UIView subclasses to meet the needs of developer for developing eye-catching and elegant user interface. However, the default UI components provided in the iOS SDK are jus not enough sometimes. In that case, you can create your own UI components as required by writing your code on top of the sdk's classes i.e. UIView.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyCustomView: UIView { | |
override init(frame: CGRect) { | |
super.init(frame: frame) | |
} | |
required init?(coder aDecoder: NSCoder) { | |
super.init(coder: aDecoder) | |
} | |
override func draw(_ rect: CGRect) { | |
//create a path to perform the custom drawing | |
print(rect) | |
let trianglePath = UIBezierPath() | |
trianglePath.move(to: CGPoint(x: 0, y: 0)) | |
trianglePath.addLine(to: CGPoint(x: rect.width, y: 0)) | |
trianglePath.addLine(to: CGPoint(x: rect.width / 2, y: rect.height)) | |
trianglePath.addLine(to: CGPoint(x: 0, y: 0)) | |
trianglePath.fill() | |
self.backgroundColor = UIColor.white | |
} | |
} | |
var myView = MyCustomView(frame: CGRect(x: 10, y: 10, width: 100, height: 150)) | |
myView.backgroundColor = UIColor.clear |

Comments
Post a Comment