Search Results

Search found 447 results on 18 pages for 'uibutton'.

Page 2/18 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • How to pass an int value on UIButton click inside UITableView

    - by Toran Billups
    So I have a view controller with a single UITableView that shows a string to the user. But I needed a way to have the user select this object by id using a normal UIButton so I added it as a subview and the click event works as expected. The issue is this - how can I pass an int value to this click event? I've tried using attributes of the button like button.tag or button.accessibilityhint without much success. How do the professionals pass an int value like this? Also it's important that I can get the actual [x intValue] from the int later in the process. A while back I thought I could do this with a simple NSLog(@"the actual selected hat was %d", [obj.idValue intValue]); But this doesn't appear to work (any idea how I can pull the actual int value directly from the variable?). The working code I have is below - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } if ([self.hats count] > 0) { Hat* obj = [self.hats objectAtIndex: [indexPath row]]; NSMutableString* fullName = [[NSMutableString alloc] init]; [fullName appendFormat:@"%@", obj.name]; [fullName appendFormat:@" %@", obj.type]; cell.textLabel.text = fullName; cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton; //add the button to subview hack UIButton* button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; button.frame = CGRectMake(50, 5, 50, 25); [button setTitle:@"Select" forState:UIControlStateNormal]; button.backgroundColor = [UIColor clearColor]; button.adjustsImageWhenHighlighted = YES; button.tag = obj.idValue; //this is my current hack to add the id but no dice :( [button addTarget:self action:@selector(action:) forControlEvents:UIControlEventTouchUpInside]; [cell.contentView addSubview:button]; //hack } return cell; } - (void)action:(id)sender { int* hatId = ((UIButton *)sender).tag; //try to pull the id value I added above ... //do something w/ the hatId }

    Read the article

  • iPhone: Override UIButton buttonWithType to return subclass

    - by Amagrammer
    I want to be able to create a UIButton with an oversized responsive area. I know that one way to do that is to override the hitTest method in a subclass, but how do I instantiate my custom button object in the first place? [OversizedButton buttonWithType: UIButtonTypeDetailDisclosure]; doesn't work out of the box because buttonWithType returns a UIButton, not an OversizedButton. So it seems like I need to override the buttonWithType method as well. Does anyone know how to do this? @implementation OversizedButton + (id)buttonWithType:(UIButtonType)buttonType { // Construct and return an OversizedButton rather than a UIButton // Needs to handle special types such as UIButtonTypeDetailDisclosure // I NEED TO KNOW HOW TO DO THIS PART } - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { // Return results if touch event was in oversized region // I ALREADY KNOW HOW TO DO THIS PART } @end Alternatively, maybe I could create the button using alloc/initWithFrame. But the buttonType property is readonly, so how do you create the custom button types? Note: I know there are other ways to do this, such as having an invisible button behind the visible one. I don't care for that approach and would prefer to avoid it. Any help on the approach described above would be very helpful. Thanks

    Read the article

  • UIButton addTarget method can not use in IOS 4.2

    - by Risma
    hi i have a UIButton made programmatically and i want to add the target and the action for that button. i have use method addTarget: action: forControlEvents: in IOS 4.1 this method is detected, but in 4.2 it didn't, here is my code float version = [[[UIDevice currentDevice] systemVersion] floatValue]; if(version <= 4.1){ moreButton = [[UIButton buttonWithType:UIButtonTypeCustom] initWithFrame:CGRectMake(6.3+5*widthSegment, 0.0, widthSegment, heightSegment)]; [moreButton addTarget:self action:@selector(getPopOverMore:) forControlEvents:UIControlEventTouchUpInside]; } else{ //version 4.2 NSLog(@"versi 4.2"); moreButton = [UIButton buttonWithType:UIButtonTypeCustom]; moreButton.frame = CGRectMake(6.3+7*widthSegment, 0.0, widthSegment, heightSegment); [moreButton addTarget:self action:@selector(getPopOverMore:) forControlEvents:UIControlEventTouchUpInside]; } and this is the action method : - (IBAction)getPopOverMore:(id)sender{ if(moreFileController == nil) { moreFileController = [[MoreFilePopController alloc] initWithStyle:UITableViewStylePlain]; moreFileController.delegate = self; moreFilePopOverController = [[UIPopoverController alloc] initWithContentViewController:moreFileController]; } CGRect frameMore = CGRectMake(6.3+5*widthSegment, 0.0, widthSegment, heightSegment); [moreFilePopOverController presentPopoverFromRect:frameMore inView:navBar permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES]; } any body know, what's wrong here??

    Read the article

  • UIButton title disappears on touch

    - by psychotik
    I want a touchable UILabel, but since that's not possible I decided to create a UIButton of type UIButtonTypeCustom. It looks how I want it to look, but when I touch it, the title disappears. I tried setting the title for state UIControlStateHighlighted but that didn't help. I know I'm doing something really silly here, but can't figure it out. I tried a few things (commented in the code below) which didn't seem to help. Here's how I'm configuring the button: UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom]; button.frame = CGRectMake(0, 0, width, height); button.clearsContextBeforeDrawing = YES; button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; button.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; button.enabled = YES; button.hidden = NO; button.highlighted = NO; button.opaque = YES; button.selected = NO; button.userInteractionEnabled = YES; button.showsTouchWhenHighlighted = NO; [button setTitle:@"Hello World" forState:UIControlStateNormal]; button.titleLabel.font = [UIFont boldSystemFontOfSize:16]; button.titleLabel.textColor = [UIColor blackColor]; // Things I tried that didn't help //[button setBackgroundColor:[UIColor clearColor]]; //button.titleLabel.text = @"Hello World"; //[button setTitle:@"Hello World" forState:UIControlStateHighlighted]; Any ideas?

    Read the article

  • Highlighting a custom UIButton

    - by Dan Ray
    The app I'm building has LOTS of custom UIButtons laying over top of fairly precisely laid out images. Buttonish, controllish images and labels and what have you, but with a clear custom-style UIButton sitting over top of it to handle the tap. My client yesterday says, "I want that to highlight when you tap it". Never mind that it immediately pushes on a new uinavigationcontroller view... it didn't blink, and so he's confused. Oy. Here's what I've done to address it. I don't like it, but it's what I've done: I subclassed UIButton (naming it FlashingUIButton). For some reason I couldn't just configure it with a background image on control mode highlighted. It never seemed to hit the state "highlighted". Don't know why that is. So instead I wrote: -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [self setBackgroundImage:[UIImage imageNamed:@"grey_screen"] forState:UIControlStateNormal]; [self performSelector:@selector(resetImage) withObject:nil afterDelay:0.2]; [super touchesBegan:touches withEvent:event]; } -(void)resetImage { [self setBackgroundImage:nil forState:UIControlStateNormal]; } This happily lays my grey_screen.png (a 30% opaque black box) over the button when it's tapped and replaces it with happy emptyness .2 of a second later. This is fine, but it means I have to go through all my many nibs and change all my buttons from UIButtons to FlashingUIButtons. Which isn't the end of the world, but I'd really hoped to address this as a UIButton category, and hit all birds with one stone. Any suggestions for a better approach than this one?

    Read the article

  • Objective C : UIButton image with NSArray in a random order

    - by Sarah
    Brief Idea about the flow : I have say minimum 1 and maximum 18 records in my database with a text and an image from which I have to fetch images and place any 3 of the same randomly to 3 UIButtons among which one image should match with my question. i.e. 1 is the answer and other 2 are the distractors. For Example : Question is : where is Apple? Now among the bunch of images, I want to place any 3 images on the 3 UIButtons(1 answer i.e. An Apple and 2 distractors) in a random order and on selecting the UIButton it should prompt me if it's a right answer or not. I am implementing below code for placing the UIImages in a random order : -(void) placeImages { NSMutableArray *images = [NSMutableArray arrayWithArray:arrImg]; NSArray *buttons = [NSArray arrayWithObjects:btn1,btn2,btn3, nil]; for (UIButton *btn in buttons) { int randomIndex= random() % images.count; UIImage *img = [images objectAtIndex:randomIndex]; [btn setImage:img forState:UIControlStateNormal]; [images removeObjectAtIndex:randomIndex]; } } But I am stuck at a point that how should I get 1 UIButton image with an answer and other as distractors also that how should i maintain the index of the image from the NSArray? Kindly guide me. Thank you.

    Read the article

  • Hide/ change width/ change position of UIButton based on device type

    - by Giles Van Gruisen
    I'm using the new in-app SMS features in my iPhone app, but obviously iPod Touches aren't able to send and receive SMS without support of a third party app. I know all well how to detect the device and how to hide a UIButton, but what I do not know is how to change the width of the others. Above are the three icons. The one on the far rights needs to be hidden on an iPod Touch, and the other two need to adjust size/ position to fill the remaining space. Any tips on programatically changing the position and width of a UIButton is greatly appreciated. Thanks!

    Read the article

  • UIButton of type UIButtonTypeCustom will not display Title (iPhone)

    - by RickiG
    Hi I must have overlooked something completely obvious?? but my button displays its image and size correctly, but I simply can't get the Title to show up. I did a really simple test, the Title does not even show up when I do this: CGRect frameBtn = CGRectMake(160.0f, 150.0f, 144.0f, 42.0f); UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [button setImage:[UIImage imageNamed:@"left_halfscreen_button.png"] forState:UIControlStateNormal]; [button setTitle:@"Hello" forState:UIControlStateNormal]; [button setFrame:frameBtn]; NSLog(@"Title:%@", [button currentTitle]); //prints "Title:Hello [self addSubview:button]; I have a factory class that generates custom buttons for me and I thought I messed some detail up there, so I moved the above code directly into my UIView, the title is still blank. Is this a bug or am I simply missing something right in front of my eyes. Thank you for the extra set of eyes:)

    Read the article

  • iPhone UIButton Tap

    - by Ivan
    Hello all, I am trying to make a button that response to single and double tap. I am trying to do this using myAction method. The problem is that first time when I press the button the method myAction isn't called. Can somebody tell why this happening and how can I fix that? -(IBAction)myButton:(id)sender{ UIButton *theButton = (UIButton *)sender; [theButton addTarget:self action:@selector(myAction:forEvent:) forControlEvents:UIControlEventAllEvents]; } - (void)myAction:(id)sender forEvent:(UIEvent *)event { NSLog(@"Touch events goes here"); } Thank you, I. Vasilev

    Read the article

  • UIButton: Need a circle hit area

    - by Pavan
    Ok I have 6 custom UIButtons. Their normal state image are all circles images. They are all spaced out equally but all the circles touch each other. The problem with the custom UIbutton (which has a circle image on it), is that the hit area of that button is square, and the corners of this square overlaps the hitarea of the other custom button's hitarea. How do i make the hit area of a UIbutton whos normal state has a circle image, be only clickable on that circle only, rather than the normal square hit area?! I hope that someone can find a way for me to solve this problem that i currently am having! Thanks in advance Pavan

    Read the article

  • custom UIButton with skewed area in iPhone

    - by sugar
    I want to have a button on a screen with this image. this image is transparent from its corners as you can see here. UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom]; [btn setFrame:CGRectMake(xCo, yCo, kImageSizeWidth, kImageSizeHeight)]; [btn setImage:[UIImage imageNamed:@"aboveImg.png"] forState:UIControlStateNormal]; [btn addTarget:self action:@selector(btnTapped:) forControlEvents:UIControlEventTouchDown]; But the button tap is recognized out side image & i don't want that kind of functionality. I mean tap must be recognized only when it is tapped within image not outside image. How is that possible ? Thanks in advance for sharing your great knowledge. Sagar.

    Read the article

  • Change backgroundcolor for UIButton IPhone

    - by lightwave
    I have a problem. I use a Button as a BarButtonItem. It works fine so far, but my backgroundcolor works only if I click on my button. How can I make it so that my backgroundcolor will be set every time ? UIButton *redEmergencyButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain]; redEmergencyButton.frame = CGRectMake(100, 100, 100, 50); redEmergencyButton.backgroundColor = [UIColor colorWithRed:0.8 green:0.898039215686274509803 blue:1.0 alpha:1.0]; [redEmergencyButton setTitle:@"Emergency" forState:UIControlStateNormal]; [redEmergencyButton addTarget:self action:@selector(doEmergency) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem *rButton = [[UIBarButtonItem alloc] initWithCustomView:redEmergencyButton];

    Read the article

  • UIButton in UITableViewCell events not working

    - by Tristan
    I see this problem all over the net, and none of the solutions listed work for me! I have added UIButton to a UITableViewCell in IB. I have assigned a custom UITableViewCell class to the UITableViewCell. My custom UITableViewCell class has an IBAction that im connecting to the Touch Up Inside event (I have tried other events they all don't work) but the IBAction function is never called! There is nothing else in the UITableViewCell, I have added the UIButton directly into the Content View. And everything has user interaction enabled! It is as simple as that I have nothing complex going on! What is is about a UITableViewCell that stops buttons working? EDIT: By request the code where I initialize my UITableViewCells the custom class is called DownloadCell - (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"DownloadCell"; DownloadCell *cell = (DownloadCell *)[aTableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { UIViewController * cellController = [[UIViewController alloc] initWithNibName:@"DownloadCell" bundle:nil]; cell = (DownloadCell *)cellController.view; [cellController release]; } SoundLibrarianIPhoneAppDelegate * del = (SoundLibrarianIPhoneAppDelegate *)[UIApplication sharedApplication].delegate; DownloadQueue * dq = del.downloadQueue; DownloadJob * job = [dq getDownloadJob: indexPath.row]; [job setDelegate:self]; SoundInfo * info = [job sound]; NSArray * seperated = [info.fileName componentsSeparatedByString: @"."]; NSString * displayName = [seperated objectAtIndex:0]; displayName = [displayName stringByReplacingOccurrencesOfString:@"_" withString:@" "]; displayName = [displayName capitalizedString]; [cell.titleLabel setText: displayName]; cell.progressBar.progress = job.percentCompleted; [cell.progressLabel setText: [job getProgessText]]; cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.userInteractionEnabled = YES; [cell setDelegate:self]; return cell; }

    Read the article

  • iPhone UIView Animation Disables UIButton Subview

    - by bensnider
    So I've got a problem with buttons and animations. Basically, I'm animating a view using the UIView animations while also trying to listen for taps on the button inside the view. The view is just as large as the button, and the view is actually a subclass of UIImageView with an image below the button. The view is a subview of a container view placed in Interface Builder with user interaction enabled and clipping enabled. All the animation and button handling is done in this UIImageView subclass, while the startFloating message is sent from a separate class as needed. If I do no animation, the buttonTapped: message gets sent correctly, but during the animation it does not get sent. I've also tried implementing the touchesEnded method, and the same behavior occurs. UIImageView subclass init (I have the button filled with a color so I can see the frame gets set properly, which it does): - (id)initWithImage:(UIImage *)image { self = [super initWithImage:image]; if (self != nil) { // ...stuffs UIButton *tapBtn = [UIButton buttonWithType:UIButtonTypeCustom]; tapBtn.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height); [tapBtn addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside]; tapBtn.backgroundColor = [UIColor cyanColor]; [self addSubview:tapBtn]; self.userInteractionEnabled = YES; } return self; } Animation method that starts the animation (if I don't call this the button works correctly): - (void)startFloating { [UIView beginAnimations:@"floating" context:nil]; [UIView setAnimationDelegate:self]; [UIView setAnimationCurve:UIViewAnimationCurveLinear]; [UIView setAnimationDuration:10.0f]; self.frame = CGRectMake(self.frame.origin.x, -self.frame.size.height, self.frame.size.width, self.frame.size.height); [UIView commitAnimations]; } So, to be clear: Using the UIView animation effectively disables the button. Disabling the animation causes the button to work. The button is correctly sized and positioned on screen, and moves along with the view correctly.

    Read the article

  • CONFUSING : CGAffineTransform - rotation on uibutton resizes buttonimage ?! (iPad)

    - by Michael
    hi there, i've got a strange problem using uibuttons, type custom. i'm placing 4 of those buttons on a scrollview, rotating each button by a random angle using CGAffineTransform. now it seems, that the buttons itself change size depending on the angle of rotation. can't get this problem solved :( UIGraphicsBeginImageContext(tempCtxSize); [cookbookImage drawInRect:CGRectMake(imgOffsetX, imgOffsetY+frmOffsetY, cookbookImage.size.width, cookbookImage.size.height)]; [cookbookFrame drawInRect:CGRectMake(0.0f, frmOffsetY, cookbookFrame.size.width, cookbookFrame.size.height)]; UIImage *combinedImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); ... ... UIButton *cookbookViewButton = [UIButton buttonWithType:UIButtonTypeCustom]; [cookbookViewButton setFrame:CGRectMake(0.0f, 0.0f, combinedImage.size.width, combinedImage.size.height)]; [cookbookViewButton setBackgroundColor:[UIColor clearColor]]; [cookbookViewButton setBackgroundImage:combinedImage forState:UIControlStateNormal]; CGAffineTransform rotation = [cookbookViewButton transform]; rotation = CGAffineTransformRotate(rotation, angle); // some random angle [cookbookViewButton setTransform:rotation]; thx for your help in advance!

    Read the article

  • Custom UIButton Memory Management in dealloc

    - by ddawber
    I am hoping to clarify the processes going on here. I have created a subclass of UIButton whose init method looks like this: - (id)initWithTitle:(NSString *)title frame:(CGRect)btnFrame { self = [UIButton buttonWithType:UIButtonTypeCustom]; [self setTitle:title forState:UIControlStateNormal]; self.frame = btnFrame; return self; } In my view controller I am creating one of these buttons and adding it as a subview: myButton = [[CustomButton alloc] initWithTitle:@"Title" frame:someFrame]; [self.view addSubview:myButton]; In the view controller's dealloc method I log the retain count of my button: - (void)dealloc { NSLog(@"RC: %d", [myButton retainCount]); //RC = 2 [super dealloc]; NSLog(@"RC: %d", [myButton retainCount]); //RC = 1 } The way I understand it, myButton is not actually retained, even though I invoked it using alloc, because in my subclass I created an autorelease button (using buttonWithType:). In dealloc, does this mean that, when dealloc is called the superview releases the button and its retain count goes down to 1? The button has not yet been autoreleased? Or do I need to get that retain count down to zero after calling [super dealloc]? Cheers.

    Read the article

  • Objective-C / UIButton / SetTitle

    - by apple92
    Does the setTitle method of UIButton retain the NSString passed as argument ? I guess I can rely on the fact that the property is defined as: property(nonatomic,readonly,retain) UILabel *titleLabel In this case, I think that it does retain the string. Thanks, Apple92

    Read the article

  • Animate move and scale of image UIButton

    - by Sam V
    I want it to be animated so I'm using [UIView beginAnimations] I've tried animating using button.imageView.frame (with image set as imageView) but it only animates the position, the image doesn't get scaled down at all. using hateButton.frame (when image is set as backgroundImage), the backgroundImage gets scaled down but it's not animated. How do I animate-scale a UIButton image?

    Read the article

  • UIButton to intercept UITableView's didSelectRowAtIndexPath method

    - by Michael
    I've got a UIButton on a table cell that is meant to pop up a UIActionSheet but the problem is the didSelectRowAtIndexPath captures that touch and its action takes precedence. Any clever way to override that action when the user touches the button and still have the default action when the user presses elsewhere in the cell? Too bad there is no MoveToFront property.

    Read the article

  • Subclassing UIButton.

    - by Joshua
    I would like to subclass UIButton so I can give it a fill image, left side image and right side image which I can't do in IB. All I can do in IB is give it a full background image which would mean the background would get stretched if the text was larger than the image. How would I do this? as unlike NSButton, there is no UIButtonCell class.

    Read the article

  • How can I change UIButton title color?

    - by HelloWorld
    I create a button programmatically button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [button addTarget:self action:@selector(aMethod:) forControlEvents:UIControlEventTouchDown]; [button setTitle:@"Show View" forState:UIControlStateNormal]; button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0); [view addSubview:button]; how can I change title color?

    Read the article

  • UIbutton stretchable

    - by mindfreak
    I have 2 images for UIbutton (1 for normal state and 1 for highlited state). When the button is highlited the height of button increases(as per image size) . I want that height of button should increase only from top and not from bottom. I mean it should stretch from top .is it possible ? if yes ,how ?

    Read the article

  • Vertical text in a Horizontal UIButton

    - by ArQangel
    I'm using a vertical UIButton in a portrait app (Just a normal button that is of width 60 and Height 160) I want to put the label Vetically down the button instead of across it. When I use the following code to rotate the label [workPackageButton.titleLabel setTransform:CGAffineTransformMakeRotation(M_PI / 2)]; It rotates the label but the length seems to be constrained by the original width, so I get the ... abreviation in the middle. Is there an easy way round this?

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >