दिलचस्प पोस्ट
क्या एक कार्यक्रम संकलन के दौरान लाइब्रेरी पर निर्भर करता है, लेकिन रनटाइम नहीं? Excel CSV – संख्या सेल प्रारूप CMake का उपयोग करके Boost के साथ C ++ प्रोग्राम को लिंक कैसे करें I PHP का उपयोग कर फ़ोल्डर से सभी फाइलों को हटाना? फ़ोल्डर में एक निश्चित एक्सटेंशन के साथ एक फ़ाइल खोजें ग्रिड दृश्य आइटम वर्ग बनाना एंड्रॉइड स्टूडियो "आर" को प्रतीक आर के हल नहीं कर सकता है, लेकिन लाल रंग के साथ लाल रंग में आर मारता है, लेकिन सफल बनाते हैं वैध ईमेल पते की जांच करने के लिए पायथन? उत्पत्ति को ggplot2 (R) में 0 पर प्रारंभ करने के लिए मजबूर करें जावा: क्या एखेल (स्ट्रिंग, स्ट्रिंग) विश्वसनीय है? क्यों इंटरफ़ेस परत / सार वर्ग हमारे परियोजना में आवश्यक है? टैब बार पर निष्क्रिय आइकन / पाठ रंग कैसे बदल सकता है? एंड्रॉइड: एक गतिविधि संदर्भ के बाहर WebView का उपयोग करना एंड्रॉइड गैलरी से ImageView में छवि प्राप्त करें Content_main.xml और activity_main.xml के बीच का अंतर?

मैं एक बुनियादी UIButton प्रोग्राम कैसे बनाऊं?

मैं एक बुनियादी UIButton प्रोग्राम को कैसे बना सकता हूं? उदाहरण के लिए मेरे दृश्य नियंत्रक में, viewDidLoad विधि निष्पादित करते समय, तीन UIButton को गतिशील रूप से बनाया जाएगा और इसके लेआउट या गुण सेट किए गए हैं।

Solutions Collecting From Web of "मैं एक बुनियादी UIButton प्रोग्राम कैसे बनाऊं?"

