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

Remove messageLabel and titleLabel #204

Closed
saidyuce opened this issue Jan 29, 2018 · 5 comments
Closed

Remove messageLabel and titleLabel #204

saidyuce opened this issue Jan 29, 2018 · 5 comments
Labels

Comments

@saidyuce
Copy link

Hi, thanks for the library, it's awesome! I was wondering if there is a way to remove both the messageLabel and titleLabel from the DefaultView? I'm not familiar with the programmatic constraint stuff. I don't mind having title and message in the constructor, just a simple solution to remove those areas from the view would be fine. Also as a feedback, I think it would be cool to have options to disable certain areas of the popup. Thanks.

@mwfire
Copy link
Member

mwfire commented Jan 30, 2018

Hey there! The default view controller is just a convenience view that resembles UIAlertController layout. For custom layouts, you can always pass a custom view controller. Moreover, title and message are optional and should take zero space if not provided.

Still, for custom layouts custom view controllers are the way to go.

@saidyuce
Copy link
Author

Thanks for the quick reply. I may go with the custom view controller approach then.

However, I didn't feel like title and message are optional since I tried passing in both "" and nil for them in the constructor and still they occupied empty space. I'm attaching a screenshot for title = nil and message = nil. Not an issue anymore as long as I can use a custom view controller, but just to let you know. Or am I missing something?

let popup = PopupDialog(title: nil, message: nil, image: UIImage(contentsOfFile: data[indexPath.row])!)

img_4660

@Xabchinsk
Copy link

Xabchinsk commented Feb 9, 2018

Unfortunately, that's feature is not presented at this time. Yes, you could pass a nil values as text, but there are constraints between imageview, title and message.

constraints += NSLayoutConstraint.constraints(withVisualFormat: "V:|[imageView]-(==30@900)-[titleLabel]-(==8@900)-[messageLabel]-(==30@900)-|", options: [], metrics: nil, views: views)

For achieving that result, your should reassemble those (30, 8, 30) constraints with zero values (modify source code).

@stale
Copy link

stale bot commented Mar 11, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Mar 11, 2018
@stale stale bot closed this as completed Mar 18, 2018
@aliondos
Copy link

I kinda got it to do what was needed with this code... I know it's not elegant... But it works.

In PopupDialogDefaultView.swift below the inits

    internal func setupViews(){
        translatesAutoresizingMaskIntoConstraints = false
        addSubview(imageView)
        addSubview(titleLabel)
        addSubview(messageLabel)
        setupConstraints()
    }

    var constToRemove: [NSLayoutConstraint] = [NSLayoutConstraint]()

    func setupConstraints(){
        if self.constToRemove.count > 0 {
            NSLayoutConstraint.deactivate(self.constToRemove)
            self.constToRemove.removeAll()
        }
        let views: [String: Any] = ["imageView": imageView, "titleLabel": titleLabel, "messageLabel": messageLabel] as [String: Any]
        self.constToRemove += NSLayoutConstraint.constraints(withVisualFormat: "H:|[imageView]|", options: [], metrics: nil, views: views)
        self.constToRemove += NSLayoutConstraint.constraints(withVisualFormat: "H:|-(==20@900)-[titleLabel]-(==20@900)-|", options: [], metrics: nil, views: views)
        self.constToRemove += NSLayoutConstraint.constraints(withVisualFormat: "H:|-(==20@900)-[messageLabel]-(==20@900)-|", options: [], metrics: nil, views: views)
        var const: String
        if self.titleLabel.text == nil {
            if self.messageLabel.text == nil {
                const = "V:|[imageView]-(==0@900)-[titleLabel]-(==0@900)-[messageLabel]-(==0@900)-|"
            } else {
                const = "V:|[imageView]-(==0@900)-[titleLabel]-(==25@900)-[messageLabel]-(==25@900)-|"
            }
        } else {
            if self.messageLabel.text == nil {
                const = "V:|[imageView]-(==25@900)-[titleLabel]-(==25@900)-[messageLabel]-(==0@900)-|"
            } else {
                const = "V:|[imageView]-(==30@900)-[titleLabel]-(==8@900)-[messageLabel]-(==30@900)-|"
            }
        }
        self.constToRemove += NSLayoutConstraint.constraints(withVisualFormat: const, options: [], metrics: nil, views: views)
        imageHeightConstraint = NSLayoutConstraint(item: imageView, attribute: .height, relatedBy: .equal, toItem: imageView, attribute: .height, multiplier: 0, constant: 0)
        if let imageHeightConstraint: NSLayoutConstraint = imageHeightConstraint {
            self.constToRemove.append(imageHeightConstraint)
        }
        NSLayoutConstraint.activate(self.constToRemove)
    }

And this in the image, title & message setters on PopupDialogDefaultViewController.swift

    standardView.setupConstraints()

Hope it helps someone out :)

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

No branches or pull requests

4 participants