I hope to know how to add an icon to an UIActionSheet button?
I checked some document but no result.
Welcome any comment
Thanks
interdev
Although there is no API, it is a simple property you can change.
You can access each UIButton image like so:
SEL buttonsSEL = #selector(buttons);
if([yourUIActionSheet respondsToSelector:buttonsSEL]) {
NSString *buttonsSel = NSStringFromSelector(buttonsSEL);
[[[yourUIActionSheet valueForKey:buttonsSel objectAtIndex:yourIndex]
setImage:[UIImage imageNamed:#"yourImage.png"]
forState:UIControlStateNormal];
...
}
where
yourUIActionSheet is a UIActionSheet*
yourIndex is an int representing the button index, starting at 0
No way to do this with the current SDK.
Related
I am using GSRadioButtonSetController for the radio button implementation...I created two buttons and included in IBOutletCollection(UIButton) NSArray *buttonCollection....then I included GSRadioButtonSetController.h and GSRadioButtonSetController.m file to my project. Then to my viewdidload I added
// Instantiate your GSRadioButtonSetController object
self.radioButtonSetController = [[GSRadioButtonSetController alloc] init];
// Set its delegate to your view controller
self.radioButtonSetController.delegate = self;
// Set its buttons property to an array of buttons that you've
// created previously.
self.radioButtonSetController.buttons = buttonCollection;
and then I put
- (void)radioButtonSetController:(GSRadioButtonSetController *)controller
didSelectButtonAtIndex:(NSUInteger)selectedIndex
{
//implemetation
}
There are tow image for the button...one for the select state and 2nd for the deselcetd state....the code is giving me indexes however I dont know how to change to image dynamically so that user know which one is selected and which one is not...
Thanx in advance
When you create the buttons to add to `buttonCollection', set image to buttons, like:
[button_1 setImage:[UIImage imageNamed:#"radio_button_off.png"] forState:UIControlStateNormal];
[button_1 setImage:[UIImage imageNamed:#"radio_button_on.png"] forState:UIControlStateSelected];
it worked for me
I've got a problem with the route-me framework and marker labels. I'm trying now about 5 hours with no luck and searched almost every forum topic on the web about this.
I want to add a marker label with a UIButtonTypeDetailDisclosure-Button on it.
When I add the Button to the UIView that should be the label I can't click on the Button.
My code is as follows:
- (void)tapOnMarker:(RMMarker*)marker onMap:(RMMapView*)map {
UIView *frame = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
UIButton *button = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
button.frame = CGRectMake(0, 0, 34, 34);
button.enabled = YES;
button.userInteractionEnabled = YES;
[button addTarget:self action:#selector(markerLabelButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[frame addSubview:button];
[marker setLabel:frame];
[marker showLabel];
}
-(void)markerLabelButtonPressed:(id)sender {
NSLog(#"pressed");
}
I hope anyone may help me with this. Thanks :)
I you need any more information please let me know!
Ok finally i managed to solve the problem.
Maybe it's a little dirty workaround, but anyway it's working ;)
I modified the route-me framework and added a method called
- (void) tapOnLabelForMarker: (RMMarker*) marker onMap: (RMMapView*) map onLayer:(CALayer *)layer;
In RMMapView.m I added the following Lines in Line 584:
else if ([superlayer superlayer] != nil && [[[superlayer superlayer] superlayer] isKindOfClass: [RMMarker class]]) {
if (_delegateHasTapOnLabelForMarker) {
[delegate tapOnLabelForMarker:(RMMarker*)[[superlayer superlayer] superlayer] onMap:self onLayer:superlayer];
}
}
Now then the disclosurebutton is tapped this part of the code is executed and my method is called.
When any other area of the marker label is tapped the
- (void) tapOnLabelForMarker: (RMMarker*) marker onMap: (RMMapView*) map;
method is called.
Hope this helps anyone else ;)
This issue is resolved by this pull request https://github.com/route-me/route-me/pull/161.
It has been merged in route-me code on feb 21st 2012.
Take a look to this thread in the route google groups list:
http://groups.google.com/group/route-me-map/browse_thread/thread/343cb3ebfd9480e3
someone was answered with some code for marker "balloon" labels that uses a close button.
I had trouble with this solution, and I don't want to be one of those people who tell you to do it differently because you may have good cause to do things the way you are doing them.
I took this initial approach, then via another thread I realized: If I only want to have one callout at a time, I can just manage him as a subview of the mapView and use the helper methods of the mapView.markerManager. A RMMarker object has a data pointer which you can use to fill in the contents of your callout bubble.
This saved me a lot of time and I have a satisfactory solution that doesn't get that dirty at all.
I would like to ask if there are examples out there on how to implement radio-button options on an iPhone app.
I find the Picker View quite big for a simple selection feature.
I'm not sure if Apple excluded radio buttons on purpose, and whether if it is better to simply use a Picker View from a usability / user experience point-of-view.
I have some thoughts on how the best radio button implementation should look like. It can be based on UIButton class and use it's 'selected' state to indicate one from the group. The UIButton has native customisation options in IB, so it is convenient to design XIBs.
Also there should be an easy way to group buttons using IB outlet connections:
I have implemented my ideas in this RadioButton class. Works like a charm:
Download the sample project.
Try UISegmentedControl. It behaves similarly to radio buttons -- presents an array of choices and lets the user pick 1.
Just want to sum up, there might be 4 ways.
If you don't have much space, add a click event for text or button, then show UIPickerView:
or open a new table view control with a check mark:
If there is more space, add a table view directly to your main view:
The final solution is using UISegmentedControl:
Hope this helps.
Try DLRadioButton, works for both Swift and ObjC. You can also use images to indicate selection status or customize your own style.
Check it out at GitHub.
**Update: added the option for putting selection indicator on the right side.
**Update: added square button, IBDesignable, improved performance.
**Update: added multiple selection support.
I know its very late to answer this but hope this may help anyone.
you can create button like radio button using IBOutletCollection. create one IBOutletCollection property in our .h file.
#property (nonatomic, strong) IBOutletCollection(UIButton) NSArray *ButtonArray;
connect all button with this IBOutletCollection and make one IBAction method for all three button.
- (IBAction)btnTapped:(id)sender {
for ( int i=0; i < [self.ButtonArray count]; i++) {
[[self.ButtonArray objectAtIndex:i] setImage:[UIImage
imageNamed:#"radio-off.png"]
forState:UIControlStateNormal];
}
[sender setImage:[UIImage imageNamed:#"radio-on.png"]
forState:UIControlStateNormal];
}
For options screens, especially where there are multiple radio groups, I like to use a grouped table view. Each group is a radio group and each cell a choice within the group. It is trivial to use the accessory view of a cell for a check mark indicating which option you want.
If only UIPickerView could be made just a little smaller or their gradients were a bit better suited to tiling two to a page...
I've written a controller for handling the logic behind an array of radio buttons. It's open source and on GitHub, check it out!
https://github.com/goosoftware/GSRadioButtonSetController
The following simple way to create radio button in your iOS app follow two steps.
Step1- Put this code in your in viewDidLoad or any other desired method
[_mrRadio setSelected:YES];
[_mrRadio setTag:1];
[_msRadio setTag:1];
[_mrRadio setBackgroundImage:[UIImage imageNamed:#"radiodselect_white.png"] forState:UIControlStateNormal];
[_mrRadio setBackgroundImage:[UIImage imageNamed:#"radioselect_white.png"] forState:UIControlStateSelected];
[_mrRadio addTarget:self action:#selector(radioButtonSelected:) forControlEvents:UIControlEventTouchUpInside];
[_msRadio setBackgroundImage:[UIImage imageNamed:#"radiodselect_white.png"] forState:UIControlStateNormal];
[_msRadio setBackgroundImage:[UIImage imageNamed:#"radioselect_white.png"] forState:UIControlStateSelected];
[_msRadio addTarget:self action:#selector(radioButtonSelected:) forControlEvents:UIControlEventTouchUpInside];
Step2- Put following IBAction method in your class
-(void)radioButtonSelected:(id)sender
{
switch ([sender tag ]) {
case 1:
if ([_mrRadio isSelected]==YES) {
// [_mrRadio setSelected:NO];
// [_msRadio setSelected:YES];
genderType = #"1";
}
else
{
[_mrRadio setSelected:YES];
[_msRadio setSelected:NO];
genderType = #"1";
}
break;
case 2:
if ([_msRadio isSelected]==YES) {
// [_msRadio setSelected:NO];
// [_mrRadio setSelected:YES];
genderType = #"2";
}
else
{
[_msRadio setSelected:YES];
[_mrRadio setSelected:NO];
genderType = #"2";
}
break;
default:
break;
}
}
If I have a random integer e.g. randomInt and want to call a created button e.g. UIButton *button1, button2, button3 etc.
Will I be able to call the button as follows
NSString *buttonNumber = [NSString stringWithFormat:#"button%d", randomInt];
[buttonNumber setImage:[UIImage imageNamed:#"someImage.png"] forState:UIControlStateNormal];
I have a lot of these and it would decrease code amount dramatically.
Thanks
Create then Store your buttons in an NS(Mutable)Array then access them using:
UIButton* button = [buttonArray objectAtIndex:randomInt];
When you create the button assign a tag to the button like
button.tag = number
you can get the button later with
[[parentview viewWithTag:randomInt] setimage:...]
If the UIButtons are properties of your self object, you can do it like this:
[[self valueForKey:buttonNumber] setImage:...]
Its better to use the tags with the button. It will help you a lot and it will reduce the code than you currently are using.
-hAPPY iCODING...
So, I have a UISegmentedControl with:
[control addTarget:self action:#selector(myAction) forControlEvents:UIControlEventValueChanged];
Just wondering how I would find out what segment has been selected (so I can do the appropriate action). I know its something like:
#selector(myAction:) but what gets sent? ie: when I define my method what do I have to define?
Thank you.
get the selected item... second part of question
-(IBAction) myAction:(id)sender{
NSLog(#"myAction",nil);
UISegmentedControl * control = sender;
int selectedIndex = [control selectedSegmentIndex];
}
- (IBAction)myAction:(id)selector;
selector is an UISegmentedControl object. Thus you may differ two UISegmentedControl's if you bind one action to both.
There is also easier way:
-(IBAction) myAction:(UISegmentedControl*)control {
NSLog(#"selected index %d", control.selectedSegmentIndex);
}