Background property of UIButton - uibutton

I can see that there is a Background property in the Attributes Inspector of UIButton but how do I set it programmatically?
It is not background color or background image because I have tried setting these in code but it doesn't have the desired effect.

I used setBackgroundImage of UIButton

First, be sure to have a referencing outlet for your button then,
try, button.backgroundColor = UIColor.black of course the 'button' name may be diffrent for you and the color of choice may also be.
If this doesn't work for you for some reason this video may be of help: https://www.youtube.com/watch?v=9Vq_xckdJkQ

Related

Objective-C UIButton in UIView Hierarchy not animating

I have a ScrollView with multiple Subviews and somewhere down there two UIButtons. They are not covered by a different UIView and they are perfectly visible.
The problem now is that the buttons are working, but they are not getting the "pressed" look like all other buttons.
Is there a possibility to trigger that "pressed" animation manually or is there another workaround?
Make sure for those buttons in the Attributes inspector the "Type" is set to "System"

Override [UIButton Appearance] for one button

See subject. Is this possible? When I add a tint color with UIButton Appearance... it applies to all UIButtons, not just "System" buttons but even custom ones.
I just want to be able to set a couple of destructive buttons with red text while keeping a customizable tint color for everything else.
Check out UIAppearance appearanceWhenContainedIn.
This one provides way to customize appearance whenever your control is contained within specific view, such as UIToolbar or UINavigationBar. You may check up your own parent view class which contains your custom UIButton.

Change UIButton type programmatically

I have an UIButton made with IB, it is set to "Rounded Rect". At one point, I'd like to change the type to "Custom" in the code, is that possible ? I saw the type can be set at creation, but did not see if it was possible to change it later on.
If I'm not mistaken, different button types are represented by different (private) subclasses of UIButton. That's why you can only set type at creation time but not after.
I don't know if I'll be much help, but for me it worked by doing:
button = [UIButton buttonWithType:(UIButtonType)];
example:
calculateButton = [UIButton buttonWithType: UIButtonTypeRoundedRect];

iPhone: rotate the UIImageView inside a UIButton (Weird effect)

My problem is that I want to rotate the UIImageView of a UIButton.
The transformation itself is pretty easy:
super.imageView.transform = CGAffineTransformMakeRotation((M_PI*120)/180);
(I subclass a button, but it doesn't work with a normal button either.)
So, it rotates but looks not very pretty: http://img534.imageshack.us/img534/2796/afterh.png
As reference, this is the same imageView but not rotated:
http:// img704.imageshack.us/img704/1299/beforen.png (sorry for that whitespace, I'm new and can just post one link...)
Thanks for your help
Sebastian
Okay, i finally got it.
It was needed to set the clipsToBounds property of the imageView to NO.
Sebstian

UILabel inside a UIToolbar using IB is invisible on run, how fix?

I want to show a total inside a toolbar. I put in IB the UILabel on top of the toolbar .
However, when I run the app, the UILabel is totally invisible (but can set values on code fine).
The most bizarre thing is that in other form, all work fine. I don't see why in one form work but not in another...
Any idea in how fix this? Or why is this behaviour happening?
Don't use a UILabel.
Use a UIBarButtonItem. Then set it to style: plain. It looks like a label, but it actually borderless button. This is the general practice of displaying text on a bar.
You can also create UIBarButtonItem with a custom view in code. You are simple "wrapping" the UILabel in a UIBarButtonItem allowing you to add anything you want to a tool bar.
To add in response to comment:
Either way, you make the button "inactive" and it doesn't respond to touches. Even though it is a button, it doesn't appear to be one. This is how Apple expects to add views to a toolbar/navbar as apposed to "float things on top of it". It violates no HIG guidelines, much the opposite, it is a reccomended design technique.
To stop the glow:
Create the button programmatically, make sure it is disabled, add it to the bar, it should then be disabled, but not dim.
In IB, have you tried to select the label and use the "Bring to Font" menu item (under Layout)? It seems like you are trying to do something pretty standard.
When you try to set values, is the label coming up as nil or at address 0x0? It's possible that the label is there, but its text cannot be set because its instance is faulty (not properly connected in IB to the IBOutlet).... Just put a breakpoint on the line where you are trying to set the value(s) for the label, and verify that the label variable is not nil (or 0x0). If it's not, try setting the text and verify on the next line that its text was set properly.
drag a UIButton into your UIToolBar. Then uncheck User Interaction Enables for this button.
Customize your UIButton so that it will look like a UILabel. Hope this will help you.