简体   繁体   English

UIButton插座集标题Swift

[英]UIButton Outlet Set title Swift

I have set up an outlet as follows using a storyboard: 我使用情节提要板设置了以下出口:

@IBOutlet var completeButton: UIButton!



self.completeButton.titleLabel = UIFont (name: standardFont, size: 22.0)

give the error cannot assign to the result of this expression. 给出错误,不能将其赋给该表达式的结果。

Simple task but can't seem to get round this in swift. 简单的任务,但似乎无法很快解决。

You are missing out the font property and titleLabel needs to be unwrapped. 您丢失了font属性,并且需要解开titleLabel。 Try the following: 请尝试以下操作:

self.completeButton.titleLabel!.font = UIFont.systemFontOfSize(22.0)

@Melvin Wijenayaka: For your example, the UIFont constructor contains two parameters this will also work for you @Melvin Wijenayaka:以您的示例为例,UIFont构造函数包含两个参数,这对您也将起作用

self.completeButton!.titleLabel.font = UIFont(name: "System", size: 22.0)

Note: You missed out the property font in your code. 注意:您错过了代码中的属性字体。

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

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