Respond to CR.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent 8ceca76453
commit 2affcd934f

@ -346,11 +346,12 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat
// The save button is only used in "registration" and "upgrade or nag" modes. // The save button is only used in "registration" and "upgrade or nag" modes.
if (self.hasUnsavedChanges) { if (self.hasUnsavedChanges) {
self.saveButton.enabled = YES; self.saveButton.enabled = YES;
[self.saveButton setBackgroundColors:[UIColor ows_signalBrandBlueColor]]; [self.saveButton setBackgroundColorsWithUpColor:[UIColor ows_signalBrandBlueColor]];
} else { } else {
self.saveButton.enabled = NO; self.saveButton.enabled = NO;
[self.saveButton [self.saveButton
setBackgroundColors:[[UIColor ows_signalBrandBlueColor] blendWithColor:[UIColor whiteColor] alpha:0.5f]]; setBackgroundColorsWithUpColor:[[UIColor ows_signalBrandBlueColor] blendWithColor:[UIColor whiteColor]
alpha:0.5f]];
} }
} }

@ -379,7 +379,7 @@ NSString *const kSelectRecipientViewControllerCellIdentifier = @"kSelectRecipien
BOOL isEnabled = [self hasValidPhoneNumber]; BOOL isEnabled = [self hasValidPhoneNumber];
self.phoneNumberButton.enabled = isEnabled; self.phoneNumberButton.enabled = isEnabled;
[self.phoneNumberButton [self.phoneNumberButton
setBackgroundColors:(isEnabled ? [UIColor ows_signalBrandBlueColor] : [UIColor lightGrayColor])]; setBackgroundColorsWithUpColor:(isEnabled ? [UIColor ows_signalBrandBlueColor] : [UIColor lightGrayColor])];
} }
#pragma mark - CountryCodeViewControllerDelegate #pragma mark - CountryCodeViewControllerDelegate

@ -170,6 +170,7 @@
+ (UIImage *)imageWithColor:(UIColor *)color + (UIImage *)imageWithColor:(UIColor *)color
{ {
OWSAssert([NSThread isMainThread]);
OWSAssert(color); OWSAssert(color);
return [self imageWithColor:color size:CGSizeMake(1.f, 1.f)]; return [self imageWithColor:color size:CGSizeMake(1.f, 1.f)];
@ -177,6 +178,7 @@
+ (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size + (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size
{ {
OWSAssert([NSThread isMainThread]);
OWSAssert(color); OWSAssert(color);
CGRect rect = CGRectMake(0.0f, 0.0f, size.width, size.height); CGRect rect = CGRectMake(0.0f, 0.0f, size.width, size.height);

@ -7,16 +7,24 @@ import Foundation
@objc class OWSFlatButton: UIView { @objc class OWSFlatButton: UIView {
let TAG = "[OWSFlatButton]" let TAG = "[OWSFlatButton]"
private var button: UIButton? private let button: UIButton
private var pressedBlock : (() -> Void)? private var pressedBlock : (() -> Void)?
private var upColor: UIColor? private var upColor: UIColor?
private var downColor: UIColor? private var downColor: UIColor?
override var backgroundColor: UIColor? {
willSet {
owsFail("Use setBackgroundColors(upColor:) instead.")
}
}
init() { init() {
AssertIsOnMainThread() AssertIsOnMainThread()
button = UIButton(type:.custom)
super.init(frame:CGRect.zero) super.init(frame:CGRect.zero)
createContent() createContent()
@ -24,13 +32,14 @@ import Foundation
@available(*, unavailable, message:"use default constructor instead.") @available(*, unavailable, message:"use default constructor instead.")
required init?(coder aDecoder: NSCoder) { required init?(coder aDecoder: NSCoder) {
button = UIButton(type:.custom)
super.init(coder: aDecoder) super.init(coder: aDecoder)
owsFail("\(self.TAG) invalid constructor") owsFail("\(self.TAG) invalid constructor")
} }
private func createContent() { private func createContent() {
let button = UIButton(type:.custom)
self.button = button
self.addSubview(button) self.addSubview(button)
button.addTarget(self, action:#selector(buttonPressed), for:.touchUpInside) button.addTarget(self, action:#selector(buttonPressed), for:.touchUpInside)
button.autoPinWidthToSuperview() button.autoPinWidthToSuperview()
@ -49,7 +58,7 @@ import Foundation
button.setTitle(title:title, button.setTitle(title:title,
font: font, font: font,
titleColor: titleColor ) titleColor: titleColor )
button.setBackgroundColors(backgroundColor) button.setBackgroundColors(upColor:backgroundColor)
button.useDefaultCornerRadius() button.useDefaultCornerRadius()
button.setSize(width:width, height:height) button.setSize(width:width, height:height)
button.addTarget(target:target, selector:selector) button.addTarget(target:target, selector:selector)
@ -83,7 +92,7 @@ import Foundation
button.setTitle(title:title, button.setTitle(title:title,
font: font, font: font,
titleColor: titleColor ) titleColor: titleColor )
button.setBackgroundColors(backgroundColor) button.setBackgroundColors(upColor:backgroundColor)
button.useDefaultCornerRadius() button.useDefaultCornerRadius()
button.addTarget(target:target, selector:selector) button.addTarget(target:target, selector:selector)
return button return button
@ -98,10 +107,6 @@ import Foundation
public func setTitle(title: String, font: UIFont, public func setTitle(title: String, font: UIFont,
titleColor: UIColor ) { titleColor: UIColor ) {
guard let button = self.button else {
owsFail("Missing button")
return
}
button.setTitle(title, for: .normal) button.setTitle(title, for: .normal)
button.setTitleColor(titleColor, for: .normal) button.setTitleColor(titleColor, for: .normal)
button.titleLabel!.font = font button.titleLabel!.font = font
@ -109,33 +114,21 @@ import Foundation
public func setBackgroundColors(upColor: UIColor, public func setBackgroundColors(upColor: UIColor,
downColor: UIColor ) { downColor: UIColor ) {
guard let button = self.button else {
owsFail("Missing button")
return
}
button.setBackgroundImage(UIImage(color:upColor), for: .normal) button.setBackgroundImage(UIImage(color:upColor), for: .normal)
button.setBackgroundImage(UIImage(color:downColor), for: .highlighted) button.setBackgroundImage(UIImage(color:downColor), for: .highlighted)
} }
public func setBackgroundColors(_ backgroundColor: UIColor ) { public func setBackgroundColors(upColor: UIColor ) {
setBackgroundColors(upColor: backgroundColor, setBackgroundColors(upColor: upColor,
downColor: backgroundColor.withAlphaComponent(0.7) ) downColor: upColor.withAlphaComponent(0.7) )
} }
public func setSize(width: CGFloat, height: CGFloat) { public func setSize(width: CGFloat, height: CGFloat) {
guard let button = self.button else {
owsFail("Missing button")
return
}
button.autoSetDimension(.width, toSize:width) button.autoSetDimension(.width, toSize:width)
button.autoSetDimension(.height, toSize:height) button.autoSetDimension(.height, toSize:height)
} }
public func useDefaultCornerRadius() { public func useDefaultCornerRadius() {
guard let button = self.button else {
owsFail("Missing button")
return
}
// To my eye, this radius tends to look right regardless of button size // To my eye, this radius tends to look right regardless of button size
// (within reason) or device size. // (within reason) or device size.
button.layer.cornerRadius = 5 button.layer.cornerRadius = 5
@ -143,19 +136,11 @@ import Foundation
} }
public func setEnabled(_ isEnabled: Bool) { public func setEnabled(_ isEnabled: Bool) {
guard let button = self.button else {
owsFail("Missing button")
return
}
button.isEnabled = isEnabled button.isEnabled = isEnabled
} }
public func addTarget(target:Any, public func addTarget(target:Any,
selector: Selector) { selector: Selector) {
guard let button = self.button else {
owsFail("Missing button")
return
}
button.addTarget(target, action:selector, for:.touchUpInside) button.addTarget(target, action:selector, for:.touchUpInside)
} }
@ -168,9 +153,6 @@ import Foundation
} }
internal func buttonPressed() { internal func buttonPressed() {
guard let pressedBlock = pressedBlock else { pressedBlock?()
return
}
pressedBlock()
} }
} }

Loading…
Cancel
Save