0

I have a Master-DetailView project and i need to change a button's title by an array like i do here :

import UIKit
import AVFoundation
import MapKit

class TemplateTestViewController: UIViewController,MKMapViewDelegate {

    @IBOutlet var ProfileMapView: MKMapView!
    @IBOutlet var BarOrClubLabel: UILabel!
    @IBOutlet var HeaderProfileName: UILabel!
    @IBOutlet var HeaderprofileImage: UIImageView!
    @IBOutlet var StreetProfileLabel: UILabel!
    @IBOutlet var ProfilePhoneNumberLabel: UIButton!
    @IBOutlet var WorkTimeLabel: UILabel!
    @IBOutlet var AgeLabel: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()
        //Set Ups the Image Template :
        HeaderprofileImage.image = UIImage(named: ProfileImages[MyIndex])
        //Sets Up The BIG Name Template :
        HeaderProfileName.text = ProfileNames[MyIndex]
        //Sets Up The Navigation Bar Name :
        navigationItem.title = ProfileNames[MyIndex]
        //Sets Up Street Text :
        StreetProfileLabel.text = ProfileStreets[MyIndex]
        //Sets Up Bar Or Club Text :
        BarOrClubLabel.text = ProfileBarOrClub[MyIndex]
        //Sets Up Age Text :
        AgeLabel.text = AgeText[MyIndex]

I TRIED :

ProfilePhoneNumberLabel.setTitle(ProfilePhoneNumbers[MyIndex], for: UIControlState.normal)

AND IT DIDNT CHANGE.

is there a way to do something like that ? and if so can someone show me how to ? thanks ahead

Newbie Questions
  • 463
  • 1
  • 11
  • 31

2 Answers2

4

Well....This is awkward but you have to set your UIButton title to Plain in storyboard to have it changed

ProfilePhoneNumberLabel.setTitle(PhoneNumbers[MyIndex], for: .normal)

+

Plain UIButton Title

=

Happy Camper

Newbie Questions
  • 463
  • 1
  • 11
  • 31
1

Here's how you set the title for ProfilePhoneNumberLabel

ProfilePhoneNumberLabel.setTitle(PhoneNumbers[MyIndex], for: .normal)

The for parameter lets you set the text for the button in various states. In most cases, setting the title for the normal state should be enough.

Joey deVilla
  • 8,403
  • 2
  • 29
  • 15