调整主页布局代码

This commit is contained in:
Fin 2020-05-30 14:50:14 +08:00
parent b8982f2060
commit 21a449a899
4 changed files with 111 additions and 65 deletions

View File

@ -59,3 +59,6 @@ iCloudSync = "Notification messages will be synced when iCloud is available";
defaultArchiveSettings = "Archive by default"; defaultArchiveSettings = "Archive by default";
archiveNote = "When the isArchive parameter is not specified in the push request URL, whether to archive the notification message will be decided according to this setting"; archiveNote = "When the isArchive parameter is not specified in the push request URL, whether to archive the notification message will be decided according to this setting";
archiveNotificationMessageTitle = "Archive notification message";
archiveNotificationMessage = "Notification message will be archived when isArchive value is 1, and will not be archived when the value is 0.\nIf the isArchive parameter is not specified, the notification message will be archived according to the default settings";

View File

@ -59,3 +59,6 @@ iCloudSync = "通知消息将在iCloud可用时同步";
defaultArchiveSettings = "默认保存"; defaultArchiveSettings = "默认保存";
archiveNote = "当推送请求URL没有指定 isArchive 参数时,将按照此设置来决定是否保存通知消息"; archiveNote = "当推送请求URL没有指定 isArchive 参数时,将按照此设置来决定是否保存通知消息";
archiveNotificationMessageTitle = "自动保存通知消息";
archiveNotificationMessage = "当设置 isArchive 值为 1 时,则会自动保存这条推送消息,设置为其他值时,则不会保存。\n如果不指定 isArchive 参数时,则按照默认设置保存消息,可以在 消息->设置->默认保存消息 更改默认保存设置";

View File

