Skip to content

Commit

Permalink
Prevent images to change button/item size (#193)
Browse files Browse the repository at this point in the history
Images are now subviews of the circle background view. 
Like that we can set the define hugging and content compression resistance priorities.

Fixes #191
  • Loading branch information
jjochen committed Feb 8, 2019
1 parent e3c23a9 commit 7477205
Show file tree
Hide file tree
Showing 49 changed files with 13 additions and 3 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion Sources/JJActionItem.swift
Expand Up @@ -218,7 +218,7 @@ fileprivate extension JJActionItem {

addSubview(titleLabel)
addSubview(circleView)
addSubview(imageView)
circleView.addSubview(imageView)

titleLabel.translatesAutoresizingMaskIntoConstraints = false
circleView.translatesAutoresizingMaskIntoConstraints = false
Expand Down Expand Up @@ -279,6 +279,11 @@ fileprivate extension JJActionItem {
constraints.append(titleLabel.bottomAnchor.constraint(lessThanOrEqualTo: bottomAnchor))

NSLayoutConstraint.activate(constraints)

imageView.setContentCompressionResistancePriority(.fittingSizeLevel, for: .horizontal)
imageView.setContentCompressionResistancePriority(.fittingSizeLevel, for: .vertical)
circleView.setContentHuggingPriority(.fittingSizeLevel, for: .horizontal)
circleView.setContentHuggingPriority(.fittingSizeLevel, for: .vertical)
}

func createDynamicConstraints() {
Expand Down
2 changes: 1 addition & 1 deletion Sources/JJFloatingActionButton+Animation.swift
Expand Up @@ -213,7 +213,7 @@ fileprivate extension JJFloatingActionButton {
group: DispatchGroup,
animated: Bool) {
let animation: () -> Void = {
self.imageView.transform = CGAffineTransform(rotationAngle: angle)
self.circleView.transform = CGAffineTransform(rotationAngle: angle)
}

UIView.animate(duration: settings.duration,
Expand Down
7 changes: 6 additions & 1 deletion Sources/JJFloatingActionButton.swift
Expand Up @@ -385,7 +385,7 @@ fileprivate extension JJFloatingActionButton {
layer.shadowRadius = 2

addSubview(circleView)
addSubview(imageView)
circleView.addSubview(imageView)

circleView.translatesAutoresizingMaskIntoConstraints = false
circleView.centerXAnchor.constraint(equalTo: centerXAnchor).isActive = true
Expand All @@ -407,6 +407,11 @@ fileprivate extension JJFloatingActionButton {
imageView.widthAnchor.constraint(lessThanOrEqualTo: circleView.widthAnchor, multiplier: imageSizeMuliplier).isActive = true
imageView.heightAnchor.constraint(lessThanOrEqualTo: circleView.heightAnchor, multiplier: imageSizeMuliplier).isActive = true

imageView.setContentCompressionResistancePriority(.fittingSizeLevel, for: .horizontal)
imageView.setContentCompressionResistancePriority(.fittingSizeLevel, for: .vertical)
circleView.setContentHuggingPriority(.fittingSizeLevel, for: .horizontal)
circleView.setContentHuggingPriority(.fittingSizeLevel, for: .vertical)

configureButtonImage()
}

Expand Down

0 comments on commit 7477205

Please sign in to comment.