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

you can add code to hashtag and you can press tag to act something #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions Hashtags/Classes/Hashtag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@ extension Array where Element: Equatable {

open class HashTag: Equatable {

open var text: String
open var isRemovable: Bool
open var hasHashSymbol: Bool
open var configuration: HashtagConfiguration?
open var code : String
open var text : String
open var isRemovable : Bool
open var hasHashSymbol : Bool
open var configuration : HashtagConfiguration?

public init(word: String, withHashSymbol: Bool = true, isRemovable: Bool = false) {
self.text = word
self.isRemovable = isRemovable
public init(word: String, code: String, withHashSymbol: Bool = true, isRemovable: Bool = false) {
self.text = word
self.code = code
self.isRemovable = isRemovable
self.hasHashSymbol = withHashSymbol

if hasHashSymbol {
Expand Down
26 changes: 13 additions & 13 deletions Hashtags/Classes/HashtagCollectionViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ open class HashtagCollectionViewCell: UICollectionViewCell {

static let cellIdentifier = "HashtagCollectionViewCell"

var paddingLeftConstraint: NSLayoutConstraint?
var paddingRightConstraint: NSLayoutConstraint?
var paddingTopConstraint: NSLayoutConstraint?
var paddingBottomConstraint: NSLayoutConstraint?
var paddingLeftConstraint : NSLayoutConstraint?
var paddingRightConstraint : NSLayoutConstraint?
var paddingTopConstraint : NSLayoutConstraint?
var paddingBottomConstraint : NSLayoutConstraint?

lazy var wordLabel : UILabel = {
let lbl = UILabel()
lbl.textColor = UIColor.white
lbl.textAlignment = .center
let lbl = UILabel()
lbl.textColor = UIColor.white
lbl.textAlignment = .center
lbl.translatesAutoresizingMaskIntoConstraints = false
return lbl
}()
Expand Down Expand Up @@ -63,18 +63,18 @@ open class HashtagCollectionViewCell: UICollectionViewCell {
}

open func configureWithTag(tag: HashTag, configuration: HashtagConfiguration) {
self.hashtag = tag
self.hashtag = tag
wordLabel.text = tag.text

self.paddingLeftConstraint!.constant = configuration.paddingLeft
self.paddingTopConstraint!.constant = configuration.paddingTop
self.paddingLeftConstraint!.constant = configuration.paddingLeft
self.paddingTopConstraint!.constant = configuration.paddingTop
self.paddingBottomConstraint!.constant = -1 * configuration.paddingBottom
self.paddingRightConstraint!.constant = -1 * configuration.paddingRight
self.paddingRightConstraint!.constant = -1 * configuration.paddingRight

self.layer.cornerRadius = configuration.cornerRadius
self.backgroundColor = configuration.backgroundColor
self.backgroundColor = configuration.backgroundColor

self.wordLabel.textColor = configuration.textColor
self.wordLabel.font = UIFont.systemFont(ofSize: configuration.textSize)
self.wordLabel.font = UIFont.systemFont(ofSize : configuration.textSize)
}
}
20 changes: 10 additions & 10 deletions Hashtags/Classes/HashtagConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
import Foundation

open class HashtagConfiguration {
var paddingLeft: CGFloat = 0.0
var paddingTop: CGFloat = 0.0
var paddingRight: CGFloat = 0.0
var paddingBottom: CGFloat = 0.0
var removeButtonSize: CGFloat = 0.0
var removeButtonSpacing: CGFloat = 0.0
var cornerRadius: CGFloat = 0.0
var textSize: CGFloat = 0.0
var textColor = UIColor()
var backgroundColor = UIColor()
var paddingLeft : CGFloat = 0.0
var paddingTop : CGFloat = 0.0
var paddingRight : CGFloat = 0.0
var paddingBottom : CGFloat = 0.0
var removeButtonSize : CGFloat = 0.0
var removeButtonSpacing : CGFloat = 0.0
var cornerRadius : CGFloat = 0.0
var textSize : CGFloat = 0.0
var textColor = UIColor()
var backgroundColor = UIColor()
}
61 changes: 25 additions & 36 deletions Hashtags/Classes/HashtagView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import AlignedCollectionViewFlowLayout

// MARK: Class

@IBDesignable
open class HashtagView: UIView {

private var sizingLabel = UILabel(frame: .zero)
Expand All @@ -30,7 +29,6 @@ open class HashtagView: UIView {

public var delegate: HashtagViewDelegate?

@IBInspectable
open var cornerRadius: CGFloat = 5.0 {
didSet {
self.layer.cornerRadius = self.cornerRadius
Expand All @@ -39,28 +37,24 @@ open class HashtagView: UIView {

// MARK: Container padding (insets)

@IBInspectable
open var containerPaddingLeft: CGFloat = 10.0 {
didSet {
setup()
}
}

@IBInspectable
open var containerPaddingRight: CGFloat = 10.0 {
didSet {
setup()
}
}

@IBInspectable
open var containerPaddingTop: CGFloat = 10.0 {
didSet {
setup()
}
}

@IBInspectable
open var containerPaddingBottom: CGFloat = 10.0 {
didSet {
setup()
Expand All @@ -69,70 +63,61 @@ open class HashtagView: UIView {

// MARK: Hashtag cell padding

@IBInspectable
open var tagPaddingLeft: CGFloat = 5.0 {
didSet {
self.collectionView.reloadData()
}
}

@IBInspectable
open var tagPaddingRight: CGFloat = 5.0 {
didSet {
self.collectionView.reloadData()
}
}

@IBInspectable
open var tagPaddingTop: CGFloat = 5.0 {
didSet {
self.collectionView.reloadData()
}
}

@IBInspectable
open var tagPaddingBottom: CGFloat = 5.0 {
didSet {
self.collectionView.reloadData()
}
}

@IBInspectable
open var tagCornerRadius: CGFloat = 5.0 {
didSet {
self.collectionView.reloadData()
}
}

@IBInspectable
open var textSize: CGFloat = 14.0 {
didSet {
self.collectionView.reloadData()
}
}

@IBInspectable
open var tagBackgroundColor: UIColor = .lightGray {
didSet {
self.collectionView.reloadData()
}
}

@IBInspectable
open var tagTextColor: UIColor = .white {
didSet {
self.collectionView.reloadData()
}
}


@IBInspectable
open var removeButtonSize: CGFloat = 10.0 {
didSet {
self.collectionView.reloadData()
}
}
@IBInspectable

open var removeButtonSpacing: CGFloat = 5.0 {
didSet {
self.collectionView.reloadData()
Expand All @@ -141,14 +126,12 @@ open class HashtagView: UIView {

// MARK: Hashtags cell margins

@IBInspectable
open var horizontalTagSpacing: CGFloat = 5.0 {
didSet {
setup()
}
}

@IBInspectable
open var verticalTagSpacing: CGFloat = 5.0 {
didSet {
setup()
Expand All @@ -174,9 +157,9 @@ open class HashtagView: UIView {
override open func prepareForInterfaceBuilder() {
super.prepareForInterfaceBuilder()

self.addTag(tag: HashTag(word: "hashtag"))
self.addTag(tag: HashTag(word: "hashtag", withHashSymbol: true, isRemovable: false))
self.addTag(tag: HashTag(word: "RemovableHashtag", isRemovable: true))
self.addTag(tag: HashTag(word: "hashtag", code: "hashtag"))
self.addTag(tag: HashTag(word: "hashtag", code: "hashtag", withHashSymbol: true, isRemovable: false))
self.addTag(tag: HashTag(word: "RemovableHashtag", code: "RemovableHashtag", isRemovable: true))
}

open override var intrinsicContentSize: CGSize {
Expand All @@ -202,16 +185,16 @@ open class HashtagView: UIView {

let configuration = HashtagConfiguration()

configuration.paddingLeft = self.tagPaddingLeft
configuration.paddingRight = self.tagPaddingRight
configuration.paddingTop = self.tagPaddingTop
configuration.paddingBottom = self.tagPaddingBottom
configuration.removeButtonSize = self.removeButtonSize
configuration.paddingLeft = self.tagPaddingLeft
configuration.paddingRight = self.tagPaddingRight
configuration.paddingTop = self.tagPaddingTop
configuration.paddingBottom = self.tagPaddingBottom
configuration.removeButtonSize = self.removeButtonSize
configuration.removeButtonSpacing = self.removeButtonSpacing
configuration.backgroundColor = self.tagBackgroundColor
configuration.cornerRadius = self.tagCornerRadius
configuration.textSize = self.textSize
configuration.textColor = self.tagTextColor
configuration.backgroundColor = self.tagBackgroundColor
configuration.cornerRadius = self.tagCornerRadius
configuration.textSize = self.textSize
configuration.textColor = self.tagTextColor

return configuration
}
Expand All @@ -229,13 +212,13 @@ open class HashtagView: UIView {
bottom: self.containerPaddingBottom,
right: self.containerPaddingRight)

self.collectionView.showsVerticalScrollIndicator = false
self.collectionView.showsVerticalScrollIndicator = false
self.collectionView.showsHorizontalScrollIndicator = false
self.collectionView.collectionViewLayout = alignedFlowLayout
self.collectionView.delegate = self
self.collectionView.dataSource = self
self.collectionView.backgroundColor = UIColor.clear
self.collectionView.isScrollEnabled = false
self.collectionView.collectionViewLayout = alignedFlowLayout
self.collectionView.delegate = self
self.collectionView.dataSource = self
self.collectionView.backgroundColor = UIColor.clear
self.collectionView.isScrollEnabled = false

self.collectionView.register(HashtagCollectionViewCell.self,
forCellWithReuseIdentifier: HashtagCollectionViewCell.cellIdentifier)
Expand Down Expand Up @@ -337,6 +320,12 @@ extension HashtagView: UICollectionViewDelegate, UICollectionViewDataSource {
cell.configureWithTag(tag: hashtag, configuration: makeConfiguration())
return cell
}

public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let hashtag: HashTag = self.hashtags[indexPath.item]

self.delegate?.didSelectTag(hashtag: hashtag)
}
}

extension HashtagView: UICollectionViewDelegateFlowLayout {
Expand Down
1 change: 1 addition & 0 deletions Hashtags/Classes/HashtagViewDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ import Foundation
public protocol HashtagViewDelegate: class {
func hashtagRemoved(hashtag: HashTag)
func viewShouldResizeTo(size: CGSize)
func didSelectTag(hashtag: HashTag)
}
26 changes: 13 additions & 13 deletions Hashtags/Classes/RemovableHashtagCollectionViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ open class RemovableHashtagCollectionViewCell: UICollectionViewCell {

static let cellIdentifier = "RemovableHashtagCollectionViewCell"

var paddingLeftConstraint: NSLayoutConstraint?
var paddingRightConstraint: NSLayoutConstraint?
var paddingTopConstraint: NSLayoutConstraint?
var paddingBottomConstraint: NSLayoutConstraint?
var removeButtonHeightConstraint: NSLayoutConstraint?
var removeButtonWidthConstraint: NSLayoutConstraint?
var removeButtonSpacingConstraint: NSLayoutConstraint?
var paddingLeftConstraint : NSLayoutConstraint?
var paddingRightConstraint : NSLayoutConstraint?
var paddingTopConstraint : NSLayoutConstraint?
var paddingBottomConstraint : NSLayoutConstraint?
var removeButtonHeightConstraint : NSLayoutConstraint?
var removeButtonWidthConstraint : NSLayoutConstraint?
var removeButtonSpacingConstraint : NSLayoutConstraint?

lazy var wordLabel : UILabel = {
let lbl = UILabel()
Expand Down Expand Up @@ -113,16 +113,16 @@ extension RemovableHashtagCollectionViewCell {
self.hashtag = tag
wordLabel.text = tag.text

self.paddingLeftConstraint!.constant = configuration.paddingLeft
self.paddingTopConstraint!.constant = configuration.paddingTop
self.paddingBottomConstraint!.constant = -1 * configuration.paddingBottom
self.paddingLeftConstraint!.constant = configuration.paddingLeft
self.paddingTopConstraint!.constant = configuration.paddingTop
self.paddingBottomConstraint!.constant = -1 * configuration.paddingBottom
self.removeButtonSpacingConstraint!.constant = configuration.removeButtonSpacing
self.removeButtonWidthConstraint!.constant = configuration.removeButtonSize
self.removeButtonWidthConstraint!.constant = configuration.removeButtonSize

self.layer.cornerRadius = configuration.cornerRadius
self.backgroundColor = configuration.backgroundColor
self.backgroundColor = configuration.backgroundColor

self.wordLabel.textColor = configuration.textColor
self.wordLabel.font = UIFont.systemFont(ofSize: configuration.textSize)
self.wordLabel.font = UIFont.systemFont(ofSize : configuration.textSize)
}
}