-
Notifications
You must be signed in to change notification settings - Fork 494
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
Add Images to TagListView #193
base: master
Are you sure you want to change the base?
Conversation
@@ -19,3 +19,6 @@ DerivedData | |||
|
|||
# CocoaPods | |||
Pods/ | |||
/TagListViewDemo/Images.xcassets/.DS_Store |
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.
You can use find . -name .DS_Store -print0 | xargs -0 git rm --ignore-unmatch
to remove all .DS_Store
s from the repository.
TagListView.podspec
Outdated
@@ -1,6 +1,6 @@ | |||
Pod::Spec.new do |s| | |||
s.name = "TagListView" | |||
s.version = "1.3.1" | |||
s.version = "1.3.2" |
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.
No need to bump version in a pr request.
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.
Fixed
TagListView/CloseButton.swift
Outdated
path.addLine(to: CGPoint(x: iconFrame.maxX, y: iconFrame.maxY)) | ||
path.move(to: CGPoint(x: iconFrame.maxX, y: iconFrame.minY)) | ||
path.addLine(to: CGPoint(x: iconFrame.minX, y: iconFrame.maxY)) | ||
// lineWidth/2 is so the edge of the stroke is not cut off |
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.
Can you refine the comments here?
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.
Done
TagListView/TagView.swift
Outdated
return hasOvalShape ? borderWidth : (paddingY / 2) + borderWidth | ||
} | ||
|
||
private var imagePaddingX: CGFloat { |
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.
imagePaddingX
should come first.
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.
Fixed!
TagListView/TagView.swift
Outdated
private var imagePaddingX: CGFloat { | ||
// If both the image and TagView are rounded, left indent by Y padding so image snugly fits on left side of TagView | ||
// If not, indent by half padding - full padding looks terrible. | ||
return hasOvalShape ? imagePaddingY : (paddingX / 2) |
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.
Could you explain how to calculate these paddings?
Also, is it possible to make these padding options @IBInspectable
?
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'll update this PR w/ better comments explaining the equaitons shortly.
As for @IBInspectable
, since this is a computed variable I'm not sure it makes sense to have it be @IBInspectable
.
return hasOvalShape ? imagePaddingY : (paddingX / 2) | ||
} | ||
|
||
private var imageWidth: CGFloat { |
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.
Here, you are assuming image in this tag view is always rounded. Is it better to leave an option for developers?
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 recognize that's an assumption I made here. Another assumption was that if you have an image and an oval pill, you want the image tucked up on the side (as in the sample image).
The only way around that I think would be to do a new boolean flag. It would be fairly easy to add a boolean to the project for isImageFlushWithBorder
(or some better-named version of that), and then use that rather than my computed hasOvalShape
. I didn't want to go that heavy-handed with another group's project, but if that's the desired route I can update all this.
} | ||
|
||
private var hasOvalShape: Bool { | ||
return layer.cornerRadius == self.frame.height / 2 |
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.
Naming hasOvalShape
is not appropriate here.
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.
Can you explain more? The computed variable, or the specific name of it?
private var imagePaddingY: CGFloat { | ||
// If both image and TagView are rounded, image should fit snugly into corner. | ||
// If not, image should still be larger than text. | ||
return hasOvalShape ? borderWidth : (paddingY / 2) + borderWidth |
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.
Is there any top/bottom/left/right padding? Maybe using an UIEdgeInsets
is much better here.
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.
This padding is for manual layout of the entire tag, so I was following that convention. With all the manual layout that is happening, throwing in UIEdgeInsets
seems like it would add more confusion here. What do you think?
TagListView/TagView.swift
Outdated
@@ -176,6 +196,8 @@ open class TagView: UIButton { | |||
|
|||
let longPress = UILongPressGestureRecognizer(target: self, action: #selector(self.longPress)) | |||
self.addGestureRecognizer(longPress) | |||
|
|||
imageView?.contentMode = .scaleAspectFit |
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.
Do we have other options for contentMode
?
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.
There are other options, we previously used the default, .scaleToFill
. This was an accidental line that snuck in when I was hacking away, will be removed in the update coming shortly.
@@ -18,7 +18,7 @@ class ViewController: UIViewController, TagListViewDelegate { | |||
super.viewDidLoad() | |||
|
|||
tagListView.delegate = self | |||
tagListView.addTag("TagListView") | |||
tagListView.addTag("TagListView", image: #imageLiteral(resourceName: "missing_person")) |
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.
Good to see #imageLiteral
👍
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.
😄
Feedback changes from upstream PR
Merge upstream changes
Upgraded the Pod to Swift 5
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.
hsafah h
This adds the ability to put an image on the left side of
TagView
s. If theTagView
is oval, the image is snug with the border. If it's not perfectly oval, it is larger than the text but still has some padding.