UIButton font size isn't changing
In Xcode 13 ,UIButton has four type are Plain,Grain,Tinted,Filled
.When you create a button in storyboard , button type automatically set with Plain that means new UIButton configurations is on. If you want to old behaviour , you must set style plain
to default
.
Or , If you want one of the style above . You need to set font like
button.titleTextAttributesTransformer = UIConfigurationTextAttributesTransformer { incoming in
var outgoing = incoming
outgoing.font = UIFont.systemFont(ofSize: 50)
return outgoing
}
Changing text size of uibutton doesn't work
Swift 3.1
_loginButton.titleLabel?.font = _loginButton.titleLabel?.font.withSize(yourSize)
changing font size of UIButton
The reason that the code you're posting isn't working is probably because Arial isn't present in iOS. You can change the properties of a UIButton
's titleLabel
just like any other instance of UILabel
. Read about that here.
So, you can change the font size with something like:
button.titleLabel.font = [UIFont systemFontOfSize:14.0];
You can choose a font by name, but not all fonts are available on iOS. Here's a list of ones that are.
Can't change custom UIFont size on the UIButton
Interestingly enough, it turned out to be my Mac. When I gave my friend to install them, he had no issues.
My Mac is on the old side, so maybe this was the reason. Here are the specs:
**Mac:** MacBook Pro 15" (Late 2008)
**Processor:** 2.4 GHz Intel Core 2 Duo
**Memory:** 4 GB 1067 MHz DDR3
**Graphics:** NVIDIA GeForce 9600M GT 256 MB
How to change font of UIButton with Swift
Use titleLabel
instead. The font
property is deprecated in iOS 3.0. It also does not work in Objective-C. titleLabel
is label used for showing title on UIButton
.
myButton.titleLabel?.font = UIFont(name: YourfontName, size: 20)
However, while setting title text you should only use setTitle:forControlState:
. Do not use titleLabel
to set any text for title directly.
How insert new font and force the change in UIButton?
You need to add MyriadPro font to your project and to info.plist file for key UIAppFonts (Fonts provided by application). Then you can use your code to set font,
[botaoCadastrar.titleLabel setFont:[UIFont fontWithName:@"MyriadPro" size:18]];
Reason:
The MyriadPro font is not iOS default font. You can find default font list here,
- iOS 6 - http://support.apple.com/en-us/ht5484
- iOS 7 - http://support.apple.com/en-us/ht5878
UIButton does not resize height correctly with custom font when sizeToFit is called
In case anyone has the same problem and comes across this, I figured out a solution simply by subclassing UIButton. Then, I just modified layoutSubviews so that the titleLabel bounds equaled the button's subviews, and it no longer cut off the top part of the font. Not sure if it's the best way, but it works.
- (void)layoutSubviews
{
[super layoutSubviews];
self.titleLabel.bounds = self.bounds;
}
UIButton font size isn't changing
In Xcode 13 ,UIButton has four type are Plain,Grain,Tinted,Filled
.When you create a button in storyboard , button type automatically set with Plain that means new UIButton configurations is on. If you want to old behaviour , you must set style plain
to default
.
Or , If you want one of the style above . You need to set font like
button.titleTextAttributesTransformer = UIConfigurationTextAttributesTransformer { incoming in
var outgoing = incoming
outgoing.font = UIFont.systemFont(ofSize: 50)
return outgoing
}
How to change the size of an SF icon in a UIButton
You can use the Default Symbol Configuration
settings on the UIButton in the Attributes Inspector
to accomplish the same thing. All Credit to Andrew Kirna below. Thanks dude!
Success!!! I finally figured out how to do this, thanks to a great article on SF Symbols. It was certainly buried in there.
It would be really nice to resize your button images in storyboard wouldn't it? I thought so at least.
Add IconButton.swift to your project in Xcode.
import UIKit
@IBDesignable
class IconButton: UIButton {
@IBInspectable var pointSize:CGFloat = 30.0
override func layoutSubviews() {
super.layoutSubviews()
if #available(iOS 13.0, *) {
let config = UIImage.SymbolConfiguration(pointSize: pointSize)
setPreferredSymbolConfiguration(config, forImageIn: .normal)
} else {
// Fallback on earlier versions
}
}
}Create a button in storyboard with an SF icon as the image.
Go to the identity inspector and make the class of your button IconButton
Go to the attribute inspector and enter in your point size. Note that this the
height of the icon
x
3/4. I wanted a 40 x 40 icon, so my point size was 30.See your icon update in storyboard and laugh happily that you didn't spend 3 hours figuring this out :D
Some credit to the great article: https://www.avanderlee.com/swift/sf-symbols-guide/
Related Topics
Uibezierpath Appending Overlapping Isn't Filled
Timer Not Firing Every Second on Watchkit
How to Hide the Back Button from the Status Bar on the Apple Watch
Swift UI Test - User Notifications System Alert
How to Add Detect Button Presses in Tvos
When to Call Activatesession() on Wcsession Object
Swiftui: How to Find the Height of an Image and Use It to Set the Size of a Frame
How to Read File Data Applications Document Directory in Swift
How to Customize the Title/Subtitle Font in Callout from Mkannotationview or Just Hide Them
How to Convert an Anykeypath to a Writablekeypath
Why Specializing a Generic Function Explicitly Is Not Allowed
Swift Error with Generic Array
Swift Change the Tableviewcell Border Color According to Data
Get All Available Characters from a Font
Firebase iOS Receive Data from Push Notification
Is There a Github Markdown Language Identifier for Swift Code