So on the App Store, what I'm seeing a lot is a custom UI that still looks like the native Apple ones, but is some how "spruced up" in look. How exactly would I create something like that, as in say a button that is a hexagon or something instead of a rounded rectangle?
Thanks,
VectorWare
Draw any image you want, using your favorite art program.
Don't forget to make pressed and "up" states.
Create your button (in IB or code.)
Make the button of type UIButtonTypeCustom (IB or code.)
In IB, set the button's image to your image.
Set the image separately for NORMAL and HIGHLIGHTED states (IB or code.)
Example in code:
[myButton setImage: myImage forState: UIControlStateNormal];
They are probably either subclass' of UIView/UIWhatever or images with a transparent UIButton over top of the image. Is there something specific you want to implement?
Some examples:
Subclassing a UIView
UIView subclass dialog window
Related
I have multiple buttons in an outlet collection with no image defined on any of them in the inspector. I use a for loop and the following line of code to set the image on each button after each interaction.
[button setImage:(UIImage *)image forState:(UIControlState)UIControlStateNormal];
When the application starts in the simulator, some of the buttons have the image neatly fit in the button, the others have a tall, skinny version of the image. If I understand how this works, at the beginning the code to set the image has not been executed.
How is the image being displayed at the beginning?
How do some buttons have the correct image and others are screwy?
It sounds like your buttons may not be all using the same contentMode. Look at the view in interface builder and go to the attributes inspector and under "View" you should see a "Mode" drop down with values like "Scale to fill", "Aspect Fit", "Aspect Fill". You should make sure this value is the same for all your buttons. (Obviously use the value from whichever buttons are displaying the way you want). You can see what each mode option does here:
http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIView_Class/UIView/UIView.html
Use this if you don't have a background.
[button setBackgroundImage:image forState:UIControlStateNormal];
The background image is scaled to fill the bounds, but the image is not.
I wanna to make a button so that it has the shape of a stone/ rocket (i.e. irregular shape not a rectangle, square ... etc)
, i wanna to make it also highlighted/bordered with the same shape , i tried a UIButtonTypeCustom but it did not give me what i want .. so anyone has any help or idea, don't be skimpy.
Thanks in advance.
Use UIButtonTypeCustom but also add your custom assets for the look of the button.
Typically you will set the background image of the UIButton to some image you want (your rock, rocket, etc) for each state of the button (Normal, Highlighted, Disabled…).
Simply add the images in your Xcode project, then set the background image for each state of your UIButton directly in your XIB (using the Object Inspector panel on the right), or via code using the setBackgroundImage:forState: method.
I would like to make a generic class that when tapped, makes the element grayish.
Facebook's app is the perfect example of what I want to achieve. All their links and images become gray when tapped.
I can only guess that they are subclassing UIButton.
I have made my button's style UIButtonTypeCustom to get rid of the rounded border. Beyond this, I don't know how to have the gray overlay because I see no such property in the documentation.
Its simple:
#define TAG_GRAYVIEW 5671263 // some random number
// add the gray overlay
UIView *grayView = [[UIView alloc] initWithFrame:button.bounds];
grayView.backgroundColor = [UIColor grayColor];
grayView.tag = TAG_GRAYVIEW;
[button addSubview:grayView];
// remove the gray overlay
UIView *grayView = [button viewWithTag:TAG_GRAYVIEW];
[grayView removeFromSuperview];
I think you need to use a semi transperant grey image PNG file. You need to then set Image of button in Highlighted state.
Also note that both the images for Normal State and Highlighted State need to have the images with titles on them.
As once we set the image to button, btn.titleLabel.text won't be displayed.
So you can have a image with transperant background and title on it for Normal state. And an grey image with title on it for Highlighted State.
Code for doing it programmatically is
[btn setImage:#"Transperant.png" forState:UIControlStateNormal];
[btn setImage:#"Grey.png" forState:UIControlStateHighlighted];
Hope this helps you.
The default UIButton masks the opaque content using a gray highlight. For example when using a transparent png, only the parts that contain non-transparent pixels will be grayed out on touch. The default UIButton highlight has no effect on subviews/sublayers, and will only work on provided images. What you see in the Facebook app is probably just a UIWebView highlight, possibly customized using css.
To create something similar using your own control (to prevent the overhead of a UIWebView) you should probably create your own UIControl subclass and highlight the content on touch using a transparent CALayer. You can even mask the CALayer to only highlight the actual contents, instead of a rectangular shape.
Also see my stackoverflow post on creating custom controls for iOS by subclassing UIControl.
Try setting the button up something like this.
*mind you I didn't create the image for this example.
Set your button type to custom, and in "State Config" select "Highlighted" from there you will want to set the image of the button to be a semi-transparent grey image. There are probably several other ways to achieve this same effect but this one should be nice and simple.
I'm creating UIButtons (type = UIButtonTypeCustom) with a custom background drawn by an artist; unfortunately UIButton is adding an unwanted 'well' effect around the backgroundImage (as specified via setBackgroundImage). Is there a way to disable the well? It's not a simple drop shadow, so messing with the CALayer properties doesn't seem to help. I realise I could use UIControl, but that's considerably more work, since I need to handle the label subview myself, and get the artist to produce highlighted versions of the artwork - UIButton is doing all that nicely, if I could only disable the well effect.
Put your image inside a UIImageView, and then position your UIButton on top of it. Use the "custom" style, which has no UI to it at all and is totally invisible.
If you want to change ("highlight") your button image when the button is hit, just change the image contained in the UIImageView in whatever method your UIButton targets.
I want to build a spinner for menu selection like the one in where to? IPhone app as shown in image below. Any hints?
Doesn't need to be very hard. The easiest is probably a UIImageView with the image of the actual spinner, and another UIImageView with the yellow selection highlight (a transparent PNG) overlaying. The rotation can then be controlled with the transform property of the first UIImageView.
This should of course be nicely encapsulated in a custom UIView subclass.