Calling UIButton:setImage:forState makes button title disappear - ios

If I call UIButton:setImage:forState then the title text of my buttons is disappearing (set via UIButton:setTitle:forState).
If I don't call setImage:forState then the title appears perfectly.
If I set the button images in interface builder then the title does appear, so why does setting the images programmatically cause the titel to vanish?

Instead of calling setImage:forState:, you should call setBackgroundImage:forState:.

Related

iOS - Change backBarButton title when it says "Back"

Well, back bar buttons title changes to "Back" when title of the previous viewController is too long to fit the space within the button.
I want to change the title to something else when it says "Back", so I thought I can do something like that:
if navigationItem.backBarButtonItem.title == "Back" {
navigationItem.backBarButtonItem.title = "SomeThing"
}
But title (or its parent view) always returns nil.
Also, where to put the code: in the pushing or pushed viewController?
Thanks.
EDIT: The approved answer in the link
How to set back button text in Swift
is different, because I want to change the title only in the case it is too long to fit inside the button label.

Change ToolBar Title dynamically on click events in Fragment on Xamarin android?

First let me explain something, so you guys can understand better my problem:
I'm using Toolbar and i have a Fragment called Location Fragment where i have 6 floationg action button vertically .
When you click on one of the floating action button some action like geofence,live tracking,current location etc are performed on the same map fragment.
So my problem is that when i click any of the floation action button ,like when i click geo-fencing floation action button the title on the tool bar should change with the geofence title..In this way for all the Floating action button the title of toolbar should change. in my case the title of the tool bar is not changing .
I have tried to use setTitle or this.Activity.Title="Geo-fence" on the click method of Floating action button,but still it remains same title .
Change ToolBar Title dynamically on click events in Fragment
In your Fragment, add the following code in your click events :
((AppCompatActivity)Activity).SupportActionBar.SetTitle(Resource.String.YourTitle);
this.SupportActionBar.Title = "Your Title";

iOS get UINavigationBar's back button in order to set accessibility properties

I have a navigation controller stack where one of the views has a dynamic title.
The view controllers and their titles go like this:
Main --> ItemsTableView --> ItemDetails
Title:Main Title: NN Items Title: Details
Because the iOS UINavigationController sets the text of the "Back" button to be the title of the previous screen, the "Back" button on the details screen says "< NN Items" where NN is a dynamically changing number.
I'm trying to do some iOS UI automation, but the accessibility Label / ID of the back button is set by the system to it's button text. This means that the accessibility label of the back button on the details screen will change dynamically, and I can't find it from my scripts!
If I could get a reference to the UIBarButtonItem then I could easily set it's accessibilityLabel or accessibilityIdentifier from code to be a fixed string, however I can't figure out how to do this?
All of the stuff I've been able to find references setting the back button to a custom button via self.navigationItem.backBarButtonItem or similar, but when I read this property it's nil. I haven't been able to find out how to get access to the standard item without replacing it. I'd prefer not to replace the button if possible
This was bugging me as well. I've been writing Xcode 7 UI Tests and was trying to come up with a generic way of tapping on the back button without having to replace it with a custom button.
The following is how I solved this for Xcode 7 UI Tests - but you may also be able to apply this to UI Automation as well.
I discovered that (in terms of Xcode 7 UI Tests at least) the back bar button item that is created by the system consists of two buttons the entire thing is a button with an accessibility label of whatever the title of the button is, and then the arrow is also a button with an accessibility label of "Back".
Thus, as long as there aren't any other buttons on the screen that are identified as "Back", the back button can be accessed via the accessibility label of "Back". Like so in the case of UI Tests:
[[app.buttons matchingIdentifier:#"Back"] elementBoundByIndex:0]
Here I'm getting the first button that can be identified by "Back". I my case there could only ever be two such buttons - the arrow, or the whole back button itself (in the case where the back button's title is also "Back"). Since both of these buttons are essentially the same, just getting the first one it finds is sufficient.

UIButton selected content only when touched

Is it possible to see the selected state content of an UIButton only when I'm touching it?
When you're touching a button, the button is highlighted. Call setTitle:forState: to give the button the normal title (UIControlStateNormal), and call setTitle:forState: to give it the highlighted title (UIControlStateHighlighted). Now you'll see one title normally and the other title when you touch the button. The same thing for the other button features, like setImage:forState:.

How to display red "Cancel" button in UITableViewCell?

I am building a custom UITableViewCell which will be displayed while the user is downloading data from a web service, and which will include a "Cancel" button to allow them to cancel the URL connection. I'd like to emulate the look-and-feel of the "Delete" buttons which are displayed in the table editing view, like this:
How can I create such a red button which says "Cancel" instead of "Delete" in my custom UITableViewCell? It appears that the only type of button I can put in a UITableViewCell is a regular UIButton (UIBarButtonItem won't go anywhere except a UIToolbar), and Interface Builder doesn't give an option to create a red Delete-like button as a standard style.
In the end, I just had to create my own custom UITableViewCell, and use some Photoshop magic to figure out how to make a button that looks exactly like the iPhone Delete buttons, but saying "Cancel." It didn't take that much time.

Resources