I have a number of apps which use a custom tab-bar for navigation. The tab-bar uses buttons with an ICON on top and text below. I have this working in Xcode 12.5 with an extension similar to those below. I wanted to see if I could convert to Xcode 13 and take advantage of the new button configurations. I was having some problems getting this to work properly so I did the following testing.
I created a new empty project in Xcode 12.5.1. Closed and re-opened the app in Xcode 13 and added two plain buttons. I didn’t change any of the attributes in the IB so they just have a blue button text. Then I attached one of the extensions below to each button. When the app opens in iSO 15 the buttons display the correct style. However, when either of the buttons is tapped the display reverts back to the text attributes of the button in the IB. So it’s blue, the text reads button and the text size changes back to the default. The ICON and the positioning remain unchanged.
If I create a new Xcode 13 project and do the exact same thing then everything working fine. Is anybody else seeing this? Is there something I need to change something in the extensions to make it work in pre 13 Xcode?
@available(iOS 15.0, *)
extension UIButton
{
func settings_MenuBtn()
{
self.configuration = .plain()
let imageConfig = UIImage.SymbolConfiguration(scale: .large)
self.configuration?.title = "Settings"
self.configuration?.attributedTitle?.foregroundColor = .white
self.configuration?.imagePlacement = .top
self.configuration?.titleAlignment = .center
self.configuration?.imagePadding = 6
self.configuration?.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0)
self.configuration?.image = UIImage(systemName: "gearshape", withConfiguration: imageConfig)
self.configuration?.attributedTitle?.font = .systemFont(ofSize: gMenuTextSize, weight: .regular)
}
}
@available(iOS 15.0, *)
extension UIButton.Configuration
{
static func settings_MenuBtn2() -> UIButton.Configuration
{
let imageConfig = UIImage.SymbolConfiguration(scale: .large)
var config: UIButton.Configuration = .plain()
config.title = "Settings"
config.attributedTitle?.foregroundColor = .white
config.attributedTitle?.font = .systemFont(ofSize: gMenuTextSize, weight: .regular)
config.image = UIImage(systemName: "gearshape", withConfiguration: imageConfig)
config.imagePlacement = .top
config.titleAlignment = .center
config.imagePadding = 6
config.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0)
return config
}
}