Skip to content

Commit

Permalink
Merge pull request #331 from iOSappssolutions/main
Browse files Browse the repository at this point in the history
fix button background color
  • Loading branch information
migueldeicaza authored Nov 13, 2023
2 parents 6b9d7dc + 8e153aa commit 8fa2ec8
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion Sources/SwiftTerm/iOS/iOSAccessoryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -341,19 +341,22 @@ return
func makeButton (_ title: String, _ action: Selector, icon: String = "", isNormal: Bool = true) -> UIButton
{
let useSmall = self._useSmall
let b = UIButton.init(type: .roundedRect)
let b = BackgroundSelectedButton.init(type: .roundedRect)

TerminalAccessory.styleButton (b)
b.addTarget(self, action: action, for: .touchDown)
b.setTitle(title, for: .normal)
guard let terminalView else {
return b
}
b.color = isNormal ? terminalView.buttonBackgroundColor : terminalView.buttonDarkBackgroundColor
b.setTitleColor(terminalView.buttonColor, for: .normal)
b.setTitleColor(terminalView.buttonColor, for: .selected)
if useSmall {
b.titleLabel?.font = UIFont.systemFont(ofSize: 12)
}
b.backgroundColor = isNormal ? terminalView.buttonBackgroundColor : terminalView.buttonDarkBackgroundColor

if icon != "" {
if let img = UIImage (systemName: icon, withConfiguration: UIImage.SymbolConfiguration (pointSize: 14.0)) {
b.setImage(img.withTintColor(terminalView.buttonColor, renderingMode: .alwaysOriginal), for: .normal)
Expand All @@ -380,3 +383,15 @@ return
}
}
#endif


class BackgroundSelectedButton: UIButton {

var color: UIColor?

override var isSelected: Bool {
didSet {
self.backgroundColor = isSelected ? UIView().tintColor : color
}
}
}

0 comments on commit 8fa2ec8

Please sign in to comment.