I am just getting started in iOS development after working in Android since the early days and I am a bit confused on how you style/skin iPhone components.
I saw that there is a way to change the color for some components (is that what they are called?) in properties but how can I go even further?
For example, how could I be designing a custom button, or custom listview?
There are several elements here you are asking, so my answer might not be enough for everything you want.
You can for instance use this page here that give you a real nice tutorial for doing some customization to UI components:
http://www.raywenderlich.com/4344/user-interface-customization-in-ios-5
For UITableViews there are other steps you would have to take. For instance, this very good tutorial:
http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html
If you create custom UI elements to replicate standard UI elements in
all but appearance, you should instead consider using the appearance
customization programming interfaces available in iOS 5 and later.
via HIG
Which i suggest viewing this to get the best understanding of the interface builder
For a Button as an image:
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *image = [UIImage imageNamed:#"myFile.png"];
button.frame = CGRectMake(x, y, image.size.width, image.size.height);
[button setImage:image forState:UIControlStateNormal];
[myView addSubview:button];
or with the interface builder:
select "Custom Button" as the type and then select the image you want
from a drop-down menu.
Related
How do I get this effect in a UITableViewCell? The icon placement is just to the right of the label.
Also, is this shuffle icon something that is standard which I should use? I have a similar application where the user can shuffle through words, each word will play in random order if they press this.
You can use the UIKit Artwork Extractor [1] to extract all the apple standard icons and use them in your application. Apple has no problem with this (so far).
[1] https://github.com/0xced/UIKit-Artwork-Extractor/blob/master/README.md
(assuming u click that icon to shuffle the list)
its as simple as adding a custom button with that imageview as background , as subview to the cell.but set the frame accordingly like
UIButton *shuffbutton=[UIButton buttonWithType:UIButtonTypeCustom];
shuffbutton.frame=CGRectMake(100,5, 30, 30);
[shuffbutton setBackgroundImage:[UIImage imageNamed:#"shuffle_icon.png"] forState:UIControlStateNormal];
[shuffbutton addTarget:self action:#selector(shuffle:) forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:shuffbutton];
Is this a UIButton? If it is, how is the background red done? Obviously, it is not
red UIColor? Is there same tool or utility included with Xcode to allow making buttons
like this?
You can generate similar buttons with private class UIGlassButton.
I saw it first here http://pastie.org/830884 by #schwa.
Run an app with this code in your iOS simulator to create a custom button (or in the device, save to $(APP)/Documents and enable iTunes file sharing).
Class theClass = NSClassFromString(#"UIGlassButton");
UIButton *theButton = [[[theClass alloc] initWithFrame:CGRectMake(10, 10, 120, 44)] autorelease];
// Customize the color
[theButton setValue:[UIColor colorWithHue:0.267 saturation:1.000 brightness:0.667 alpha:1.000] forKey:#"tintColor"];
//[theButton setTitle:#"Accept" forState:UIControlStateNormal];
[self.view addSubview:theButton];
UIGraphicsBeginImageContext(theButton.frame.size);
CGContextRef theContext = UIGraphicsGetCurrentContext();
[theButton.layer renderInContext:theContext];
UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
NSData *theData = UIImagePNGRepresentation(theImage);
[theData writeToFile:#"/Users/<# your user #>/Desktop/button.png" atomically:NO];
UIGraphicsEndImageContext();
Once you obtain the png, use it as button background.
Alternatively, you can build the buttons programmatically (by Jeff Lamarche).
I wrote a couple of classes to generate buttons for a calculator I wrote. The classes generate the buttons based upon either standard colors or with RGB input RGB values. The buttons are in my BindleKit project on Github: https://github.com/bindle/BindleKit
My answer to Change UIButton background color describes how to use the classes and where to find the source.
To see examples of the buttons, compile the BKCatalog app in the Github project or look at the screenshot https://github.com/bindle/BindleKit/blob/master/screenshots/BKCatalog-BKButtons.png
You need to create a background image for the button.
Then add the image to the button:
- (void)setImage:(UIImage *)image forState:(UIControlState)state
Also for resizable buttons see:
- (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets
You can use programs like Graphics Converter, Photoshop and others.
And under iOS 5, you have UIAppearance.
You can make a button like that with core animation layers.
http://www.cimgf.com/2010/01/28/fun-with-uibuttons-and-core-animation-layers/
I want to change the color of my UIButton. I did this:
UIButton *alreadySubscriber = [[UIButton alloc] initWithFrame:CGRectMake(12, maxy-65, 262.0, 50)];
alreadySubscriber.layer.cornerRadius = 10.0f;
[alreadySubscriber setBackgroundColor:[UIColor orangeColor]];
[alreadySubscriber setTitle:#"Already a subscriber" forState:UIControlStateNormal];
The color of the button changes, but no longer see the effect of bright light booby top. how can I fix this?
We're unable to programmatically set this 'bubble effect' for the UIButton I'm afraid. The only way to go about it far as I can tell is to go for a custom button with an image (or two images for the normal and active states).
The resource Eugene put up earlier seems pretty good in fact.
I don't really know what kind of booby light are you talking about, but have you tried using images for your buttons? I'd suggest using two different images like those you can create here http://dabuttonfactory.com/.
You should create as a custom button and add the image/color as background.
Okay, simple enough.
I'm coding up a simple web view, and I'm providing a few Safari-like controls for navigation.
Play seems to be the obvious choice for the forward button, but I'd like to have a Back Button as well, as seen in several Apple and third party apps.
Is there a way to invert the icon, so that it points backwards, or are all the apps using this setup using images to replicate this functionality?
Unicode is your friend here.
Create a UIBarButtonItem (in Interface Builder or in code) and set it to "Custom" where you can enter text for the button.
Now use these Unicode characters to simulate the back & forward buttons:
◄ and ►
I use it in my apps and it looks great.
I know this was answered long ago, however just to add...
Yes, you can use Unicode but it does not look the same as the standard ios button. And if you have strict requirements to match ios look than you will need to at least make an image for the back button, in this case by simply downloading the play image and flipping it.
UIImage *image = [UIImage imageNamed:#"backButton.png"];
UIButton *btnBack = [UIButton buttonWithType:UIButtonTypeCustom];
[btnBack setImage:image forState:UIControlStateNormal];
btnBack.frame = CGRectMake(0.0, 0.0, image.size.width, image.size.height);
UIBarButtonItem * btnItem = [[UIBarButtonItem alloc] initWithCustomView:btnBack];
[btnItem addTarget:self action:#selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
// add it to your bar
self.navigationItem.leftBarButtonItem = btnItem;
(wrote it without spell checking... so beware of spelling errors that may have resulted)
// button images are here.
http://developer.apple.com/library/ios/#documentation/userexperience/conceptual/mobilehig/IconsImages/IconsImages.html
You could use atPeek to extract the play button png from an app that uses it, and then use any image manipulation program to flip it.
It is a very generic question (not related to any application). Just my quest to know more.
While creating any iPhone application, we see that there few UIControls available in Library of Interface Builder. Using those we can create all basic application and designs, and also we can't customize those to much extent
But if we see on App Store, thousands of applications are available, where there many UIControls which are either not available in Library or might be they customized to much extent.
I want to know that:
Can we use controls other than available in Library (if yes than how and from where to get that).
If we can't than how do we modify (customize) the available UIControls to such an extent that they look totally different from their original primary look.
Regards,
Pratik
For a start, it is possible to set an image (including transparency) for most controllers. Many controller that look like different controls may actually be the same controls, just reskinned. Many controllers allow subviews - it is amazing how much can be achieved just using the table controller.
It is also worth knowing that any control you place using the GUI can also be set to a subclass where you override behaviour. Simply select the control, hit Shift-Apple i and change the class in Class Identity.
For customised controllers you can check the Three20 Project by Joe Hewitt.
take a look at the three20 library. It include custom styled button, labels and text. It should give you the general idea, how to customize your own UI elements.
Often, you don't use images like casebash mentioned, instead your drawing your elements with graphical methods.
Another possible solution is to override your
- (void)drawRect:(CGRect)rect
of your UIView
Edit:
Source Code taken from
Custom UIButton for Iphone
INDEX_OFFSET = 82753; // random
UIButton *sampleButton = [UIButton buttonWithType:UIButtonTypeCustom];
[sampleButton setFrame:CGRectMake(kLeftMargin, 10, self.view.bounds.size.width - kLeftMargin - kRightMargin, 52)];
[sampleButton setTitle:#"Button Title" forState:UIControlStateNormal];
[sampleButton setFont:[UIFont boldSystemFontOfSize:20]];
[sampleButton setTag:<INDEX>+INDEX_OFFSET];
[sampleButton setBackgroundImage:[[UIImage imageNamed:#"redButton.png"] stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0] forState:UIControlStateNormal];
[sampleButton addTarget:self action:#selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:sampleButton];