Post

Replies

Boosts

Views

Activity

Sign in with Apple button dark mode in Swift
I implemented Sign in with Apple but in all cases the button is always black. I would like to show it in light/ dark mode depending on the phone settings. This is my code: class MyAuthorizationAppleIDButton: UIButton { private var authorizationButton: ASAuthorizationAppleIDButton! @IBInspectable var cornerRadius: CGFloat = 3.0 @IBInspectable var authButtonType: Int = ASAuthorizationAppleIDButton.ButtonType.default.rawValue @IBInspectable var authButtonStyle: Int = ASAuthorizationAppleIDButton.Style.black.rawValue override public init(frame: CGRect) { super.init(frame: frame) } required public init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) } override public func draw(_ rect: CGRect) { super.draw(rect) // Create ASAuthorizationAppleIDButton authorizationButton = ASAuthorizationAppleIDButton(authorizationButtonType: .signIn, authorizationButtonStyle: .black) let type = ASAuthorizationAppleIDButton.ButtonType.init(rawValue: authButtonType) ?? .default let style = ASAuthorizationAppleIDButton.Style.init(rawValue: authButtonStyle) ?? .black authorizationButton = ASAuthorizationAppleIDButton(authorizationButtonType: type, authorizationButtonStyle: style) authorizationButton.cornerRadius = cornerRadius // Show authorizationButton addSubview(authorizationButton) // Use auto layout to make authorizationButton follow the MyAuthorizationAppleIDButton's dimension authorizationButton.translatesAutoresizingMaskIntoConstraints = false NSLayoutConstraint.activate([ authorizationButton.topAnchor.constraint(equalTo: self.topAnchor, constant: 0.0), authorizationButton.leadingAnchor.constraint(equalTo: self.leadingAnchor, constant: 0.0), authorizationButton.trailingAnchor.constraint(equalTo: self.trailingAnchor, constant: 0.0), authorizationButton.bottomAnchor.constraint(equalTo: self.bottomAnchor, constant: 0.0), ]) } } So basically with the code above, I can set on Storyboard the style of the button but it seems that even if I change the value at my code, the result is based on what I chose on Storyboard's variable. Is there any solution where I would be able to show the button in light/ dark mode depending on the phone settings ?
2
1
941
Jul ’23
Different background colour on Cancel action of UIAlertController with actionSheet style
I have a UIAlertController with preferred style actionSheet and a cancel action with cancel style. The issue I have is that as you can see from the image below, the background colour of the cancel action is slightly different from the other actions. This is the piece of code I have: let alert = UIAlertController(title: alertTitle, message: message, preferredStyle: .actionSheet) let defaultAction = UIAlertAction(title: defaultTitle1, style: .default, handler: { (_) in self.baseDelegate?.defaultButtonPressed() }) let default2Action = UIAlertAction(title: defaultTitle2, style: .default, handler: { (_) in self.baseDelegate?.default2ButtonPressed() }) let cancelAction = UIAlertAction(title: cancelTitle, style: .cancel, handler: { (_) in self.baseDelegate?.cancelButtonPressed() }) alert.setValue(NSAttributedString(string: alert.title!, attributes: [NSAttributedString.Key.font : UIFont.init(name: "SF Compact Display", size: 18) ?? UIFont.systemFont(ofSize: 18.0, weight: .regular), NSAttributedString.Key.foregroundColor : UIColor(named: "Grey#444444") ?? UIColor(red: 68, green: 68, blue: 68, alpha: 1)]), forKey: "attributedTitle") alert.setValue(NSAttributedString(string: alert.message!, attributes: [NSAttributedString.Key.font : UIFont.init(name: "SF Compact Display", size: 13) ?? UIFont.systemFont(ofSize: 13.0, weight: .regular), NSAttributedString.Key.foregroundColor : UIColor(named: "Grey#444444") ?? UIColor(red: 68, green: 68, blue: 68, alpha: 1)]), forKey: "attributedMessage") defaultAction.setValue(UIColor(named: "Blue#007AFF"), forKey: "titleTextColor") default2Action.setValue(UIColor(named: "Grey#444444"), forKey: "titleTextColor") cancelAction.setValue(UIColor(named: "Grey#444444"), forKey: "titleTextColor") alert.addAction(defaultAction) alert.addAction(default2Action) alert.addAction(cancelAction) self.present(alert, animated: true, completion: nil) } I have run the app on simulator and a device and the result is the same. Do you know how I can have the same background colour on all of my actions ?
0
0
898
Jun ’23
Items are not updated on UI after updating them in Core Data
Hi there! I have an issue with UI when updating items in Core Data. Let's say I have three screens A, B and C where A --> B --> C. On screen A, I have a tableView with items from Core Data. On screen C, I have to make some changes on items of Core Data such as update or remove them. So, when I go back to screen A and refresh the tableView in order to get the updated list, the UI is not updated. I debugged the code and I can see that Core Data are correctly updated. Do you know what the issue is and why the UI is not updated but Core Data is up to date?
8
1
1.5k
Mar ’23