Merge branch 'charlesmchen/flatButtonCR'
This commit is contained in:
commit
05cc84ee11
@ -346,11 +346,12 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat
|
||||
// The save button is only used in "registration" and "upgrade or nag" modes.
|
||||
if (self.hasUnsavedChanges) {
|
||||
self.saveButton.enabled = YES;
|
||||
[self.saveButton setBackgroundColors:[UIColor ows_signalBrandBlueColor]];
|
||||
[self.saveButton setBackgroundColorsWithUpColor:[UIColor ows_signalBrandBlueColor]];
|
||||
} else {
|
||||
self.saveButton.enabled = NO;
|
||||
[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];
|
||||
self.phoneNumberButton.enabled = isEnabled;
|
||||
[self.phoneNumberButton
|
||||
setBackgroundColors:(isEnabled ? [UIColor ows_signalBrandBlueColor] : [UIColor lightGrayColor])];
|
||||
setBackgroundColorsWithUpColor:(isEnabled ? [UIColor ows_signalBrandBlueColor] : [UIColor lightGrayColor])];
|
||||
}
|
||||
|
||||
#pragma mark - CountryCodeViewControllerDelegate
|
||||
|
||||
@ -170,6 +170,7 @@
|
||||
|
||||
+ (UIImage *)imageWithColor:(UIColor *)color
|
||||
{
|
||||
OWSAssert([NSThread isMainThread]);
|
||||
OWSAssert(color);
|
||||
|
||||
return [self imageWithColor:color size:CGSizeMake(1.f, 1.f)];
|
||||
@ -177,6 +178,7 @@
|
||||
|
||||
+ (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size
|
||||
{
|
||||
OWSAssert([NSThread isMainThread]);
|
||||
OWSAssert(color);
|
||||
|
||||
CGRect rect = CGRectMake(0.0f, 0.0f, size.width, size.height);
|
||||
|
||||
@ -7,16 +7,24 @@ import Foundation
|
||||
@objc class OWSFlatButton: UIView {
|
||||
let TAG = "[OWSFlatButton]"
|
||||
|
||||
private var button: UIButton?
|
||||
private let button: UIButton
|
||||
|
||||
private var pressedBlock : (() -> Void)?
|
||||
|
||||
private var upColor: UIColor?
|
||||
private var downColor: UIColor?
|
||||
|
||||
override var backgroundColor: UIColor? {
|
||||
willSet {
|
||||
owsFail("Use setBackgroundColors(upColor:) instead.")
|
||||
}
|
||||
}
|
||||
|
||||
init() {
|
||||
AssertIsOnMainThread()
|
||||
|
||||
button = UIButton(type:.custom)
|
||||
|
||||
super.init(frame:CGRect.zero)
|
||||
|
||||
createContent()
|
||||
@ -24,13 +32,14 @@ import Foundation
|
||||
|
||||
@available(*, unavailable, message:"use default constructor instead.")
|
||||
required init?(coder aDecoder: NSCoder) {
|
||||
button = UIButton(type:.custom)
|
||||
|
||||
super.init(coder: aDecoder)
|
||||
|
||||
owsFail("\(self.TAG) invalid constructor")
|
||||
}
|
||||
|
||||
private func createContent() {
|
||||
let button = UIButton(type:.custom)
|
||||
self.button = button
|
||||
self.addSubview(button)
|
||||
button.addTarget(self, action:#selector(buttonPressed), for:.touchUpInside)
|
||||
button.autoPinWidthToSuperview()
|
||||
@ -49,7 +58,7 @@ import Foundation
|
||||
button.setTitle(title:title,
|
||||
font: font,
|
||||
titleColor: titleColor )
|
||||
button.setBackgroundColors(backgroundColor)
|
||||
button.setBackgroundColors(upColor:backgroundColor)
|
||||
button.useDefaultCornerRadius()
|
||||
button.setSize(width:width, height:height)
|
||||
button.addTarget(target:target, selector:selector)
|
||||
@ -83,7 +92,7 @@ import Foundation
|
||||
button.setTitle(title:title,
|
||||
font: font,
|
||||
titleColor: titleColor )
|
||||
button.setBackgroundColors(backgroundColor)
|
||||
button.setBackgroundColors(upColor:backgroundColor)
|
||||
button.useDefaultCornerRadius()
|
||||
button.addTarget(target:target, selector:selector)
|
||||
return button
|
||||
@ -98,10 +107,6 @@ import Foundation
|
||||
|
||||
public func setTitle(title: String, font: UIFont,
|
||||
titleColor: UIColor ) {
|
||||
guard let button = self.button else {
|
||||
owsFail("Missing button")
|
||||
return
|
||||
}
|
||||
button.setTitle(title, for: .normal)
|
||||
button.setTitleColor(titleColor, for: .normal)
|
||||
button.titleLabel!.font = font
|
||||
@ -109,33 +114,21 @@ import Foundation
|
||||
|
||||
public func setBackgroundColors(upColor: UIColor,
|
||||
downColor: UIColor ) {
|
||||
guard let button = self.button else {
|
||||
owsFail("Missing button")
|
||||
return
|
||||
}
|
||||
button.setBackgroundImage(UIImage(color:upColor), for: .normal)
|
||||
button.setBackgroundImage(UIImage(color:downColor), for: .highlighted)
|
||||
}
|
||||
|
||||
public func setBackgroundColors(_ backgroundColor: UIColor ) {
|
||||
setBackgroundColors(upColor: backgroundColor,
|
||||
downColor: backgroundColor.withAlphaComponent(0.7) )
|
||||
public func setBackgroundColors(upColor: UIColor ) {
|
||||
setBackgroundColors(upColor: upColor,
|
||||
downColor: upColor.withAlphaComponent(0.7) )
|
||||
}
|
||||
|
||||
public func setSize(width: CGFloat, height: CGFloat) {
|
||||
guard let button = self.button else {
|
||||
owsFail("Missing button")
|
||||
return
|
||||
}
|
||||
button.autoSetDimension(.width, toSize:width)
|
||||
button.autoSetDimension(.height, toSize:height)
|
||||
}
|
||||
|
||||
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
|
||||
// (within reason) or device size.
|
||||
button.layer.cornerRadius = 5
|
||||
@ -143,19 +136,11 @@ import Foundation
|
||||
}
|
||||
|
||||
public func setEnabled(_ isEnabled: Bool) {
|
||||
guard let button = self.button else {
|
||||
owsFail("Missing button")
|
||||
return
|
||||
}
|
||||
button.isEnabled = isEnabled
|
||||
}
|
||||
|
||||
public func addTarget(target:Any,
|
||||
selector: Selector) {
|
||||
guard let button = self.button else {
|
||||
owsFail("Missing button")
|
||||
return
|
||||
}
|
||||
button.addTarget(target, action:selector, for:.touchUpInside)
|
||||
}
|
||||
|
||||
@ -168,9 +153,6 @@ import Foundation
|
||||
}
|
||||
|
||||
internal func buttonPressed() {
|
||||
guard let pressedBlock = pressedBlock else {
|
||||
return
|
||||
}
|
||||
pressedBlock()
|
||||
pressedBlock?()
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user