简体   繁体   English

外面触摸时如何更改按钮字体?

[英]How to change button font when touch up outside?

So I am trying to change the font of a button when it is pressed and then revert the font when the user touches up inside of another button. 因此,我试图在按下按钮时更改按钮的字体,然后在用户触摸另一个按钮内部时恢复字体。 Changing the font when a user touches up inside currently works but I created an outlet from storyboard for a touchUpOutside action and tried to recycle the code and it is not working. 目前,当用户在内部触摸时更改字体是可行的,但是我从情节提要中为touchUpOutside动作创建了一个出口,并尝试回收代码,但该代码不起作用。

@IBAction func touchUpInside(_ sender: AnyObject) {
    sender.titleLabel?!.font = UIFont(name: "Futura-CondensedExtraBold", size: 25)
}
@IBAction func touchUpOutside(_ sender: AnyObject) {
    sender.titleLabel?.font = UIFont(name: "Futura-Medium", size: 22)
}

Are you saying you have one button and when you touchUpInside the text font will change and when you touchUpOutside on the same button the text font will change to another font of revert back. 您是说有一个按钮,当您触摸touchUpInside时,文本字体将更改,而当您在同一按钮上触摸touchUpOutside时,文本字体将更改为另一种字体。

If this is the answer you were looking for don't forget to except the answer. 如果这是您要找的答案,请不要忘记答案。

// The Button As An Outlet
@IBOutlet weak var theButton: UIButton!

// The Button using Touch Up Inside
@IBAction func theButtonInside(_ sender: AnyObject) {
     sender.titleLabel?!.font = UIFont(name: "Futura-CondensedExtraBold", size: 25)
}

// The Button using Touch Up Outside
@IBAction func theButtonOutside(_ sender: AnyObject) {
    //This is a reference to the button as an outlet.
    theButton.titleLabel?.font = UIFont(name: "Futura-Medium", size: 22)
}

Revert font for button1 when pressing button2 按下button2时还原button1的字体

If this is the answer you were looking for don't forget to except the answer. 如果这是您要找的答案,请不要忘记答案。

//Button 1 as outlet.
@IBOutlet weak var button1Outlet: UIButton!

//Button 1 as touchUpInside.
@IBAction func button1(_ sender: AnyObject) {
    sender.titleLabel?!.font = UIFont(name: "Futura-CondensedExtraBold", size: 25)
}

//Button 2 as touchUpInside.
@IBAction func button2(_ sender: AnyObject) {

//Referenceing button 1 outlet.
    button1Outlet.titleLabel?.font = UIFont.systemFont(ofSize: 15.0)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM