parent
3b0e49a369
commit
7c16642d66
@ -1,45 +0,0 @@ |
||||
// Copyright © 2018 Stormbird PTE. LTD. |
||||
|
||||
import Foundation |
||||
import UIKit |
||||
import AlphaWalletFoundation |
||||
|
||||
struct DappsAutoCompletionCellViewModel { |
||||
let dapp: Dapp |
||||
let keyword: String |
||||
|
||||
var backgroundColor: UIColor { |
||||
return UIColor(red: 244, green: 244, blue: 244) |
||||
} |
||||
|
||||
var name: NSAttributedString { |
||||
let text = NSMutableAttributedString(string: dapp.name) |
||||
text.setAttributes([NSAttributedString.Key.foregroundColor: nameColor as Any], range: .init(location: 0, length: dapp.name.count)) |
||||
if let range = dapp.name.lowercased().range(of: keyword.lowercased()) { |
||||
let location = dapp.name.distance(from: dapp.name.startIndex, to: range.lowerBound) |
||||
let length = keyword.count |
||||
text.setAttributes([NSAttributedString.Key.foregroundColor: Colors.appTint], range: .init(location: location, length: length)) |
||||
} |
||||
return text |
||||
} |
||||
|
||||
var description: String { |
||||
return dapp.description |
||||
} |
||||
|
||||
var nameFont: UIFont { |
||||
return Fonts.regular(size: 16) |
||||
} |
||||
|
||||
var descriptionFont: UIFont { |
||||
return Fonts.regular(size: 12) |
||||
} |
||||
|
||||
private var nameColor: UIColor? { |
||||
return UIColor(red: 55, green: 55, blue: 55) |
||||
} |
||||
|
||||
var descriptionColor: UIColor? { |
||||
return UIColor(red: 77, green: 77, blue: 77) |
||||
} |
||||
} |
@ -1,43 +0,0 @@ |
||||
// Copyright © 2018 Stormbird PTE. LTD. |
||||
|
||||
import Foundation |
||||
import UIKit |
||||
|
||||
class DappsAutoCompletionCell: UITableViewCell { |
||||
let titleLabel = UILabel() |
||||
let descriptionLabel = UILabel() |
||||
|
||||
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { |
||||
super.init(style: .subtitle, reuseIdentifier: reuseIdentifier) |
||||
|
||||
let stackView = [ |
||||
titleLabel, |
||||
descriptionLabel |
||||
].asStackView(axis: .vertical) |
||||
stackView.translatesAutoresizingMaskIntoConstraints = false |
||||
contentView.addSubview(stackView) |
||||
|
||||
NSLayoutConstraint.activate([ |
||||
stackView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 28), |
||||
stackView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -28), |
||||
stackView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 10), |
||||
stackView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -10), |
||||
]) |
||||
} |
||||
|
||||
required init?(coder aDecoder: NSCoder) { |
||||
fatalError("init(coder:) has not been implemented") |
||||
} |
||||
|
||||
func configure(viewModel: DappsAutoCompletionCellViewModel) { |
||||
backgroundColor = viewModel.backgroundColor |
||||
contentView.backgroundColor = viewModel.backgroundColor |
||||
|
||||
titleLabel.font = viewModel.nameFont |
||||
titleLabel.attributedText = viewModel.name |
||||
|
||||
descriptionLabel.font = viewModel.descriptionFont |
||||
descriptionLabel.textColor = viewModel.descriptionColor |
||||
descriptionLabel.text = viewModel.description |
||||
} |
||||
} |
Loading…
Reference in new issue