I posted this question 9 days ago.
I haven't figured it out so I'm reposting with code and screenshots.
I have a custom button that works fine in the host app but doesn't draw completely in the Today Extension.
Here's what it should look like in the storyboard and how the preview looks distorted:
and here's how it actually looks on an iPhone 5s:
I figure this has something to do with how the Today Extension loads - that somehow the button isn't being drawn completely. This, however, doesn't explain the distorted preview (at least to my newbie self).
Here's the button code:
@IBDesignable class TakeButton: UIButton {
@IBInspectable var fillColor: UIColor = UIColor.greenColor()
@IBInspectable var isAddButton: Bool = true
@IBInspectable var isTodayExtensionButton: Bool = false
var plusHeight: CGFloat = 0.0
var plusWidth: CGFloat = 0.0
//
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
override func drawRect(rect: CGRect) {
var path = UIBezierPath(ovalInRect: rect)
fillColor.setFill()
path.fill()
//set up width and height variables for horizontal stroke
if isTodayExtensionButton {
plusHeight = 2.0
plusWidth = 25.0
}
else {
plusHeight = 3.0
plusWidth = 45.0
}
//create the path
var plusPath = UIBezierPath()
//set the path's line width to the height of the stroke
plusPath.lineWidth = plusHeight
//move the initial point of the path
//to the start of the horizontal stroke
plusPath.moveToPoint(CGPoint(
x: bounds.width/2 - plusWidth/2 + 0.5,
y: bounds.height/2))
//add a point to the path at the end of the stroke
plusPath.addLineToPoint(CGPoint(
x: bounds.width/2 + plusWidth/2 + 0.5,
y: bounds.height/2))
//for vertical line - take button
if isAddButton {
plusPath.moveToPoint(CGPoint(
x: bounds.width/2,
y: bounds.height/2 - plusWidth/2 + 0.5))
plusPath.addLineToPoint(CGPoint(
x: bounds.width/2,
y: bounds.height/2 + plusWidth/2 + 0.5))
}
//set the stroke color
UIColor.whiteColor().setStroke()
//draw the stroke
plusPath.stroke()
}
}