-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feed/title body+view more #161
base: develop
Are you sure you want to change the base?
Changes from 7 commits
85d45a8
01466d3
9a29581
a6ecf52
617f72d
22dd0a7
f86ec84
1188487
b781857
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// | ||
// FeedBodyTxt.swift | ||
// FightPandemics | ||
// | ||
// Created by ehsan sat on 5/26/20. | ||
// | ||
// Copyright (c) 2020 FightPandemics | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
import UIKit | ||
|
||
class FeedBodyTxt: UIView { | ||
private var bodyLbl = UILabel() | ||
private var viewMore = FeedViewMoreBtn() | ||
var text: String | ||
init(text: String) { | ||
self.text = text | ||
super.init(frame: .zero) | ||
setUp() | ||
} | ||
|
||
required init?(coder _: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
func setUp() { | ||
let newTxt = text.components(separatedBy: " ").dropLast().dropLast().dropLast().joined(separator: " ") | ||
bodyLbl.attributedText = NSAttributedString(string: newTxt, attributes: [NSAttributedString.Key.font: Fonts.poppinsRegular.customFont(size: 14), NSAttributedString.Key.foregroundColor: UIColor.fightPandemicsNero()]) | ||
bodyLbl.textAlignment = .left | ||
bodyLbl.numberOfLines = 0 | ||
bodyLbl.lineBreakMode = .byWordWrapping | ||
bodyLbl.makeSubview(of: self) | ||
.width(UIScreen.main.bounds.width - 40) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can constrain the bodyLbl to the the width of its parent view. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh! that's right |
||
.height(heighOfBody(text: newTxt)) | ||
viewMore.makeSubview(of: self) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To position the viewMore button correctly, check out the code snippet below: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was looking for a way to attach the button to the end of text (which has different length), do you have any solution for that? |
||
.width(72) | ||
.height(16) | ||
.right(to: \.rightAnchor, constant: -5) | ||
.bottom(to: \.bottomAnchor, constant: -5) | ||
} | ||
|
||
func heighOfBody(text: String) -> CGFloat { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice work Ethan, can we abstract out this method and reuse it in the other place where you also used it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks, this is already available. it depends on the font and font size, so we can access it with FeeBodyTxt.heightOfBody(text: String) |
||
let boundingBox = NSString(string: text).boundingRect(with: CGSize(width: UIScreen.main.bounds.width - 40, height: .greatestFiniteMagnitude), options: NSStringDrawingOptions.usesFontLeading.union(.usesLineFragmentOrigin), attributes: [NSAttributedString.Key.font: Fonts.poppinsBold.customFont(size: 14)], context: nil) | ||
return boundingBox.height | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// | ||
// FeedTitle.swift | ||
// FightPandemics | ||
// | ||
// Created by ehsan sat on 5/26/20. | ||
// | ||
// Copyright (c) 2020 FightPandemics | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
import UIKit | ||
|
||
class FeedTitle: UIView { | ||
private var titleLbl = UILabel() | ||
var title: String | ||
init(title: String) { | ||
self.title = title | ||
super.init(frame: .zero) | ||
setUp() | ||
} | ||
|
||
required init?(coder _: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
func setUp() { | ||
titleLbl.attributedText = NSAttributedString(string: title, attributes: [NSAttributedString.Key.font: Fonts.poppinsBold.customFont(size: 22), NSAttributedString.Key.foregroundColor: UIColor.fightPandemicsNero()]) | ||
titleLbl.numberOfLines = 0 | ||
titleLbl.lineBreakMode = .byWordWrapping | ||
titleLbl.makeSubview(of: self) | ||
.width(UIScreen.main.bounds.size.width - 40) | ||
.height(heighOfTitle(title: title)) | ||
} | ||
|
||
func heighOfTitle(title: String) -> CGFloat { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, please do try to fix the lint warning here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the swiftLint was disabled in my code, I'm trying to fix this later. (update, fixed) |
||
let boundingBox = NSString(string: title).boundingRect(with: CGSize(width: UIScreen.main.bounds.width - 40, height: .greatestFiniteMagnitude), options: NSStringDrawingOptions.usesFontLeading.union(.usesLineFragmentOrigin), attributes: [NSAttributedString.Key.font: Fonts.poppinsBold.customFont(size: 22)], context: nil) | ||
return boundingBox.height | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// | ||
// FeedViewMoreBtn.swift | ||
// FightPandemics | ||
// | ||
// Created by ehsan sat on 5/26/20. | ||
// | ||
// Copyright (c) 2020 FightPandemics | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
import UIKit | ||
|
||
class FeedViewMoreBtn: UIButton { | ||
override init(frame: CGRect) { | ||
super.init(frame: frame) | ||
setUp() | ||
} | ||
|
||
required init?(coder _: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
func setUp() { | ||
setAttributedTitle(NSAttributedString(string: "ViewMoreBtn".localized, attributes: [NSAttributedString.Key.font: Fonts.dmSansRegular.customFont(size: 14), NSAttributedString.Key.foregroundColor: UIColor.fightPandemicsNeonBlue()]), for: .normal) | ||
backgroundColor = UIColor.white | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand the purpose of this code here, please can you help put me through?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the words that appear at the end of text sometimes overlapped with the button, I tried to fix this.