Posts

Showing posts with the label UIView

Swift: Giving Context To Cgcontext (Part I)

First encounters alongside CGContext tin flaming hold upwards bewildering. We are presented alongside a lot of code that looks most dissimilar Swift together with to a greater extent than than probable it's inwards a drawRect: method of a UIView. So let's consider the entry signal to drawing: override func drawRect(rect: CGRect) { if permit context = UIGraphicsGetCurrentContext() { } } To explain, during the lifetime of a drawRect: in that location is a CGContext that nosotros tin flaming gain access to past times precisely calling UIGraphicsGetCurrentContext() as demonstrated above. Once nosotros convey the context, which is the house that we're going to hold upwards drawing to, nosotros tin flaming draw. And this drawing volition appear every fourth dimension a stance of our UIView subclass type is presented on screen. Demonstrating CGContext To demonstrate this, the showtime affair we're going to practise is to fill upwards the stance together with to ...

Uibutton At Your Convenience

UIButton is 1 of those classes where y'all receive got to receive got quite a few steps to ready an instance if y'all require anything beyond the default. For example, I would similar to practise a circular push clitoris alongside a title, border, background colour, etc. extension UIButton { convenience init(withRadius radius:CGFloat, title:String, titleColor:UIColor, target:UIViewController, selector:Selector, backgroundColor:UIColor, borderColor:UIColor, borderWidth:CGFloat, position:CGPoint) { self.init() self.setTitle(title, for: .normal) self.setTitleColor(titleColor, for: .normal) self.addTarget(target, action: selector, for: .touchDown) self.backgroundColor = backgroundColor allow diameter = ii * radius self.frame = CGRect(x: position.x, y: position.y, width: diameter, height: diameter) self.layer.cornerRadius = radius self.layer.masksToBounds = imitation self.layer.borderWidth = border...