Apple rejected my app because Stripe pod show inappropriate apple pay icon, which added an extra "apple pay" next to the apple pay icon. (see attached)
Is anyone had the same problem like me and what are your solution?
Is anyone had successfully uploaded an app with apple pay function installed?
Please See my calling code as below too, many thank!
private func reloadPaymentButtonContent() {
guard let selectedPaymentMethod = paymentContext.selectedPaymentOption else {
// Show default image, text, and color
paymentButton.setImage(#imageLiteral(resourceName: "Payment"), for: .normal)
paymentButton.setTitle("付款", for: .normal)
paymentButton.setTitleColor(.gray, for: .normal)
return
}
// Show selected payment method image, label, and darker color
paymentButton.setImage(selectedPaymentMethod.image, for: .normal)
paymentButton.setTitle(selectedPaymentMethod.label, for: .normal)
paymentButton.setTitleColor(.blue, for: .normal)
}
private func reloadBuyButton(){
if paymentContext.selectedPaymentOption == nil {
// buySubscriptionButton.backgroundColor = .loopGrayColor
// buySubscriptionButton.setTitle("订阅", for: .normal)
// buySubscriptionButton.setTitleColor(.white, for: .normal)
buySubscriptionButton.isEnabled = false
}else{
buySubscriptionButton.isEnabled = true
// buySubscriptionButton.backgroundColor = .loopGreenColor
// buySubscriptionButton.setTitle("订阅", for: .normal)
// buySubscriptionButton.setTitleColor(.white, for: .normal)
}
You're setting both in the code. So, either set Image or Label text.
Related
I have an application that needs to open third-party apps (i.e Whatsapp), it runs smoothly when I build this app using Xcode 10, but in Xcode 12, it's causing the freeze. Does anyone have to face this problem before?
My code was like this
declaring button
let buttonWA: UIButton = {
let v = UIButton()
v.imageView?.contentMode = .scaleAspectFit
v.setImage(UIImage(named: "ic_whatsapp"), for: .normal)
return v
}()
let buttonEmail: UIButton = {
let v = UIButton()
v.imageView?.contentMode = .scaleAspectFit
v.setImage(UIImage(named: "ic_email"), for: .normal)
return v
}()
Then I add some functions to be called each button
#objc func WaPressed() {
let no = "*************".urlwithPercentEscapes()
let urlWhatsApp = "whatsapp://send?phone=\(no)"
self.openUrl(urlString: urlWhatsApp)
}
#objc func EmailPressed() {
self.openUrl(urlString: "mailto:myEmail#gmail.com")
}
func openUrl(urlString: String) {
guard let url = URL(string: urlString) else {
return
}
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else {
UIApplication.shared.openURL(url)
}
}
Everything running smoothly, and open third apps very well, but when I returning back to my apps, it goes freeze without telling me anything
I've tried change ".normal" options to other options like ".application" etc in the line
v.setImage(UIImage(named: "ic_whatsapp"), for: .normal)
and it makes my apps running well again, but I need this "for: .normal" state so bad.
Then I've tried to change
v.setImage(UIImage(named: "ic_whatsapp"), for: .normal)
to
v.setBackgroundImage(UIImage(named: "ic_whatsapp"), for: .normal)
and it works, but then the image scale is messy.
Could anybody help me to solve this?
After trying other options, I figure it out with add RenderingMode when I set Image in my button, the code looks like this:
For whatsapp button
v.setImage(UIImage(named: "ic_whatsapp").withRenderingMode(.alwaysOriginal), for: .normal)
For email button
v.setImage(UIImage(named: "ic_email").withRenderingMode(.automatic), for: .normal)
I don't understand why I can't set "automatic / alwaysOriginal" both. But this way works for me.
Thankyou
I created the SwipingController app.
The application was supposed to have the functionality of scrolling with gestures and a management bar with 2 buttons and UIPageControl.
For now, these buttons were supposed to print only a text message in the console, but it doesn't.
let nextButton: UIButton = {
let button = UIButton(type: .system)
button.setTitle("NEXT", for: .normal)
button.setTitleColor(.black, for: .normal)
button.titleLabel?.font = UIFont.boldSystemFont(ofSize: 14)
button.addTarget(self, action: #selector(handleNextButton), for: .touchUpInside)
return button
}()
#objc func handleNextButton() {
print("Next Botton Pressed")
}
I wanted to add the whole page management bar in a separate file.
When it goes to the main controller, the whole functionality work.
I don't want to paste all the code, so it gives a link to the git
https://github.com/SebaKrk/SwipingControllerProgrammatic.git
Picture from simulator
The Problem is that you set your target right in the setup code of your UIButton
let previousBotton : UIButton = {
let button = UIButton(type: .system)
button.setTitle("PREV", for: .normal)
button.setTitleColor(.black, for: .normal)
button.titleLabel?.font = UIFont.boldSystemFont(ofSize: 14)
button.addTarget(self, action: #selector(handlePreviousButton), for: .touchUpInside)
return button
}()
It seems like the self is not initialized at this point. Because this code is run before your init was run.
So you have to set the target of the Button after you called super.init then it works.
I have an app and I want to support 2 languages. English and Greek.
I have already localised the whole app and everything works perfect except the UI.
I want to change images based on the system language user has. It works fine on simulator but when I use my real device the app changes its language except the images.
This is my code for the change.
let language = NSLocale.current.identifier
override func viewDidLoad() {
super.viewDidLoad()
setupUI()
}
func setupUI() {
if language == "el_US" {
print(language)
scanBtn.setBackgroundImage(UIImage(named: "scanBtnGr"), for: .normal)
detoxBtn.setBackgroundImage(UIImage(named: "detoxGr"), for: .normal)
bioBtn.setBackgroundImage(UIImage(named: "bioBtn"), for: .normal)
searchBtn.setBackgroundImage(UIImage(named: "browseGr"), for: .normal)
captureBtn.setBackgroundImage(UIImage(named: "scanGr"), for: .normal)
uploadBtn.setBackgroundImage(UIImage(named: "uploadGr"), for: .normal)
}else{
print(language)
scanBtn.setBackgroundImage(UIImage(named: "scanBtn"), for: .normal)
detoxBtn.setBackgroundImage(UIImage(named: "detoxBtn"), for: .normal)
bioBtn.setBackgroundImage(UIImage(named: "bioBtn"), for: .normal)
searchBtn.setBackgroundImage(UIImage(named: "browseBtn"), for: .normal)
captureBtn.setBackgroundImage(UIImage(named: "scan"), for: .normal)
uploadBtn.setBackgroundImage(UIImage(named: "upload"), for: .normal)
}
}
I really don't know where is the problem because on the Simulator works perfect.
Changing the way you set those images as below can help.
scanBtn.setBackgroundImage(UIImage(named: NSLocalizedString(key: "scanBtnGr", comment: ""), for: .normal)
In this way, you won't have to worry about the target language code as well. You can remove if statement and define corresponding names in Localizable.strings file.
Besides, if you change the language of your app without terminating the app and changing the device language, please make sure that setupUI() function gets invoked one more time after the language switch. viewWillAppear may be a suitable place for it.
I recently asked a question here where I wanted to understand how to change the UIColor of a button's image. I followed #Dorian Roy's recommendation which was very clean and it worked well for my needs. While my specific question previously was around a single button, I would like to know how to change multiple UIBUttons. Can this be done? My thought would be to subclass a UIButton and initialize it to automatically change its image color. I can't quite grasp how to do this though.
Here is how I am currently performing this action and I am seeking a more elegant solution.
private func changeBtnColors() {
let ccStencil = creditCardBtn.imageView?.image?.withRenderingMode(.alwaysTemplate)
let planeStencil = planeBtn.imageView?.image?.withRenderingMode(.alwaysTemplate)
let towelStencil = towelBtn.imageView?.image?.withRenderingMode(.alwaysTemplate)
let carStencil = carBtn.imageView?.image?.withRenderingMode(.alwaysTemplate)
let trainStencil = trainBtn.imageView?.image?.withRenderingMode(.alwaysTemplate)
let graphStencil = graphBtn.imageView?.image?.withRenderingMode(.alwaysTemplate)
creditCardBtn.setImage(ccStencil, for: .normal)
planeBtn.setImage(planeStencil, for: .normal)
towelBtn.setImage(towelStencil, for: .normal)
carBtn.setImage(carStencil, for: .normal)
trainBtn.setImage(trainStencil, for: .normal)
graphBtn.setImage(graphStencil, for: .normal)
creditCardBtn.tintColor = UIColor.white
planeBtn.tintColor = UIColor.white
towelBtn.tintColor = UIColor.white
carBtn.tintColor = UIColor.white
trainBtn.tintColor = UIColor.white
graphBtn.tintColor = UIColor.white
}
The simplest way is create one array of UIButton and loop through all the elements.
let buttonArray = [creditCardBtn, planeBtn, towelBtn, carBtn, trainBtn, graphBtn]
buttonArray.forEach { button in
let image = button.imageView?.image?.withRenderingMode(.alwaysTemplate)
button.setImage(image, for: .normal)
button.tintColor = UIColor.white
}
You can also create extension of UIButton and put this settings code of Button in a function like this.
extension UIButton {
func setImageWithRandringMode() {
let image = self.imageView?.image?.withRenderingMode(.alwaysTemplate)
self.setImage(image, for: .normal)
self.tintColor = .white
}
}
And now simply call this function with forEach closure.
buttonArray.forEach { button in
button.setImageWithRandringMode()
}
I want to change the image of a UIButton for different states. To achieve this, I'm using:
btn.setImage(UIImage(named: "blabla"), for .normal)
and
btn.setImage(UIImage(named: blabla2), for .disabled)
This only makes some appear dimmed.
What did I do wrong? I just want to make my button appearance the same for different states, how?
(my button type - .system).
This helped me (swift 3.0)
btn.setImage(UIImage(named:"yourFriend")?.withRenderingMode(.alwaysOriginal), for: .normal)
btn.setImage(UIImage(named:"yourFriend")?.withRenderingMode(.alwaysOriginal), for: .disabled)
You just need to set one for the state. And if you don't set another image for different state. It would look the same in all state.
button.setImage(image, forState: .Normal)
How to change UIButton image in Swift
For display disabled button set image
let btn = UIButton(type: .Custom)
btn.setImage(UIImage(named: blabla2), for .disabled)
Then
btn.enabled = false // to display Disable image
btn.enabled = true // to display Normal image
private let button1: UIButton = {
let button = UIButton(type: .custom)
button.setImage(UIImage(named:"firstButtonNormalStateImage"), for: .normal)
button.setImagesetImage(UIImage(named:"firstButtonSelectedStateImage"), for: .selected)
return button
}()
private let button2: UIButton = {
let button = UIButton(type: .custom)
button.setImage(UIImage(named:"secondButtonNormalStateImage"), for: .normal)
button.setImage(UIImage(named:"secondButtonSelectedStateImage"), for: .selected)
return button
}()
// implement for example in viewDidLoad()
button1.addTarget(self, action: #selector(firstButtonDidTap), for: .touchUpInside)
button2.addTarget(self, action: #selector(secondButtonDidTap), for: .touchUpInside)
// trigger actions
#objc func firstButtonDidTap() {
button1.isSelected = true
button2.isSelected = false
}
#objc func secondButtonDidTap() {
button2.isSelected = true
button1.isSelected = false
}
For whoever is still having this issue (currently Xcode 10.0) with a Custom button, I found I was able to change the text and/or image if instead of:
myButton.setTitle("Hi", for: [.normal])
I used this:
myButton.setTitle("Hi", for: []) //remove specific states
I don't know why .normal was not working for me, even though the button was definitely enabled. But maybe this will save someone else a headache!
You can simply do this by StoryBoard as well.
Select the button, got to identity inspector and do the following:-
Firstly set the buttonType to custom instead of system.
Secondly choose state Config to lets say default and give the imageName in "image" attribute, similarly choose other state configs (Highlighted, disabled, selected etc.) and set images as required by you.
Then later in the code you just have to control and set the state of the button, and respective image will be shown to you.