我有一个Master-DetailView项目,我需要通过数组更改按钮的标题,就像我在这里一样:
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]
ProfilePhoneNumberLabel.setTitle(ProfilePhoneNumbers[MyIndex], for: UIControlState.normal)
和它有所改变。
有没有办法做这样的事情?若有,有人可以告诉我该怎么做? 提前谢谢
答案 0 :(得分:2)
嗯....这很尴尬,但你必须在故事板中将你的UIButton标题设置为Plain才能让它改变
ProfilePhoneNumberLabel.setTitle(PhoneNumbers[MyIndex], for: .normal)
+
普通UIButton
标题
=
快乐露营者
答案 1 :(得分:1)
以下是设置ProfilePhoneNumberLabel
ProfilePhoneNumberLabel.setTitle(PhoneNumbers[MyIndex], for: .normal)
for
参数允许您在各种状态下设置按钮的文本。在大多数情况下,设置normal
状态的标题应该足够了。