UIButton image gets pixelated when highlighted - iphone

I have an UIButton (type:custom) in an UIView set up in the interface builder, add an image for the default state to it with retina sizes. When I try on my iPhone, I see the retina version of the image, when I highlight it by tapping it it gets pixelated while being highlighted.
The funny part is when I change the image of the UIButton by code, there is no pixelated error.
Does anyone know a workaround without loading all my button images by code? thnx!

In interface builder you can specify both regular state and highlighted state images: simply choose the required "State Config" and configure the button.
If you specified an image for Default state, and left the image for "Highlighted" state empty, and checked the "Highlighted Adjusts Image" property on, then the button will use the Default state image and gray it out when it's pressed.
However, if your Highlighted state image is also set, the button will use that instead of generating its own highlighting.
Other things to check: make sure both versions of the image are included in the project.
E.g. say you have "button_image.png" and "button_image#2x.png". Make sure both of them are in the project. Also when you specify the image in the interface builder, use the name of the standard definition image, cocoa will pick the 2x version automatically - i.e. you would put "button_image.png" as your button's image, not "button_image#2x.png"
Hope this helps

Related

Set toolbar button width appropriately in Interface Builder

I've created a blank project, and added a toolbar to the main window. To it, I've added two "Textured Rounded Button[s]" from the object library. I've left one as-is, and the other I've customized by setting the image.
At runtime, they look correct, with the correct width automatically inferred:
However, this doesn't match the interface builder preview:
The button's width was set when it used to have the title "Textured Rounded", but it didn't readjust its width after removing the title and adding the icon.
It bugs me that my IB preview and runtime UI don't match. Of course, I can hand-tweak the button width, but that:
Suggests to me I'm doing it wrong
Is going to break in the future, similar to how my mis-configured toolbar buttons started looking wonky in Big Sur.
What's the correct way to add a button to a toolbar, in interface builder?

Setting Button's Size in TinyMCE 4

I'm new with TinyMCE and trying to set the size of some of the buttons in the editor to small and some others' to medium, in TinyMCE 4.
I know about this property toolbar_items_size but this sets all the button's size small or medium. Instead, I'm trying to set the size property of the buttons in editor.buttons[] manually after the buttons get registered with the editor but before the theme gets initialized since the theme uses Factory.create() to create buttons & that sets class btn-<size> to the button, which sets its size.
I've looked into TinyMCE's code too but have not able to figure out a way to do so. Also, I've observed that all the editor's events get fired after the theme gets initialized, like BeforeSetContent,..etc.
I'm using modern theme.
Is there some way to achieve this?
Thanks.
TinyMCE simply does not support what you are trying to do - the buttons on the toolbar(s) are a uniform size. You can pick that uniform size (as you reference) but you can't mix buttons of different sizes on the toolbar.

UILabel automatically changes color

i'm facing a really strange problem: i have some UILabel in my view, which has a black background, so i set their text color to white in Interface Builder in order to see them, the problem is, when i run the app on the simulator or on my iphone with ios7 or iOS 6.1.3 i can update them without problems (for update i mean: myLabel.text = #"Something")
but when i run the app on my sister's iphone 3gs with iOS 6.0 at the moment i update them the font color turns black. It seems that on her phone the label can't remember the color set on IB.
Does anyone of you know why this happens?
Thanks
It sounds like you have set the label "type" to "Attributed" in Interface Builder.
If this is the case then it is not the label that holds the text colour. It is the text itself.
If you replace the text with something else then the default text color of black will be used.
If you want to continue using Attributed text then you need to add a "foregroundColor" attribute to the text before setting it to the label.
The easier way round this is to change the label type to "Plain" in Interface Builder.
Of course, this depends on you having set it to Attributed.
I think you shouldn't use default label color in the interface builder, just provide something else (black color or etc.).
I ran into a similar problem. Was stumping me completely, until I quit and relaunched the simulator. It wasn't enough to just close the window or rebuild. I had to cmd-q, then build and launch again. Magically fixed the issue. Annoying.. but worked for me

iOS - Interface Builder: UIButton title disappears when setting image

I have made a project previously where I set a UIButton to have both text and also an image (in interface builder).
I have created another project and I want to achieve the same thing, but when I set the button to have an image, the title disappears (it's not getting hidden behind the image).
I can't seem to figure out why this is so if anyone could shed some light on this subject I'd appreciate it!
Thanks.
Change your button to custom type. put the image on then put the text in.
You will need to put your own background on it, but at that point you will be able to use the edge settings to position both the text and the image.
Every button that I have with image and text is set to custom and ultimately has its own bg image as well.
Oh, another thing I use. Is the cornerRadius. To give the view the rounded effect like the buttons have by default.
saveButton.layer.cornerRadius = roundingNumber.floatValue;
Additionally you should be able to use the borderWidth and borderColor in conjunction with cornerRadius to get a button that looks quite similar to the original button
saveButton.layer.borderRadius = 1.0f;
saveButton.layer.borderColor = [[UIColor blueColor] CGColor];
// These are not the exact values (or maybe they are) but you get the idea.
hope that helps.
Correction
After Spending a little time investigating, it appears that when you put an image in the button. the text is shoved off to the right.
Use the edge settings to bring it back over the image.
With the button selected, Look in "Attributes Inspector" > Button > Edge > (Dropdown "Title")
the equasion I have come up with is
[Edge inset for Title] Left = -(imageWidth * 2)
This should Left align your title with the image that you have put in.
Custom positioning will need to be done to make it look correct.
This can be done entirely in the Interface Builder and you can use RoundedRect button style
Here are some images demonstrating the change.
Here I set the Button type to "Custom" to remove the border and background.
Here I set the Top and Left in the Edge set for "Title" (Title is an option in the drop down)
EDIT
Newest Xcode has moved the size settings to a new location
Just put the image in the background field instead. This way the text will appear in front of the image.
It sounds like you are setting the image for the button but not the background image so reverse that.
I noticed that if the UIButton colour is set to default, adding an image makes it white and thus invisible. Changing the colour manually makes it visible again.

set gradient colour (color) for uibutton background image iphone sdk

I have purchased the Glyphish set of icons.. but they are all dark. I was wondering if there's a way to set the PNG gradient colour when I set the image as the background of a UIButton?
I was thinking of something like when the button is disabled, it changes colour. Is there any way to replicate this functionality??
The simplest method would be to create copies of the icons you're using, and tint/modify them in your favorite image editor. Name the various images something like:
icon.png
icon-disabled.png
Then, you can set one image for each button state. In Interface Builder, just select the button and in the Inspector window you'll see a popup menu that says "Default State Configuration". The image(s) you specify here will be used for all the various button state by default. In the Background field, enter icon.png. Then select "Disabled State Configuration" from the menu and enter icon-disabled.png as the Background image. Be sure to set the menu back to Default State Configuration to avoid getting confused in future edits.
If you want to set the same programmatically, just use something like:
[myButton setBackgroundImage:[UIImage imageNamed:#"icon.png" forState:UIControlStateNormal];
[myButton setBackgroundImage:[UIImage imageNamed:#"icon-disabled.png" forState:UIControlStateDisabled];
It's possible to take an image and modify it programmatically with a gradient, but unless you're doing it all the time and modifying the gradient based on user input or something, you'll save yourself a lot of headaches and time by just doing it this way.
I Have some code for the gradient... if you want simple color for different states of the button.. i. e
selected, disabled and all.
You can create different configuration from the interface builder.
Code which I have will give you gradient color for button but then you check the status of the button to use different gradient colors..
Make your button backgrounds with this free app: http://itunes.apple.com/us/app/uibutton-builder/id408204223?mt=8