Re: CGContext always creating a black rect.
I know I don’t need the self, but I want the context. A variable just sitting around tells me nothing about the context in which it exists. I want to see the context and want to see the self.
- The `roundRect(…)` function would be better named as `drawRoundRect(…)`.
Want them. They indicate scope. I don’t need to think. I just look at it and know the scope. Anything that makes code more vague sucks. I want easier understanding rather than “but we can use less words!” People’s time is $$.
It can’t exist without its configuration being set and it will be drawing with those internal settings once I have the details set up. Then it’s possible that I’ll move the configuration internal. Eventually, it will have a gradient interior. It’s replacing a UISwitch.
Here’s how I currently call it.
self.roundedRect = RoundedRectUIView()
self.roundedRect.backgroundColor = .clear
self.roundedRect.clipsToBounds = true
let rectBorderWidth = CGFloat(2)
let rectWidth = CGFloat(100)
let rectHeight = CGFloat(40)
let rectBorderColor = UIColor.blue
let rectBgColor = UIColor.systemGray3
let rectCornerRadius = CGFloat(-1)
let origin = CGPoint(x: 10, y: 200)
viewRect = CGRect(origin: origin,
size: CGSize(width: rectWidth + rectBorderWidth * 2.0,
height: rectHeight + (rectBorderWidth * 2.0)))
self.roundedRect.frame = viewRect
self.roundedRect.configure(rectWidth: rectWidth, rectHeight: rectHeight, rectBgColor: rectBgColor , rectBorderColor: rectBorderColor, rectBorderWidth: rectBorderWidth, rectCornerRadius: rectCornerRadius)
In Swift, I HATE how they have done method parameters, so I’m opting for redundant redundancy over terseness or brevity.