2011-07-19 17 views
24

मैं एक बटन के लिए आईबीएक्शन बनाना चाहता हूं, जब आप इसे दबाते हैं, तो ऐप पृष्ठभूमि में जाता है और साथ ही एक विशिष्ट लिंक पर सफारी खोलता है (उदाहरण के लिए "www.google.it") क्या आप मेरी मदद कर सकते हैं?आईओएस: एक लिंक बटन बनाएं

एक UITextView और नहीं एक UIButton बनाएँ, पाठ के रूप में लिंक बारे में TextView और में लिंक चेकबॉक्स का चयन करें:

उत्तर

59

अपने IBAction विधि के अंदर, आप इंटरफ़ेस बिल्डर का उपयोग करते हैं लाइन

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.google.com"]]; 
3

शामिल इंटरफेस बिल्डर। यह वह समय बन जाएगा जो आप रन टाइम पर चाहते हैं।

0
@interface ViewController : UIViewController<NSURLConnectionDelegate> 
@property (strong, nonatomic) IBOutlet UIButton *okbutton; 
@property (strong, nonatomic) IBOutlet UIButton *canel; 
@property (strong, nonatomic) IBOutlet UITextField *textfiled; 
- (IBAction)okButtonClick:(id)sender; 

- (IBAction)CanelButton:(id)sender; 



- (IBAction)okButtonClick:(id)sender { 


    NSString *searchString = textfiled.text; // UItextField.text 
    NSString *finalString = [NSString stringWithFormat:@"http://www.google.com/search?q=%@",searchString]; 

    [[UIApplication sharedApplication]openURL:[NSURL URLWithString:finalString]]; 



} 
2

तेज

UIApplication.sharedApplication().openURL(NSURL(string: "http://www.google.com")!) 

या तेज 3,0

UIApplication.shared.openURL(URL(string: "http://google.com")!) 
का उपयोग कर
संबंधित मुद्दे