Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Simple iPhone App with Swift Improving Our User Interface Adding a Pop of Color

Charutha Bandara
Charutha Bandara
5,958 Points

Tint color changes but background color does not.

I just added an iAd Banner to experiment with to the bottom of my Main.storyboard and now my background color of the application will no longer change from the default color but the tint color does change.

Here is my ViewController.swift

import UIKit
import iAd

class ViewController: UIViewController, ADBannerViewDelegate {

    @IBOutlet weak var adBannerView: ADBannerView!
    @IBOutlet weak var funFactLabel: UILabel!
    @IBOutlet weak var funFactButton: UIButton!

    let factBook = FactBook()
    let colorWheel = ColorWheel()

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.


        self.canDisplayBannerAds = true
        self.adBannerView?.delegate = self
        self.adBannerView?.hidden = true


        funFactLabel.text = factBook.randomFact()

    }

    func bannerViewWillLoadAd(banner: ADBannerView!) {

    }

    func bannerViewDidLoadAd(banner: ADBannerView!) {
        self.adBannerView?.hidden = false
    }

    func bannerViewActionDidFinish(banner: ADBannerView!) {

    }

    func bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave: Bool) -> Bool {

        return true
    }

    func bannerView(banner: ADBannerView!, didFailToRecieveAdWithError error: NSError!) {

    }



    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    @IBAction func showFunFact(sender: AnyObject) {

        var randomColor = colorWheel.randomColor()
        view.backgroundColor = randomColor
        funFactButton.tintColor = randomColor
        funFactLabel.text = factBook.randomFact()



    }

}

and here is my debug console log:

2015-01-09 05:32:59.717 Daily Facts[76244:1075554] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSLayoutConstraint:0x7cbd9390 H:[UILabel:0x7cbd9400'Karoke means 'empty orche...'(216)]>",
    "<NSLayoutConstraint:0x7cbdbef0 UILabel:0x7cbd9400'Karoke means 'empty orche...'.leading == UIView:0x7cbdac20.leadingMargin + 36>",
    "<NSLayoutConstraint:0x7cbdbf20 UIView:0x7cbdac20.trailingMargin == UILabel:0x7cbd9400'Karoke means 'empty orche...'.trailing + 36>",
    "<NSLayoutConstraint:0x7b692b30 'UIView-Encapsulated-Layout-Width' H:[UIView:0x7cbdac20(320)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7cbd9390 H:[UILabel:0x7cbd9400'Karoke means 'empty orche...'(216)]>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2015-01-09 05:32:59.718 Daily Facts[76244:1075554] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSLayoutConstraint:0x7cbd2c50 H:[UIButton:0x7cbd3a70'Next Daily Fact'(216)]>",
    "<NSLayoutConstraint:0x7cbdbf80 UIView:0x7cbdac20.trailingMargin == UIButton:0x7cbd3a70'Next Daily Fact'.trailing + 36>",
    "<NSLayoutConstraint:0x7b692b30 'UIView-Encapsulated-Layout-Width' H:[UIView:0x7cbdac20(320)]>",
    "<NSLayoutConstraint:0x7cbdbfb0 UIButton:0x7cbd3a70'Next Daily Fact'.leading == UIView:0x7cbdac20.leadingMargin + 36>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7cbd2c50 H:[UIButton:0x7cbd3a70'Next Daily Fact'(216)]>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

2 Answers

Mathieu Grenier
PLUS
Mathieu Grenier
Courses Plus Student 8,997 Points

only thing i mess with this tintColor is "textColor" ! Set textColor "Default". My problem is fixed because color never changed and stay which color was for "textColor" Retry

Hey Charutha,

It looks likes your constraints are all messed up. That could be the problem or it could be to do with how the referencing of the view is occurring.

I see that your tint works but your background color does not. That could mean that your background view is being obstructed by something?

These are all shots in the dark though and without having your code to debug I can't say. Fix those constraints to see if that works, it could be that because your constraints are breaking, it is forcing the adbanner to be fullscreen and therefore blocking the background. This is possible if your adBanner is behind every other element in your IB.

Thanks, Alex