I was having trouble changing font size in my project, so I made a playground. No matter where I put the font.withSize property, the simulator does not reflect the font size change.
import UIKit
import PlaygroundSupport
class MyViewController : UIViewController {
override func loadView() {
let view = UIView()
view.backgroundColor = .white
let label = UILabel()
label.font.withSize(80)
label.frame = CGRect(x: 150, y: 200, width: 200, height: 20)
label.text = "Hello Mom!"
label.textColor = .black
view.addSubview(label)
self.view = view
}
}
Changing the Xcode Font SizePress CMD + , Go to Font & Colors. Make sure to press CMD+A to select all possible text types. Then change the font size from the picker above.
withSize(_:)
does not modify the font. It returns a new font with the same properties as the font you called it on, but with the new size. You have to assign the label's font to it instead:
label.font = label.font.withSize(80)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With