2 Replies
      Latest reply on Feb 12, 2019 6:12 AM by eskimo
      chessfish Level 1 Level 1 (0 points)

        why does the function call for this reference the state of the button as .normal or .highlighted and not as UIControlStateNormal which is what it says in the documentation?

        • Re: set title of UIKit Button.
          Claude31 Level 8 Level 8 (5,485 points)

          Can you explain your question ?

           

          why does the function call for this reference the state of the button as .normal or .highlighted and not as UIControlStateNormal

          What did you try exactly ?

          If you try

                    aButton.setTitle("Title", for: UIControlStateNormal)

          You get error:

               Use of unresolved identifier 'UIControlStateNormal'

          if you try

               aButton.setTitle("Title", for: UIControl.State.normal)

          you get errors:

               'UIControlState' has been renamed to 'UIControl.State'

               UIControlState' was obsoleted in Swift 4.2

          So, you need

               aButton.setTitle("Title", for: UIControl.State.normal)

           

           

          which is what it says in the documentation?

          Which documentation (which version of XCode ?) => Swift 4.2 has changed it.

           

          Note also Doc states:

          At a minimum, you should set the value for the normal state. If a title is not specified for a state, the default behavior is to use the title associated with the normal state. If the value for normal is not set, then the property defaults to a system value.

           

          So, you have not to set title for all states, normal will be used as default if needed.

          • Re: set title of UIKit Button.
            eskimo Apple Staff Apple Staff (10,695 points)

            not as UIControlStateNormal which is what it says in the documentation?

            Which documentation are you referring to here?  The documentation for the setTitle(_:) method uses the Swift name (normal) as long as you’re in Swift mode (which you can select via the menu at the top).

            Share and Enjoy

            Quinn “The Eskimo!”
            Apple Developer Relations, Developer Technical Support, Core OS/Hardware
            let myEmail = "eskimo" + "1" + "@apple.com"