I'm sure I set right images for different states. But the UIButtons looks not good. Like this:
Anyone knows why? Many thanks in advance!
change from system to Custom then try ,
[UIButton buttonWithType:UIButtonTypeCustom];
I didn't enter any words(including while space) in all states.I made tint color white.It worked.And I think maybe this is caused by auto layout.
Related
I have problem when in iOS settings is enabled this setting "Button Shapes"
It causing this underline in application (first picture with enabled setting, second without)
Any idea how to programatically or in storyboard disable it?
I tried attributed text but I get same result :(
I'm newbie in Swift.
Thanks for help!
It's not a problem. You should not make any attempt to counter any accessibility changes set by the user. They are there for a reason.
This is an answer by user4291543 from this question Remove underline on UIButton in iOS 7
[yourBtnHere setBackgroundImage:[[UIImage alloc] init] forState:UIControlStateNormal];
I found this answer works with SWFrameButton
And for all the others saying "Don't Do This", SWFrameButton is a very good example of when you would want to do this. I also think the OP's situation is a perfectly valid scenario as well...
I totally agree with #maddy's comment:
It's not a problem. You should not make any attempt to counter any accessibility changes set by the user. They are there for a reason.
But I did stumble on a way to accomplish the task at hand...
In addition to a UIButton, you'll also need to make a .png file that contains nothing (meaning the entire contents have an opacity of 0%). Go ahead and load that into your xcode project's assets.
Now go ahead and set the Button's Background to that image you just provided. (In my case, I called it clear) This will remove the underline from the button's text. However, now you can't see the boundaries of the button. This can be solved by changing the Background of the button's View. Go ahead and select any color for the View's Background property and now the background of the View visibly defines the button's boundaries. You're able to see this because your clear.png has an opacity of 0%.
see the Attributes inspector for UIButton here.
Rather than trying to defeat the underline by going to make a label perform some action via UITapGestureRecognizer, this allows you to still use a UIButton. Keeping inline with accessibility features to mark buttons for people that want to do that.
You could create a custom button class with a label (with clear color). If you set the text of this label instead it shouldn`t get an underline.
Are you sure you want to do that?
Apple added an accessibility feature to mark buttons for people that want to do that. Apple will probably reject your app because it defeats a system function meant to help the disabled.
I found the solution. All you have to do is set a picture as the background of the button. just pick a picture with the same color as the button you created.
I have some requirement to prepare a UI like Image 1:
But sometime i get it like(title disappeared)
I am not sure why this is happening.
The background image second has half transparent and half image(refresh image),there i need to show text.
EDIT
XIB settings:
Any idea or solution for this ?
OR
Please suggest some other way to achieve this.
I just found in the UIstoryboard, why don't you try in this way
You can configure this UIButton as your need with the title attributes, right ?
As per your comment => colour of the title will be configured from server.
Then may be it is also possible that sometimes you will get clearColor of your button's title from server so you not able to display title of button. For solve this issue you need to put condition such like,
if(ButtonTitleColor is "clearColor")
[myButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; // here set color whatever you want.
I checked out iPhone: How can I make a UITextField invisible but still clickable?, but the OP has something else going on and the answers didn't seem to help me out of my fix.
I have a UITextField in which the user has to enter text. Instead of the standard UITextField graphic, I want to use a lovely graphic that's been designed for that purpose. The user would still need to be able to enter text and see the text s/he's entering, but I need the textfield to be invisible so that the graphic can show from underneath it.
How can I do this? Or is there another way to do what I'm after?
Adding my comment as an answer. You can try this,
[textField setBackgroundColor:[UIColor clearColor]];
And then set the border style as UITextBorderStyleNone.
something like:
yourTextField.borderStyle = UITextBorderStyleNone;
should do it
Another solution would be hiding the UITextView itself and just adding a transparent button that will call the keyboard to display.
Otherwise, the other answers should work.
Easiest option is to do it in interface builder. Choose the first uitext field style with no border and that's it.
I try to make a simple calculator using Xcode 4 for iPhone. It is my very first iOS application.
I use several buttons with titles: 1, 2,...9, +, =, -...
But when I run the program in iOS simulation, some of the buttons do not show their titles (i.e. they have nothing written on them).
The buttons without the titles are somewhat random: majorly the ones at the bottom of the screen, but also one on the top. The other buttons show their titles normally.
What the hell?
I had the same experience while doing the iOS calculator app from the iTunes U Piazza course. I think it started when I moved some of the buttons. I checked in the MainStoryboard.storyboard file with text edit - it appears that the height constraint went missing from these buttons - not clear how/why
whatever the root cause , I was able to fix it only by deleting the buttons in question and recreating them in the xcode editor
Try simply copy and pasting the duff control - I had this problem after changing the view from inferred to retina 3.5
This can be fixed by turning off "AutoLayout" on the storyboard. more info here: https://stackoverflow.com/a/16556044/26510
Changing text type from attributed to plain worked for me.
Per Apple developer guide, you should not set either the button title label text or color directly as a property (for example, do not do this: myButton.titleLabel.text=#"SomeText" or myButton.titleLabel.textColor=[UIColor blackColor]).
Rather, you set them using the UIButton setter functionality, like this:
[myButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
...or like this:
[myButton setTitle:#"SomeText" forState:UIControlStateNormal];.
See the Apple guide.
I Figure it out that there are some reasons why this can happen. In my case the problem was that I was setting the background image as button image, so the text was right-shifted out of the bounds of the button.
I am working on a tab bar application which needs a global title bar with a setttings button attached. I have achieved adding an imageview to the main window, then a label, another image, and finally a button. However, I cannot get this button to fire an action. it is set up like this:
[settingsButton addTarget:self action:#selector(settings) forControlEvents:UIControlEventTouchupInside];
Then the action defined like:
-(void)settings{
NSLog(#"please do something");
}
However nothing happens, the image doesn't even change like it is being pressed. Can i not define buttons in the app delegate this way? is it because the target is not something that is control based? i tried different targets but i must not fully understand what setting a target is. thanks for any help.
P.S.- i tried setting up the method like so as well:
-(void) settings:(id)sender{
}
and calling it by replacing the action with #selector(settings:) to no avail. Thank you.
I solved it. I forgot I changed the view behind the button to a UIImageView. I can't believe I didn't think of this before since this same issue cost me 2 hours the other day. When you have an imageView always remember to set this flag if you want stuff on it:
(someImageView).userInteractionEnabled = YES;
Hopefully I save someone an hour or two of needless headaches.
P.S. Thanks for the speedy comment !