Skip to content

Commit

Permalink
make sure that font changes affect both buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
stakes committed Jan 23, 2015
1 parent 2c8c742 commit 76c20f7
Showing 1 changed file with 40 additions and 29 deletions.
69 changes: 40 additions & 29 deletions JSSAlertView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,28 +85,28 @@ class JSSAlertView: UIViewController {

func setFont(fontStr: String, type: FontType) {
switch type {
case .Title:
self.titleFont = fontStr
if let font = UIFont(name: self.titleFont, size: 24) {
self.titleLabel.font = font
case .Title:
self.titleFont = fontStr
if let font = UIFont(name: self.titleFont, size: 24) {
self.titleLabel.font = font
} else {
self.titleLabel.font = UIFont.systemFontOfSize(24)
}
case .Text:
if self.textView != nil {
self.textFont = fontStr
if let font = UIFont(name: self.textFont, size: 16) {
self.textView.font = font
} else {
self.titleLabel.font = UIFont.systemFontOfSize(24)
}
case .Text:
if self.textView != nil {
self.textFont = fontStr
if let font = UIFont(name: self.textFont, size: 16) {
self.textView.font = font
} else {
self.textView.font = UIFont.systemFontOfSize(16)
}
self.textView.font = UIFont.systemFontOfSize(16)
}
case .Button:
self.buttonFont = fontStr
if let font = UIFont(name: self.buttonFont, size: 24) {
self.buttonLabel.font = font
} else {
self.buttonLabel.font = UIFont.systemFontOfSize(24)
}
case .Button:
self.buttonFont = fontStr
if let font = UIFont(name: self.buttonFont, size: 24) {
self.buttonLabel.font = font
} else {
self.buttonLabel.font = UIFont.systemFontOfSize(24)
}
}
// relayout to account for size changes
Expand All @@ -115,10 +115,10 @@ class JSSAlertView: UIViewController {

func setTextTheme(theme: TextColorTheme) {
switch theme {
case .Light:
recolorText(lightTextColor)
case .Dark:
recolorText(darkTextColor)
case .Light:
recolorText(lightTextColor)
case .Dark:
recolorText(darkTextColor)
}
}

Expand All @@ -128,6 +128,9 @@ class JSSAlertView: UIViewController {
textView.textColor = color
}
buttonLabel.textColor = color
if cancelButtonLabel != nil {
cancelButtonLabel.textColor = color
}
}

required init(coder aDecoder: NSCoder) {
Expand Down Expand Up @@ -202,6 +205,14 @@ class JSSAlertView: UIViewController {
self.buttonLabel.frame = CGRect(x: self.padding, y: (self.buttonHeight/2) - 15, width: buttonWidth - (self.padding*2), height: 30)
}

// set button fonts
if self.buttonLabel != nil {
buttonLabel.font = UIFont(name: self.buttonFont, size: 20)
}
if self.cancelButtonLabel != nil {
cancelButtonLabel.font = UIFont(name: self.buttonFont, size: 20)
}

yPos += self.buttonHeight

// size the background view
Expand Down Expand Up @@ -305,9 +316,8 @@ class JSSAlertView: UIViewController {
buttonLabel.textColor = textColor
buttonLabel.numberOfLines = 1
buttonLabel.textAlignment = .Center
buttonLabel.font = UIFont(name: self.buttonFont, size: 20)
if let text = buttonText {
buttonLabel.text = text.uppercaseString
buttonLabel.text = text
} else {
buttonLabel.text = "OK"
}
Expand All @@ -324,14 +334,14 @@ class JSSAlertView: UIViewController {
alertBackgroundView!.addSubview(cancelButton)
// Button text
self.cancelButtonLabel = UILabel()
cancelButtonLabel.alpha = 0.75
cancelButtonLabel.textColor = textColor
cancelButtonLabel.numberOfLines = 1
cancelButtonLabel.textAlignment = .Center
cancelButtonLabel.font = UIFont(name: self.buttonFont, size: 20)
if let text = cancelButtonText {
cancelButtonLabel.text = text.uppercaseString
cancelButtonLabel.text = text
}
cancelButtonLabel.alpha = 0.75

cancelButton.addSubview(cancelButtonLabel)
}

Expand Down Expand Up @@ -389,6 +399,7 @@ class JSSAlertView: UIViewController {




// Utility methods + extensions

// Extend UIImage with a method to create
Expand Down

0 comments on commit 76c20f7

Please sign in to comment.