@ -37,6 +37,11 @@ class HomeViewController: BaseViewController {
title: NSLocalizedString("CustomedNotificationTitle"), title: NSLocalizedString("CustomedNotificationTitle"),
body: NSLocalizedString("CustomedNotificationContent"), body: NSLocalizedString("CustomedNotificationContent"),
notice: NSLocalizedString("Notice2")), notice: NSLocalizedString("Notice2")),
PreviewModel(
body: NSLocalizedString("archiveNotificationMessageTitle"),
notice: NSLocalizedString("archiveNotificationMessage"),
queryParameter: "isArchive=1"
),
PreviewModel( PreviewModel(
body: "URL Test", body: "URL Test",
notice: NSLocalizedString("urlParameter"), notice: NSLocalizedString("urlParameter"),
@ -114,28 +119,13 @@ class HomeViewController: BaseViewController {
} }
} }
let rowheight:[CGFloat] = {
let screenWidth = UIScreen.main.bounds.width
if screenWidth <= 320 {
return [170,170,170,320,170]
}
if screenWidth <= 375 {
return [205,205,205,380,205]
}
if screenWidth <= 414 {
return [195,195,195,390,195]
}
return [205,205,205,380,205]
}()
} }
extension HomeViewController : UITableViewDataSource, UITableViewDelegate { extension HomeViewController : UITableViewDataSource, UITableViewDelegate {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return dataSource.count return dataSource.count
} }
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return rowheight[indexPath.row]
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if let cell = tableView.dequeueReusableCell(withIdentifier: "\(indexPath.row)") as? PreviewCardCell{ if let cell = tableView.dequeueReusableCell(withIdentifier: "\(indexPath.row)") as? PreviewCardCell{
cell.bind(model: dataSource[indexPath.row]) cell.bind(model: dataSource[indexPath.row])

View File

@ -31,7 +31,21 @@ class PreviewCardCell: UITableViewCell {
let previewButton = IconButton(image: Icon.cm.skipForward, tintColor: Color.grey.base) let previewButton = IconButton(image: Icon.cm.skipForward, tintColor: Color.grey.base)
let copyButton = IconButton(image: UIImage(named: "baseline_file_copy_white_24pt"), tintColor: Color.grey.base) let copyButton = IconButton(image: UIImage(named: "baseline_file_copy_white_24pt"), tintColor: Color.grey.base)
let toolbar = Toolbar()
let titleLabel: UILabel = {
let label = UILabel()
label.font = RobotoFont.regular(with: 14)
label.textColor = Color.grey.darken1
label.numberOfLines = 0
return label
}()
let bodyLabel: UILabel = {
let label = UILabel()
label.font = RobotoFont.regular(with: 14)
label.textColor = Color.grey.base
label.numberOfLines = 0
return label
}()
let noticeLabel: UILabel = { let noticeLabel: UILabel = {
let label = UILabel() let label = UILabel()
@ -40,15 +54,25 @@ class PreviewCardCell: UITableViewCell {
label.numberOfLines = 0 label.numberOfLines = 0
return label return label
}() }()
let contentImageView:UIImageView = {
let bottomBar = Bar() let imageView = UIImageView()
imageView.backgroundColor = UIColor.red
let card = PresenterCard() imageView.contentMode = .scaleAspectFit
return imageView
}()
let card:UIView = {
let view = UIView()
view.backgroundColor = Color.white
view.layer.cornerRadius = 2
view.clipsToBounds = true
return view
}()
var copyHandler: (() -> Void)? var copyHandler: (() -> Void)?
let contentLabel: UILabel = { let contentLabel: UILabel = {
let label = UILabel() let label = UILabel()
label.lineBreakMode = .byCharWrapping
label.numberOfLines = 0 label.numberOfLines = 0
label.font = RobotoFont.regular(with: 14) label.font = RobotoFont.regular(with: 14)
return label return label
@ -59,44 +83,50 @@ class PreviewCardCell: UITableViewCell {
self.selectionStyle = .none self.selectionStyle = .none
self.backgroundColor = Color.grey.lighten3 self.backgroundColor = Color.grey.lighten3
self.transition([ .scale(0.75) , .opacity(0)] ) addSubview(card)
card.snp.makeConstraints { (make) in
make.left.top.equalToSuperview().offset(10)
make.right.equalToSuperview().offset(-10)
make.bottom.equalToSuperview()
}
self.toolbar.rightViews = [copyButton,previewButton] card.addSubview(titleLabel)
self.bottomBar.leftViews = [noticeLabel] card.addSubview(bodyLabel)
card.addSubview(copyButton)
card.addSubview(previewButton)
card.addSubview(contentLabel)
card.addSubview(contentImageView)
card.addSubview(noticeLabel)
toolbar.titleLabel.font = RobotoFont.regular(with: 14) bodyLabel.snp.makeConstraints { (make) in
toolbar.titleLabel.textColor = Color.grey.darken4 make.left.equalTo(titleLabel)
toolbar.titleLabel.textAlignment = .left make.top.equalTo(titleLabel.snp.bottom).offset(5)
}
previewButton.snp.makeConstraints { (make) in
make.right.equalToSuperview().offset(-10)
make.centerY.equalTo(card.snp.top).offset(40)
make.width.height.equalTo(40)
}
copyButton.snp.makeConstraints { (make) in
make.right.equalTo(previewButton.snp.left).offset(-10)
make.centerY.equalTo(previewButton)
make.width.height.equalTo(40)
}
noticeLabel.snp.makeConstraints { (make) in
make.left.equalTo(10)
make.right.equalTo(-10)
make.top.equalTo(contentLabel.snp.bottom).offset(20)
make.bottom.equalToSuperview().offset(-15)
}
toolbar.detailLabel.textAlignment = .left
toolbar.detailLabel.textColor = Color.grey.darken2
card.toolbar = toolbar
card.toolbarEdgeInsetsPreset = .square3
card.toolbarEdgeInsets.bottom = 0
card.toolbarEdgeInsets.right = 8
card.contentView = contentLabel
card.contentViewEdgeInsetsPreset = .wideRectangle3
card.bottomBar = bottomBar
card.bottomBarEdgeInsetsPreset = .wideRectangle2
self.bind(model: model) self.bind(model: model)
self.contentView.layout(card).leftRight(left: 10, right: 10).center()
previewButton.addTarget(self, action: #selector(preview), for: .touchUpInside) previewButton.addTarget(self, action: #selector(preview), for: .touchUpInside)
copyButton.addTarget(self, action: #selector(copyURL), for: .touchUpInside) copyButton.addTarget(self, action: #selector(copyURL), for: .touchUpInside)
//
if UIScreen.main.bounds.size.width <= 320 {
card.contentViewEdgeInsetsPreset = .wideRectangle2
card.bottomBarEdgeInsetsPreset = .wideRectangle1
toolbar.titleLabel.font = RobotoFont.regular(with: 12)
toolbar.detailLabel.font = RobotoFont.regular(with: 10)
contentLabel.font = RobotoFont.regular(with: 10)
noticeLabel.font = RobotoFont.regular(with: 10)
}
} }
@objc func copyURL(){ @objc func copyURL(){
@ -136,11 +166,7 @@ class PreviewCardCell: UITableViewCell {
])) ]))
if let title = model.title { if let title = model.title {
attrStr.append(NSAttributedString(string: "/\(title)", attributes: [ self.titleLabel.text = title
NSAttributedString.Key.foregroundColor: Color.grey.darken1,
NSAttributedString.Key.font : RobotoFont.regular(with: fontSize)
]))
self.toolbar.title = title
} }
if let body = model.body { if let body = model.body {
attrStr.append(NSAttributedString(string: "/\(body)", attributes: [ attrStr.append(NSAttributedString(string: "/\(body)", attributes: [
@ -148,10 +174,22 @@ class PreviewCardCell: UITableViewCell {
NSAttributedString.Key.font : RobotoFont.regular(with: fontSize) NSAttributedString.Key.font : RobotoFont.regular(with: fontSize)
])) ]))
if model.title == nil { if model.title == nil {
self.toolbar.title = body self.titleLabel.text = body
} }
else{ else{
self.toolbar.detail = body self.bodyLabel.text = body
}
}
if self.bodyLabel.text?.count ?? 0 <= 0 {
titleLabel.snp.remakeConstraints { (make) in
make.left.equalToSuperview().offset(15)
make.centerY.equalTo(copyButton)
}
}
else{
titleLabel.snp.remakeConstraints { (make) in
make.left.equalToSuperview().offset(15)
make.top.equalToSuperview().offset(20)
} }
} }
if let queryParameter = model.queryParameter { if let queryParameter = model.queryParameter {
@ -164,15 +202,27 @@ class PreviewCardCell: UITableViewCell {
self.noticeLabel.text = model.notice self.noticeLabel.text = model.notice
if let image = model.image { if let image = model.image {
let imageView = UIImageView(image: image) self.contentImageView.image = image
imageView.backgroundColor = UIColor.red
imageView.contentMode = .scaleAspectFit
let width = UIScreen.main.bounds.size.width - 20 let width = UIScreen.main.bounds.size.width - 20
imageView.frame = CGRect(x: 0, y: 0, width: 0, height: width / image.width * image.height) let height = width / image.width * image.height
contentImageView.snp.remakeConstraints { (make) in
card.presenterView = imageView make.left.right.equalToSuperview()
card.presenterViewEdgeInsetsPreset = .none make.top.equalTo(previewButton.snp.bottom).offset(15)
make.height.equalTo(height)
}
contentLabel.snp.remakeConstraints { (make) in
make.left.equalToSuperview().offset(12)
make.right.equalToSuperview().offset(-12)
make.top.equalTo(contentImageView.snp.bottom).offset(15)
}
}
else{
contentLabel.snp.remakeConstraints { (make) in
make.left.equalToSuperview().offset(12)
make.right.equalToSuperview().offset(-12)
make.top.equalTo(previewButton.snp.bottom).offset(20)
}
} }
} }