Is there a way to create a UIButton-like frame in iOS without the button? - ios

I'm working on an iPad app right now that takes as input an XML file and outputs a Cocoa-like user interface that's dynamically generated based on the content of the XML file. Part of the specification that I've been given dictates that one of the UI elements is a simple frame that looks exactly like a Cocoa Touch button, but does not act as a button; IE, it does nothing when clicked on, and does not visually change in any way. I wanted to use the iOS equivalent of a NSBox mocked up to look like a NSButton, but upon inspection it seems that there is no UIBox class that is equivalent to a NSBox the same way that UIButton is similar/equivalent to the NSButton. Can anyone more experienced in iOS than I suggest a design pattern for creating a button's 'frame' without the additional weight of a new button?

Simple, just disable user interaction on the button. This way it will still look like a button but it won't act like one.
[myButton setUserInterActionEnabled:NO];
Alternatively you could create a UIImageView and use Quartz to adjust the corner radius of the image.
#import QuartzCore/QuartzCore.h
[[myImageView layer] setCornerRadius:15.0];

Related

Component in iOS to make a selector option

I wonder which component is being used to create a selector option like the one used in iBooks where we can adjust the Font Size and also the Theme, but without moving to a new view controller.
In my application I would like to implement it giving 3 small options to the user to choose, but without moving the view controller being presented. Its a small square area with an arrow at the bottom or top side giving the impression where it's coming from. (Let me know if I am not clear with the explanation).
Does anybody know how to use it??
Thank you all in advance
ibooks is using UIView. In that UIView you can add any controls you like. You need to use delegate methods so that I can perform communication between two objects(send message to another object). You will be able to make you custom UIView as controls.

How can I get the size of the keyboard on iPhone?

I want to get the keyboard size without using NSNotification. When I press the plus button, it can replace the keyboard with a custom UIView like this:
Then the plus button is pressed and the view loaded:
How can I achieve this?
I already made same rookie mistake like you want to do here. The problem is you will write a lot only to realize you do not want to avoid standard flow provided you by iOS team. For example you will definitely have a bad time dealing with issue like this one (there is additional bar which is part of standard keyboard for Chinese locale):
I solved this by using other people's work from DAKeyboardControl project. You do not need to attach observer (or if you use DAKeyboardControl - block) directly to your bar with buttons, but to your controller and check what user is trying to do and animate this bar accordingly. In the sources you can see how to get keyboard's animation duration and timing function. It may sound more complicated than it indeed is, just give it a try.

Add new UIButton "state" with custom image

I'm trying to build a simple peg jumping game (see: http://cl.ly/2x0v1V3z351t0j3d3y0L).
My plan is to make each "peg" a UIButton and toggle the UIButton states for the different images that need to be displayed at different times during the game. Using the default states for UIButton gets me pretty far but I need to add one extra state beyond the default 4.
How would I go about doing this? I figure I will need to sub class UIButton to create a custom UIButton object but this is where I get stuck. I can't find any resources on adding new button states. Is this something that is possible?
This link below was a major help to me implementing my own custom button. I basically took that guy's code and made it ARC compatible, but the basic principle in what he's done really works great!
Custom Button States
Subclass UIBUtton and add a custom state variable, then use the setter to change the image that is shown.

How can I create a dynamic overlay for a UIButton?

My application has a few portions that have really big buttons (640x130, 230x150, etc.) What I need is to have a way to update different portions of the button, with different text. Initially, I assumed that in my code I could create various UILabels and then add them as subviews to my button. However, as soon as I try to add a UILabel to the button as a sub-view, my app crashes.
What is the easiest way to create an overlay for a button, that I can completely layout myself, without preventing button taps from being interested using overlay controls?
I imagine there are multiple ways to solve this problem. However, the best solution for my case should use the fewest lines of code (I have quite a few of these types of buttons) and I'd like to be able to continue using some form of configurable button within IB.
I'm not opposed to subclassing UIButton but, if I do, I would like to be able to use it in IB. I've never created a custom UIView for such a circumstance, so I'd need help defining that type of subclass so that it will work correctly in IB.
You need to add the subview to the containing view - not the button. To ensure that is doesn't interfere with button presses, be sure to set it to:
[myCustomTextOverlay setUserInteractionEnabled:NO];

How to make custom buttons in iOS?

The default iOS UI is nice but if I wanted to use images for buttons instead how would I do that - is it OpenGL?
Make the button a "custom button" type in interface builder. Then set the background image to be whatever you want the background to be.
Unfortunately the default button style is a little boring. You'll need to find or make a button with an image editor.
UIButton has a lot of support for custom buttons. In the nib (or storyboard or whatever), just click on the button and set its "Type" to "Custom" in the attribute inspector on the right side of the screen. Then, just below that, set the State Config to the sate you'd like (default, selected, etc) to customize, and set Image attribute to the image you'd like.
That image must be part of the project first before it will show up in the Image attribute (or in the app). You can add the image to the project simply by dragging it into the file navigator on the left side of the screen.
You can use images for buttons using a few simple lines of code:
// code to set image for button at normal state
[myButton setImage:[UIImage imageNamed:#"buttonImage.png"]
forState: UIControlStateNormal];
You can also use Xcode to change the type to "Custom" then you can set images for each button "state."
You can read more about UIButton states here
You can simply use PNG files that you create yourself. The UIButton class allows you to use custom images for all the different states of the application.
You don't really need to do custom rendering yourself, but if you really want, you can use UIKit to draw the images yourself in code (no OpenGL involved): http://developer.apple.com/library/ios/#documentation/2ddrawing/conceptual/drawingprintingios/graphicsdrawingoverview/graphicsdrawingoverview.html
You can do it by setting image or backgroundImage properties of a UIButton.
If you want your button to look nice when the size changes, you can use stretchableImageWithLeftCapWidth:topCapHeight: method of UIImage, with an appropriate image.
You may also want to use a custom component if it satisfies your need.
its very easy
change this two thing.Change "type" round rectangle to custom and drag image to project and select it as background .Run and Go
Well so far i was too looking for using custom buttons and the graphics, I've come through this site they have some awesome tutorial which was quite helpful for me. I've watched all the video tutorial and read some books but nothing helped me but this site and their 4 books are quite awesome and really helpful to read and understand it well.
http://www.raywenderlich.com/27191/learn-to-code-ios-apps-4-making-it-beautiful

Resources