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.)
Related
I'm planning to implement a custom toolbar using my own images. Something more or less exactly like this or this. What would be required to do this. Could I just derive a control from UIView, then create another subclass to display the actual toolbar items and handle all the drawing myself in drawRect, or would it be better to make use of standard UIKit controls to handle the drawing of the images?
You can use a standard UITabBar - it is very customizable. You can set a custom backgroundImage and selectionIndicatorImage to completely change its looks. On the UITabBarItems, you can control the appearance using the finishedSelectedImage and finishedUnselectedImage properties.
Hope it helps, and good luck!
The only way to get this to work the way I wanted was to use a custom control.
i want to customize my tableview, like the tipulator app for the iphone.
And heres my app:
Each UITableViewCell has a few subviews which you can replace with your own. They are:
UITableViewCell.imageView
UITableViewCell.contentView
UITableViewCell.backgroundView
UITableViewCell.accessoryView
As Gendolkari pointed out, Cocoa With Love has a great guide on custom UITableViews.
The theory is that you replace each of those views with an appropriate view to "skin" your UITableViewCells.
When replacing the background view, you check for the first and last cells when skinning the background view, otherwise you can use a "middle" background image. Implement it as a UIImageView. As far as the other views, use what you want.
Additionally, you can use a completely custom NIB file and load that in instead of the default styles provided by UIKit.
While the others are right in suggesting ways to subclass UITableView or its components, this screenshot doesn't look like it's showing a UITableView.
My guess is that they're just drawing custom images onto a background and checking certain areas for taps. What you should do is read up on the drawing methods as well as on intercepting taps and touches.
Here's a really good guide on custom styling for your table:
http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html
Create your own UITableViewCell, and use it, rather than a "generic" one.
You can do this directly in XCode with "File->New File" Then in "Cocoa Touch Class", choose "Objective-C Class" - and under the "Subclass" popup, select "UITableViewCell".
It well generate a XIB, which you can use in IB to customize the look.
Instantiate and pass-in there cells in your UITableView code, instead of the normal UITableViewCells.
Basically I want to re-style UITableView(Controller). Each cell will have a picture as a background and such. this tableview will be used throughout the app thats why I want to subclass it, because I want to be able to define the style once and then reuse it everywhere, but still be able to change things per view. For instance, I'd like every cell to have the same blue background and a specific font, but I might want to change the font in one view, or make the cell taller/shorter. You get the idea.
Can I subclass UITableViewController and create the style in the methods in that? Then subclass MyCustomUITableViewController when I want to create a table view? Or would it better to subclass UITableView and then [self.view addSubview:(MyCustomTableView *)tableVie]?
Thanks
Tom
You will probably want to subclass UITableViewController to define relevant UITableViewDelegate methods, but I think that the real work will be in subclassing UITableViewCell to get the look that you want.
UITableViewCell is a UIView, so it can have a background color and it can contain a UILabel, for example.
Your -tableView:cellForRowAtIndexPath: will need to instantiate your UITableViewCell subclass (or load it from a nib) - and then configure it appropriately. I.e., setting text, image, font, etc.
Hope this helps.
I just need to know is it possible to change UITableViewCellEditingStyle image ?. If possible please tell me How to do that?
I don't see any delegate methods for changing the editing-style view.
You could change the editing button title with the delegate method -tableView:titleForDeleteConfirmationButtonForRowAtIndexPath:, however.
You could also override UITableViewCell and create a custom cell with UITableViewCellEditingStyleNone and a custom editing style behavior and appearance.
In case you're still interested you can actually get this to work by intercepting willTransitionToState and didTransitionToState in a subclass of UITableViewCell. The solution does involve "hacking" around in the cell view hierarchy. Look for the description of recursiveDescription on UIView on how to "dump" a hierarchy, but you will find a UIImageView of which you can change the .image property...
Fairly ugly hack, but does not actually use any private api.
i have 2 tableviews in my application with 5 UISwitch in each view.For every switch there is an action.Now i decide to change the label text of switch.I was able to change the label text from ON_OFF to YES_NO .
But after implementing this method in a seperate class which is a UISwitch class i am not able to call the action method for that particular switch.The same is working well if i doesn't implement this method to change the label text.
Can anybody suggest me that were i am going wrong.
You should post some actual code; particularly how you changed the label text. Are you using undocumented APIs? The UISwitch class reference specifically says it's not customizable.
When you say things like "implementing this method in a seperate class which is a UISwitch class," do you mean you've subclassed UISwitch? This also isn't supported. It's a clunky control and there's not a lot that can be done about it without building your own.