UISwitch customization? - iphone

Is possible to add images to an UISwitch background,like when the state is ON (be one background) and when the state is OFF (another background image)?

To change the background color (not image) all you have to do is below. This changes the off color for all UISwitch controls in realm.
[[UISwitch appearance] setTintColor:[UIColor brownColor]];//Off Color
_locationSwitch.onTintColor = [UIColor orangeColor];//On Color
If you want to use image, use the following cool hack of using the segmented control.
https://stackoverflow.com/a/5088099/1705353
If you want to write a lot of code, you can write your own control. Valeriy Van pointed to: https://github.com/homick/iPhone-Snippets/tree/master/General
Also another resource is: http://www.raywenderlich.com/23424/photoshop-for-developers-creating-a-custom-uiswitch with code at: http://cdn2.raywenderlich.com/wp-content/uploads/2012/10/CustomSwitchResources.zip

I would like to suggest you to follow Custom UISwitch & App Store approval to have a better idea, which is suggesting you to create a custom switch control.

You can recreate a custom UISwitch by subclassing UIControl. By doing this you can have full control over what the switch looks like. You can look take a look at SevenSwitch. A custom UISwitch replacement I've created. The on/off colors can be customized to your liking.
https://github.com/bvogelzang/SevenSwitch

Related

Can I add a colored button to a UIToolbar?

It seems like I can't add any buttons that contain colors in a UIToolbar, they always get replaced with a white mask. How can I add a colored image to a custom button in a UIToolbar?
Yes you can, but its not really a uibarbuttonitem.
here is the link.
http://fredandrandall.com/blog/2011/03/31/how-to-change-the-color-of-a-uibarbuttonitem/
PS.
If you want to have an IBAction for that button, then call it on valuechanged event.
No, I dont think you can directly. It looks like it has to be as you said.
You might be able to hack things though by putting your image over the toolbar's image and letting the touch events pass through it by tweaking the hit testing.
Without using private API's, you can't. Apple will block your app if you use the private API's, so you might as well construct your own control and use that.
You can also look at the UIApperance protocol this is very useful for customising the look and feel of many of the UI elements. You can change a specific item or every instance of that item using the static method.
[[UIToolBar appearance] setTintColor:[UIColor blueColor]]
This would change every instance of a UIToolBar in your app blue.
You can use custom toolbar, where you can use any toolbar background and colored images: http://github.com/marichka/Custom-UIToolbar

How to design rounded boxes and separators (like the App Settings view)?

I am wondering what is the good way to design interfaces such as the one in the Settings view on an application, for instance :
What I want to do is the nice round rectangle to separate categories and horizontal line separators between categories, I can have a label, text field, slider or any other control in each line...
Do we need to use an image in the background, that seems quite dirty to me, and I cant find any control in IB that seem to do the same kind of layout.
So, how is this done?
Thanks!
Use a UITableView and set it's style to UITableViewStyleGrouped. Remember that the standard UITableViewCell's will just let you show some text and you may need to create custom UITableViewCell's to achieve more (for example, a on-off switch).
If you wan't to customise it you can add a background image. To do this, place a UIImageView behind the UITableView and make sure you set the UITableView background colour to clear:
theTableView.backgroundColor = [UIColor clearColor];
To seperate the categories make use of the "sections".
Basically, you can use grouped table.You can have sections with different/same number of rows.

How can I customize a UISwitch using my custom .png?

So in my code I used the setAlternateColor: method on my UISwitch to change the color to orange but my app got rejected because of this.
So I decided to use photoshop to create a custom UISwitch. Now that I have the image how am I supposed to get the UISwitch to use my custom .png?
You can't. It's probably easiest to write your own custom switch class. It's not very hard to subclass UIControl and reimplement the few things UISwitch does. (I don't know if it would also work to subclass UISwitch directly and override drawRect:. Might be worth a try.)

UITableViewCell action badge

Does anyone know how to implement an action badge, like the ones seen below with the price tags in them. The App Store has those too.
alt text http://m.macupdate.com/images/screens/uploaded/30815_scr.png
The easiest way is to set the accessoryView of a standard UITableViewCell to a UIView. You can just make them be standard UIButtons, set their background color and the label color and font.
If they're not meant to be interactive, then you can use a container UIView with a UIImageView in the background and a UILabel in the front added as subviews.
If you want to get fancy with it you'll have to subclass UITableViewCell and lay out the various bits yourself. It's not that difficult. The TableViewSuite sample code shows you how.
I am not sure there is anyway within the framework to create this type of button. You could fairly easily simulate it using your own custom images. What you want in this case is a stretchable image that does not distort as you resize the buttons.
Take a look at the following method on the UIImage class:
- (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight

How can I change the default color of the button on iPhone when pressed?

The default color when a button is pressed on Iphone is blue. How can I change to some other color?
The same applies to the case when I select a row of UITableViewCell. How can I change the color when selected?
Thanks.
In the case of the UIButton, I think you need to provide your own images for the highlighted state. Many of the controls in the iPhone OS like the UIToolbar and UINavigationBar provide a "tint color" that you can change to customize their appearance. The UIButton has a couple of predefined appearances, like "Rounded Button", but most of the time I end up using custom images for mine.
I'm not sure about the UITableViewCell - you might need to subclass it and draw the selected state yourself. There may be a "background image for state" that you could change instead, though.
Sorry that's really not the best news. Maybe someone else knows a better way?