简体   繁体   中英

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. 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

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

Note: You missed out the property font in your code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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