Skip to content
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

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open

Conversation

mcleinman
Copy link

This adds the ability to put an image on the left side of TagViews. If the TagView 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.

screen capture 8

@@ -19,3 +19,6 @@ DerivedData

# CocoaPods
Pods/
/TagListViewDemo/Images.xcassets/.DS_Store
Copy link
Collaborator

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_Stores from the repository.

ref: https://stackoverflow.com/questions/18393498/gitignore-all-the-ds-store-files-in-every-folder-and-subfolder

@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "TagListView"
s.version = "1.3.1"
s.version = "1.3.2"
Copy link
Collaborator

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

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
Copy link
Collaborator

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?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

return hasOvalShape ? borderWidth : (paddingY / 2) + borderWidth
}

private var imagePaddingX: CGFloat {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imagePaddingX should come first.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

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)
Copy link
Collaborator

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?

Copy link
Author

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 {
Copy link
Collaborator

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?

Copy link
Author

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
Copy link
Collaborator

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.

Copy link
Author

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
Copy link
Collaborator

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.

Copy link
Author

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?

@@ -176,6 +196,8 @@ open class TagView: UIButton {

let longPress = UILongPressGestureRecognizer(target: self, action: #selector(self.longPress))
self.addGestureRecognizer(longPress)

imageView?.contentMode = .scaleAspectFit
Copy link
Collaborator

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?

Copy link
Author

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"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to see #imageLiteral 👍

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😄

@Cee Cee added the enhancement label Aug 1, 2018
Copy link

@wioiwo37 wioiwo37 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hsafah h

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants