I have to implement a toggle like behavior between to differentiate between two states, client doesn't want UIbuttons because he has his own png's and wants them to be used.
so I need to have to UIImageViews next to each other.
I am talking about UIImageviews because the toggle behavior the client wants should be a sliding one, as in the user has two options in the control ( like on / off ) he slides the UI from on to off, or off to on, I was given 4 png's: 2 for the on state ( normal and depressed ) and 2 for the off state ( Normal and depressed ) .
I also looked into UISwitch, but again to customize it the way I want to seemed cumbersome, any ideas?
You can achieve what your client wants this way:
UIButton *nameOfButton = [UIButton buttonWithType:UIButtonTypeCustom];
[nameOfButton setImage:[UIImage imageNamed:nameOfYourClientsPNGFiles] forState:UIControlStateNormal];
[nameOfButton addTarget:self action:#selector(actionForButton) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:nameOfButton];
//Note that all the words are to be replaced with what your methods and pointers are.
Also if your clients PNG files are not the traditional square images I strongly recommend looking into this Custom Class:-)
OBShapedButton
It sorts out the problem that the user can only tab and click the shape of the image.
Related
I've been looking over countless questions and answers here on SO, but could not find one that would provide the answer for my specific problem.
In a nutshell: I am trying to implement a custom edit view for my UITableViewCells. I would like to keep the basic "delete" and "rearrange/drag" actions (although on opposite ends than in the default implementation and with custom icons), and I would also like to add a "duplicate" action to them and one that navigates to a specific view (separate from the one when you click the cell in normal state). Something like this:
Ideally, I would like to trigger this edit mode on all cells when I toggle edit mode with a separate button, and on individual cells with a left swipe (without the drag option if it is not possible on an individual cell).
I have sub-classed UITableViewCell and was able to add a swipe recognizer that reveals a view ("cellOptionsContainer") with the 3 custom buttons on the right, all of which I was able to make work using tags and delegates, but that is most certainly not the right way to do things because I've added them to the cell's content view (not knowing any better):
// Add container to hold options buttons
cellOptionsContainer = [[UIView alloc] initWithFrame:CGRectMake(cellWidth,
0.0f,
(dataBase.sizeInteraction * 3),
dataBase.sizeInteraction)];
[self.contentView addSubview:cellOptionsContainer];
// Add edit button
UIButton *cellOptionsButton = [[UIButton alloc] initWithFrame:CGRectMake((0.0f),
0.0f,
dataBase.sizeInteraction,
dataBase.sizeInteraction)];
cellOptionsButton.tag = cellID;
[cellOptionsButton setImage:[UIImage imageNamed:#"iconEditOutlined"] forState:UIControlStateNormal];
[cellOptionsButton setShowsTouchWhenHighlighted:YES];
[cellOptionsButton setAdjustsImageWhenHighlighted:NO];
[cellOptionsButton addTarget:self action:#selector(presentEditView:) forControlEvents:UIControlEventTouchUpInside];
//[cellOptionsContainer addSubview:cellOptionsButton];
[cellOptionsContainer addSubview:cellOptionsButton];
Meanwhile, I was also able to make work the standard edit view in my UITableView delegate (rearranging and deleting both works fine), but I was unable to augment this standard edit view with the added functionality and visual customization illustrated above. I cannot even find a way to change the standard icons...
Any help would be much appreciated; although, I am looking for Objective-C answers as I do not know Swift! I am also doing everything programmatically; I do not use interface builder.
I want to create an iOS app which will have use a Tab Bar controller. I know you can set this up by a template within XCode or you can just code it straight, but I'm unclear why use one approach over the other? other than I presume the template allows you to use the interface builder? if I don't want to use interface builder (and I don't) is there any point to using the tab bar app template? can I use the template but remove the interface builder bits? or if I'm doing that I might as well not use the template and just code the controller directly?
As board as the question sounds, let us look at it as a design decision and personal preference.
The Interface Builder allows you to design your layout quickly while providing you the visual bits - you know, how it would look like while designing it.
Can you achieve the same result programmatically? Yes, sure, if you can see it (where the UI element is, the color, the position it has in relation to the other elements, etc etc) while designing in your mind.
Let's say you wanted to have a UIButton, just a button, plain and have it hooked to a method called clicked when pressed. In IB you could achieve that within seconds.
Comparing that to doing it programmatically:
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:#selector(clicked:) forControlEvents:UIControlEventTouchUpInside];
[button setTitle:#"play a beep" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0f, 80.0f, 40.0f, 40.0f);
[self.view addSubview:button];
You could do it either way - in IB or in code.
For the above case, would doing it in IB faster? Yes. But it doesn't prevent you from also doing it programmatically - it's your preference.
This serves to provide a general answer; because there are many cases involved while designing the interface as to whether one should use IB or do it programmatically.
Can you remove the IB bits? Yes.
Analogy:
Take it as buying a car and pimp it up with fog lamps, have it re-painted etc.
But if you decide to pimp your own ride by replacing every single bits on the car you buy, then why buy a car to do that and not just build one from scratch?
I have a scrollView and inside this scrollView, there are various PFImageView objects.
I need a single UIButton object on every PFImageView (same place and same button) that will load a subView with the information of the image tapped.
Is this possible?
So, let me get this straight... You want to create only one button, place it on multiple imageViews and have it respond differently (depending on which imageView was tapped)?
In this case...
No, you can't have 1 button in N places.
But... you can create N button objects and have them all assigned to 1 single target method in which... you can have different functionality based on the button's tag.
PS: UICollectionView would be cleaner approach.
You can't have a single control in multiple locations, it's that simple.
I saw your comment about not wanting to use a UICollectionView because it's not the design you're looking for, but I wonder what kind of design you want to create with UIScrollView only because UICollectionView doesn't works.
UICollectionView is not restrained to line/grid display of cells, but can be customized in a huge amounts of ways. You should watch the WWDC 2012 video "Introducing Collection Views" : at the end of it, some UICollectionView possibilities are shown and some of them are quite impressive.
Also, https://www.cocoacontrols.com/ website is a good place to find custom controls and even inspiration for your own design.
This is a little digression from the original issue, but I really think that a collection of UIImageView within an UIScrollView can be created with a UICollectionView, especially if you want to add some controls within your "cells".
Yes. You should use specific control events when adding actions to the button.
E.g. in my application i record/stop/cancel sound as long as user hold a button (drag out to cancel).. like a walkie talkie phone...
[recordButton addTarget:self action:#selector(recordStart) forControlEvents:UIControlEventTouchDown];
[recordButton addTarget:self action:#selector(recordStop) forControlEvents:UIControlEventTouchUpInside];
[recordButton addTarget:self action:#selector(recordCancel) forControlEvents:UIControlEventTouchDragExit];
In a program much like the who want to be a millionaire... I have 4 option buttons. It should flash red or green on press. The four buttons have either red or green images as background images. In the code setup I have such a method ready to setup the first question and when the second question gets set, the background images change accordingly.
Currently the default blue highlight is always appearing on the first pressing of any one the buttons and after that there are other issues.
I could paste some different approaches here, (but they dont work). So any suggestions would be good.
Also in the IB, when you set the highlight with background image, that works. I would use use, but for the same button, the back ground image must be changed programmatically.
Thanks in advance for the help/suggestions!
Use two State UIControlStateNormal and UIControlStateHighlighted
[btnMenu setBackgroundImage:[UIImage imageNamed:#"img1.png"] forState:UIControlStateNormal];
[btnMenu setBackgroundImage:[UIImage imageNamed:#"img1-Highlighted.png"] forState:UIControlStateHighlighted];
I want to know whether drawing a round UIButton(not rounded rect) is possible.
When I add a round image in a UIButton of type custom, then it looks like a round button. But at the moment the button is clicked the boundary of the button becomes visible, so that it looks like a square button, then again when the click ends it looks like a round button.
I want the button to look like a round button even at the moment the click happens. is this possible?
Tested Code:
.h
-(void)vijayWithApple;
.m
-(void)vijayWithApple{
NSLog(#"vijayWithApple Called");
}
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:#"Micky.png"] forState:UIControlStateNormal];
[button addTarget:self action:#selector(vijayWithApple) forControlEvents:UIControlEventTouchUpInside];
[button setTitle:#"Show View" forState:UIControlStateNormal];
button.frame = CGRectMake(135.0, 180.0, 40.0, 40.0);//width and height should be same value
button.clipsToBounds = YES;
button.layer.cornerRadius = 20;//half of the width
button.layer.borderColor=[UIColor redColor].CGColor;
button.layer.borderWidth=2.0f;
[self.view addSubview:button];
Result
Just create two rounded button images, one for the pressed state and one for unpressed.
In IB, create a UIButton of type Custom. Go to the section where you set a background image, and set the dropdown with "All" to normal - now set the image to your unpressed image.
Then change the dropdown to "Selected", and put in your pressed image.
Now change the fill type to be aspect fit, and make the button sqare. Use as a normal UIButton anywhere. You can of course also easily do this all programaitcally with similar steps (setting images for UIControlStateNormal and UIControlStateSelected).
You'd probably have to create a custom control for that, but do you really need a round button?
Every platform has its UI conventions, and the iPhone is no exception. Users expect the buttons to be rounded rectangles.
UPDATE in response to comment:
If I'm getting this right, you're not looking for a round button, but rather a clickable (touchable) image.
You can use an UIImageView and its touchesBegan method.
UPDATE 2:
Wait a second. What kind of radio button are we talking about? For some reason I thought you were trying to imitate a real radio. If you're talking about a radio button group, please use a UISegmentedControl or a UIPicker.
UIButton *but=[UIButton buttonWithType:UIButtonTypeCustom];
but.layer.cornerRadius=50;
From what I know of the SDK (admittedly I have very little experience beyond tutorials in books/screencasts), you'd have to create your own control to have a radio button. There are a couple of suggestions on how to implement that in this question.
That said, from a user's perspective I feel like it would be better to stick to the native controls. iPhone users are used to specific controls (i.e. UITableViews or UIPickerViews) for this type of interaction. Straying from practically universal UI conventions tends to make the user experience more jarring.
take the help of this site for creating Round Button on iPhone.
You can get many custom controls :)
http://www.cocoacontrols.com/controls
http://www.cocoacontrols.com/platforms/ios/controls/uiglossybutton
H#PPY CODING !
Thanks & regards,
Gautam Tiwari