यहां एक है:

 UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [button addTarget:self action:@selector(aMethod:) forControlEvents:UIControlEventTouchUpInside]; [button setTitle:@"Show View" forState:UIControlStateNormal]; button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0); [view addSubview:button]; 
 - (void)viewDidLoad { [super viewDidLoad]; [self addMyButton]; // Call add button method on view load } - (void)addMyButton{ // Method for creating button, with background image and other properties UIButton *playButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain]; playButton.frame = CGRectMake(110.0, 360.0, 100.0, 30.0); [playButton setTitle:@"Play" forState:UIControlStateNormal]; playButton.backgroundColor = [UIColor clearColor]; [playButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal ]; UIImage *buttonImageNormal = [UIImage imageNamed:@"blueButton.png"]; UIImage *strechableButtonImageNormal = [buttonImageNormal stretchableImageWithLeftCapWidth:12 topCapHeight:0]; [playButton setBackgroundImage:strechableButtonImageNormal forState:UIControlStateNormal]; UIImage *buttonImagePressed = [UIImage imageNamed:@"whiteButton.png"]; UIImage *strechableButtonImagePressed = [buttonImagePressed stretchableImageWithLeftCapWidth:12 topCapHeight:0]; [playButton setBackgroundImage:strechableButtonImagePressed forState:UIControlStateHighlighted]; [playButton addTarget:self action:@selector(playAction:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:playButton]; } 

उद्देश्य सी

 UIButton *but= [UIButton buttonWithType:UIButtonTypeRoundedRect]; [but addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; [but setFrame:CGRectMake(52, 252, 215, 40)]; [but setTitle:@"Login" forState:UIControlStateNormal]; [but setExclusiveTouch:YES]; // if you like to add backgroundImage else no need [but setbackgroundImage:[UIImage imageNamed:@"XXX.png"] forState:UIControlStateNormal]; [self.view addSubview:but]; -(void) buttonClicked:(UIButton*)sender { NSLog(@"you clicked on button %@", sender.tag); } 

तीव्र

  let myButton = UIButton() // if you want to set the type use like UIButton(type: .RoundedRect) or UIButton(type: .Custom) myButton.setTitle("Hai Touch Me", forState: .Normal) myButton.setTitleColor(UIColor.blueColor(), forState: .Normal) myButton.frame = CGRectMake(15, 50, 300, 500) myButton.addTarget(self, action: "pressedAction:", forControlEvents: .TouchUpInside) self.view.addSubview( myButton) func pressedAction(sender: UIButton!) { // do your stuff here NSLog("you clicked on button %@", sender.tag) } 

स्विफ्ट 3 और इसके बाद के संस्करण

  let myButton = UIButton() // if you want to set the type use like UIButton(type: .RoundedRect) or UIButton(type: .Custom) myButton.setTitle("Hi, Click me", for: .normal) myButton.setTitleColor(UIColor.blue, for: .normal) myButton.frame = CGRect(x: 15, y: 50, width: 300, height: 500) myButton.addTarget(self, action: #selector(pressedAction(_:)), for: .touchUpInside) self.view.addSubview( myButton) func pressedAction(_ sender: UIButton) { // do your stuff here print("you clicked on button \(sender.tag)") } 

अपने नियंत्रक के दृश्य के लिए प्रोग्राम को एक बटन जोड़ने के लिए, निम्न का उपयोग करें:

 -(void)viewDidLoad { UIButton * btn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; btn.frame = CGRectMake(0, 0, 100, 50); [btn setTitle:@"Hello, world!" forState:UIControlStateNormal]; [self.view addSubview:btn]; } 

इनमें से तीन को जोड़ने के लिए, कुल्ला और दोहराएँ।

यहां आप गतिशील रूप से एक UIButton बना सकते हैं:

 //For button image UIImage *closebtnimg = [UIImage imageNamed:@"close_btn.png"]; //Custom type button btnclose = [[UIButton buttonWithType:UIButtonTypeCustom]retain]; //Set frame of button means position btnclose.frame = CGRectMake(103, 257, 94, 32); //Button with 0 border so it's shape like image shape [btnclose.layer setBorderWidth:0]; //Set title of button [btnclose setTitle:@"CLOSE" forState:UIControlStateNormal]; [btnclose addTarget:self action:@selector(methodname:) forControlEvents:UIControlEventTouchUpInside]; //Font size of title btnclose.titleLabel.font = [UIFont boldSystemFontOfSize:14]; //Set image of button [btnclose setBackgroundImage:closebtnimg forState:UIControlStateNormal]; 

आओ, यह 2014 का है! क्यों नहीं कोड ब्लॉक मूल्यांकन मूल्यांकन अभी तक उपयोग किया जा रहा है, क्योंकि प्रवृत्तियों से पता चलता है कि यह भविष्य है!

 UIButton* button = ({ //initialize button with frame UIButton* button = [[UIButton alloc] initWithFrame:({ CGRect frame = CGRectMake(10.0, 10.0, 200.0, 75.0); frame; })]; //set button background color [button setBackgroundColor:({ UIColor* color = [UIColor colorWithRed:1.0 green:1.0 blue:0.0 alpha:1.0]; color; })]; //set button title for state [button setTitle:({ NSString* string = [NSString stringWithFormat:@"title words"]; string; }) forState:({ UIControlState state = UIControlStateNormal; state; })]; //set selector [button addTarget:self action:({ SEL select = @selector(method:); select; }) forControlEvents:({ UIControlEvents event = UIControlEventTouchUpInside; event; })]; //return button button; }); [self.view addSubview:button]; 

रुको!

रुको!

या सटीक परिणाम इस प्रकार पूरा किया जा सकता है:

 UIButton* button = [[UIButton alloc] initWithFrame:CGRectMake(10.0, 10.0, 200.0, 75.0)]; [button setBackgroundColor:[UIColor colorWithRed:1.0 green:1.0 blue:0.0 alpha:1.0]]; [button setTitle:@"title words" forState:UIControlStateNormal]; [button addTarget:self action:@selector(method:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button]; 

'action:@selector(aMethod:)' इस प्रकार की विधि लिखें:

 - (void)aMethod:(UIButton*)button { NSLog(@"Button clicked."); } 

इससे मेरा काम बनता है। धन्यवाद। एस।

उद्देश्य सी

 // Create the Button with RoundedRect type UIButton *mybutton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; // instend of "Click Me" you can write your own message/Label [mybutton setTitle:@"Click Me" forState:UIControlStateNormal]; // create the Rectangle Frame with specified size mybutton.frame = CGRectMake(10, 10, 300, 140); // x,y,width,height [self.view addSubview:mybutton];// add button to your view. 

तीव्र

 let button = UIButton(type: UIButtonType.System) as UIButton button.frame = CGRectMake(100, 100, 100, 50) button.backgroundColor = UIColor.greenColor() button.setTitle("Test Button", forState: UIControlState.Normal) self.view.addSubview(button) 

एक बटन बनाने के लिए इस कोड को आज़माएं और इसे विभिन्न निर्देशांक के साथ दो बार दोहराएं और विधि (myButtonClick) कहा जाता है जब बटन दबाया जाता है

 UIButton *editButton = [UIButton buttonWithType: UIButtonTypeCustom]; editButton.frame = CGRectMake(0, 0, width, height); [editButton setBackgroundImage: editButtonImage forState: UIControlStateNormal]; [myButton addTarget:self action:@selector(myButtonClick:) forControlEvents:UIControlEventTouchUpInside]; editButton.adjustsImageWhenHighlighted = YES; editButton.titleLabel.text = @"Edit"; editButton.titleLabel.textColor = [UIColor whiteColor]; editButton.titleLabel.textAlignment = UITextAlignmentCenter; editButton.titleLabel.font = [UIFont fontWithName: @"Helvetica" size: 14]; [self.view addSubview: editButton]; -(void) myButtonClick:(NSString *)myString{ NSLog(@"you clicked on button %@", myString); } 

आप केवल एक निर्माता के उदाहरण को एक पाश के भीतर रख सकते हैं और यदि आप चाहें तो एक सरणी से नामों को गतिशील रूप से जोड़ सकते हैं।

इस कोड की जांच करें

 CGRect frameimg = CGRectMake(15, 46, 55,70); UIButton *SelectionButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; SelectionButton.frame=frameimg; SelectionButton.tag=i; [SelectionButton setTitle:[SelectionArray objectAtIndex:0] forState:UIControlStateNormal]; [SelectionButton addTarget:self action:@selector(BtnSelected:) forControlEvents:UIControlEventTouchUpInside]; [SelectionButton.titleLabel setFont:[UIFont boldSystemFontOfSize:12.0]]; SelectionButton.titleLabel.lineBreakMode = NSLineBreakByWordWrapping; SelectionButton.titleLabel.numberOfLines = 2; SelectionButton.titleLabel.textAlignment = NSTextAlignmentCenter; [SelectionButton setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)]; [SelectionButton setTitleColor:[UIColor blueColor] forState:UIControlStateSelected]; [SelectionButton setShowsTouchWhenHighlighted:YES]; [self.view addSubview:SelectionButton]; 

मुझे आशा है कि यह कोड आपके लिए उपयोगी है।

 UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [button addTarget:self action:@selector(aMethod:) forControlEvents:UIControlEventTouchUpInside]; [button setTitle:@"Show View" forState:UIControlStateNormal]; button.frame = CGRectMake(10.0, 100.0, 300.0, 20.0); [self.view addSubview:button]; 
 UIButton *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]; 
 -(UIButton *)addButton:(NSString *)title :(CGRect)frame : (SEL)selector :(UIImage *)image :(int)tag{ UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; btn.frame = frame; [btn addTarget:self action:selector forControlEvents:UIControlEventTouchUpInside]; [btn setTitle:title forState:UIControlStateNormal]; [btn setImage:image forState:UIControlStateNormal]; btn.backgroundColor = [UIColor clearColor]; btn.tag = tag; return btn; } 

और आप इसे इस दृश्य में जोड़ सकते हैं:

 [self.view addSubview:[self addButton:nil :self.view.frame :@selector(btnAction:) :[UIImage imageNamed:@"img.png"] :1]]; 

यह एक उदाहरण भी है जिससे तीन बटन बनाए जा सकते हैं। बस उनके स्थान को स्थानांतरित करें

 UIImage *buttonOff = [UIImage imageNamed:@"crysBallNorm.png"]; UIImage *buttonOn = [UIImage imageNamed:@"crysBallHigh.png"]; UIButton *predictButton = [UIButton alloc]; predictButton = [UIButton buttonWithType:UIButtonTypeCustom]; predictButton.frame = CGRectMake(180.0, 510.0, 120.0, 30.0); [predictButton setBackgroundImage:buttonOff forState:UIControlStateNormal]; [predictButton setBackgroundImage:buttonOn forState:UIControlStateHighlighted]; [predictButton setTitle:@"Predict" forState:UIControlStateNormal]; [predictButton setTitleColor:[UIColor purpleColor] forState:UIControlStateNormal]; [predictButton addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:predictButton]; 

आप इस कोड से बटन बना सकते हैं।

  UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; [btn addTarget:self action:@selector(btnAction) forControlEvents:UIControlEventTouchDragInside]; [btn setTitle:@"click button" forState:UIControlStateNormal]; btn.frame = CGRectMake(50, 100, 80, 40); [self.view addSubview:btn]; 

यहां बटन कार्रवाई विधि है

  -(void)btnAction { NSLog(@"button clicked"); } 

स्विफ्ट 2.0 के लिए:

 let btnObject : UIButton = UIButton() btnObject.frame = CGRect(x: 8, y: 89, width: 70, height: 22) btnObject.titleLabel?.font = UIFont(name: "Helvetica Neue", size: 13) btnObject.titleLabel?.textColor = UIColor.whiteColor() btnObject.backgroundColor = UIColor(red: 189/255, green: 176/255, blue: 0/255, alpha: 1) btnObject.titleLabel?.textAlignment = NSTextAlignment.Center btnObject.addTarget(self, action: "btnbtnObjectClick:", forControlEvents: UIControlEvents.TouchUpInside) subView.addSubview(btnObject) 

UIButton प्रोग्राम बनाने के लिए हम उद्देश्य सी और तेज दोनों में बना सकते हैं

स्विफ्ट 3

 let buttonSwift = UIButton(type: UIButtonType.system) as UIButton //OR let buttonSwift = UIButton(type: UIButtonType.Custom) as UIButton //Set Frame for Button buttonSwift.frame = CGRect(x: 100, y: 100, width: 200, height: 100) //Set title for button buttonSwift.setTitle("ClickMe", for: .normal) //If you want to set color for button title buttonSwift.setTitleColor(UIColor.white, for: .normal) //If you want to set Background color for button buttonSwift.backgroundColor = UIColor.black //If you want to set tag for button buttonSwift.tag = 0 //If you want to add or set image for button let image = UIImage(named: "YourImageName") as UIImage? buttonSwift.setImage(image, for: .normal) //If you want to add or set Background image for button buttonSwift.setBackgroundImage(image, for: .normal) //Add action for button buttonSwift.addTarget(self, action: #selector(actionPressMe), for:.touchUpInside) //Add button as SubView to Super View self.view.addSubview(buttonSwift) 

UIButton क्रिया विधि

 func actionPressMe(sender: UIButton!) { NSLog("Clicked button tag is %@", sender.tag) OR print("Clicked button tag is \(sender.tag)") //Then do whatever you want to do here ........ } 

उद्देश्य सी

 UIButton *buttonObjectiveC = [UIButton buttonWithType:UIButtonTypeCustom]; OR UIButton *buttonObjectiveC = [UIButton buttonWithType:UIButtonTypeSystem]; buttonObjectiveC.frame = CGRectMake(200, 100, 200, 100); //Set title for button [buttonObjectiveC setTitle:@"ClickMe" forState:UIControlStateNormal]; //If you want to set color for button title [buttonObjectiveC setTitleColor:[UIColor whiteColor] forState: UIControlStateNormal]; //If you want to set Background color for button [buttonObjectiveC setBackgroundColor:[UIColor blackColor]]; //If you want to set tag for button buttonSwift.tag = 0; //If you want to add or set image for button UIImage *image = [UIImage imageNamed:@"YourImageName"]; [buttonObjectiveC setImage:image forState:UIControlStateNormal]; //If you want to add or set Background image for button [buttonObjectiveC setBackgroundImage:image forState:UIControlStateNormal]; //Add action for button [buttonObjectiveC addTarget:self action:@selector(actionPressMe:)forControlEvents:UIControlEventTouchUpInside]; //Add button as SubView to Super View [self.view addSubview:buttonObjectiveC]; 

UIButton क्रिया विधि

 - (void)actionPressMe:(UIButton *)sender { NSLog(@"Clicked button tag is %@",sender.tag); //Then do whatever you want to do here .......... } 

आउटपुट स्क्रीनशॉट है

यहां छवि विवरण दर्ज करें

यहां छवि विवरण दर्ज करें

 -(void)addStuffToView { UIButton *aButton = [[UIButton alloc] initWithFrame:CGRectMake(20, 20, 20, 20)]; //(x, y, width, height of button on screen [aButton setTitle:@"Button" forState:UIControlStateNormal];//puts the text on the button aButton.titleLabel.font = somefont;//sets the font if one is already stated aButton.titleLabel.font = [UIFont fontWithName:@"Arial-MT" size:12];//sets the font type and size [aButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];//see back method below [aButton setBackgroundImage:[UIImage imageNamed:@"someImage.png"] forState:UIControlStateNormal];//sets the image of the button [self.view addSubview:back]; } -(void)back { UIAlertView *alert = [[UIAlertView alloc]initWithTitle.....] } -(void)viewDidLoad { [super viewDidLoad]; [self addStuffToView];//adds all items built in this method to the view } 

आप इसे अपने ViewDidLoad विधि में लागू कर सकते हैं:

 continuebtn = [[UIButton alloc]initWithFrame:CGRectMake(10, 100, view1.frame.size.width-20, 40)]; [continuebtn setBackgroundColor:[UIColor grayColor]]; [continuebtn setTitle:@"Continue" forState:UIControlStateNormal]; continuebtn.layer.cornerRadius = 10; continuebtn.layer.borderWidth =1.0; continuebtn.layer.borderColor = [UIColor blackColor].CGColor; [continuebtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; [continuebtn addTarget:self action:@selector(continuetonext) forControlEvents:UIControlEventTouchUpInside]; [view1 addSubview:continuebtn]; 

जहां continuetonext है:

 -(void)continuetonext { GeneratePasswordVC *u = [[GeneratePasswordVC alloc]init]; [self.navigationController pushViewController:u animated:YES]; } 

स्विफ्ट 3 के अनुसार, सिंटेक्स में कई बदलाव किए गए हैं।

स्विफ्ट 3 की तरह मूल बटन बनाने के बारे में यहां बताया गया है:

  let button = UIButton(type: UIButtonType.system) as UIButton button.frame = CGRect(x: 100, y: 100, width: 100, height: 50) button.backgroundColor = UIColor.green button.setTitle("Example Button", for: UIControlState.normal) self.view.addSubview(button) 

स्विफ्ट के पिछले संस्करणों के बाद से ये बदलाव किए गए हैं:

 let button = UIButton(type: UIButtonType.System) as UIButton // system no longer capitalised button.frame = CGRectMake(100, 100, 100, 50) // CGRectMake has been removed as of Swift 3 button.backgroundColor = UIColor.greenColor() // greenColor replaced with green button.setTitle("Example Button", forState: UIControlState.Normal) // normal is no longer capitalised self.view.addSubview(button) 

कोशिश करो….

 UIButton *finalPriceBtn=[UIButton buttonWithType:UIButtonTypeRoundedRect]; finalPriceBtn.frame=CGRectMake(260, 25, 45, 15); [finalPriceBtn addTarget:self action:@selector(goBtnClk:) forControlEvents:UIControlEventTouchUpInside]; finalPriceBtn.titleLabel.font=[UIFont systemFontOfSize:12]; [finalPriceBtn setTitle:[NSString stringWithFormat:@"$%.2f",tempVal] forState:UIControlStateNormal]; finalPriceBtn.titleLabel.textColor = [UIColor colorWithRed: 2.0f/255.0f green: 155.0f/255.0f blue: 213.0f/255.0f alpha:1]; finalPriceBtn.titleLabel.textAlignment=UITextAlignmentLeft; [imageView addSubview:finalPriceBtn]; 

आशा है कि मैंने मदद की

 UIButton *custombutton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [custombutton addTarget:self action:@selector(aMethod:) forControlEvents:UIControlEventTouchUpInside]; [custombutton setTitle:@"Click" forState:UIControlStateNormal]; custombutton.frame = CGRectMake(80.0, 110.0, 160.0, 40.0); custombutton.titleLabel.textColor = [UIColor colorWithRed: 2.0f/255.0f green: 155.0f/255.0f blue: 213.0f/255.0f alpha:1]; [custombutton setImage:[UIImage imageNamed:@"hh.png"] forState:UIControlStateNormal]; [view addSubview:custombutton]; 

**

 UIButton *buttonName = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [buttonName addTarget:self action:@selector(aMethod:)forControlEvents:UIControlEventTouchDown]; [buttonName setTitle:@"Show View" forState:UIControlStateNormal]; .frame = CGRectMake(80.0, 210.0, 160.0, 40.0); [view addSubview:buttonName]; 

**

स्विफ्ट 2.2 के लिए (नए "चयनकर्ता" घोषणा के साथ)

 let btn = UIButton(type: UIButtonType.System) as UIButton btn.frame = CGRectMake(0, 0, 100, 20) // set any frame you want btn.setTitle("MyAction", forState: UIControlState.Normal) btn.addTarget(self, action: #selector(MyClass.myAction(_:)), forControlEvents: UIControlEvents.TouchUpInside) self.view.addSubview(btn) func myAction(sender:UIButton!){ // Some action } 

स्विफ्ट 3 के लिए (यहां तक ​​कि कम कोड)

 let button = UIButton(type: UIButtonType.custom) button.frame = CGRect(x: 0, y: 0, width: 200.0, height: 40.0) button.addTarget(nil, action: #selector(tapButton(_:)), for: UIControlEvents.touchUpInside) button.tintColor = UIColor.white button.backgroundColor = UIColor.red button.setBackgroundImage(UIImage(named: "ImageName"), for: UIControlState.normal) button.setTitle("MyTitle", for: UIControlState.normal) button.isEnabled = true func tapButton(sender: UIButton) { } 

स्विफ्ट 3 वर्जन होना चाहिए

 let myButton:UIButton = { let myButton = UIButton() // if you want to set the type use like UIButton(type: .RoundedRect) or UIButton(type: .Custom) myButton.setTitle("Hai Touch Me", for: .normal) myButton.setTitleColor(UIColor.blue, for: .normal) myButton.frame = CGRect(x: 20, y: 20, width: 100, height: 40) myButton.addTarget(self, action: #selector(ViewController.pressedAction(_:)), for: .touchUpInside) self.view.addSubview(myButton) return myButton }() 
 UIButton *btnname = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [btnname setTitle:@"Click Me" forState:UIControlStateNormal]; btnname.frame = CGRectMake(10, 10, 100, 140); [self.view addSubview:btnname]; 
 UIButton * tmpBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [tmpBtn addTarget:self action:@selector(clearCart:) forControlEvents:UIControlEventTouchUpInside]; tmpBtn.tag = k; tmpBtn.frame = CGRectMake(45, 0, 15, 15); [tmpBtn setBackgroundImage:[UIImage imageNamed:@"CloseButton.png"] forState:UIControlStateNormal]; [self.view addSubview:tmpBtn]; 

इस तरह से मैंने UIButton प्रोग्राम को बनाया है

  UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [button addTarget:self action:@selector(aMethod:) forControlEvents:UIControlEventTouchUpInside]; [button setTitle:@"Show View" forState:UIControlStateNormal]; button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0); [view addSubview:button];