티스토리 뷰

여기에 이미지 설명 입력예, 다음과 같은 다른 버튼을 클릭하여 동일한 웹보기에서 여러 링크를 열 수 있습니다.

 myWebView = UIWebView(frame: CGRectMake(0,0,   self.view.frame.size.width,self.view.frame.size.height-100))

        myWebView.delegate = self
                self.view.addSubview(myWebView)
                
                    let Button1 = UIButton(frame: CGRectMake(10,self.view.frame.size.height-50,50,50))
                             Button1.setTitle("Link 1", forState: .Normal)
                             
                                     Button1.setTitleColor(UIColor.redColor(), forState: .Normal)
                                             Button1.addTarget(self, action: #selector(button1Action), forControlEvents: .TouchUpInside)
                                             
                                                      self.view.addSubview(Button1)
                                                      
                                                      
                                                              let Button2 = UIButton(frame: CGRectMake(150,self.view.frame.size.height-50,50,50))
                                                                       Button2.setTitle("Link 1", forState: .Normal)
                                                                               Button2.setTitleColor(UIColor.redColor(), forState: .Normal)
                                                                               
                                                                                       Button2.addTarget(self, action: #selector(button2Action), forControlEvents: .TouchUpInside)
                                                                                       
                                                                                               self.view.addSubview(Button2)
                                                                                               
                                                                                                        let Button3 = UIButton(frame: CGRectMake(250,self.view.frame.size.height-50,50,50))
                                                                                                                 Button3.setTitle("Link 1", forState: .Normal)
                                                                                                                         Button3.setTitleColor(UIColor.redColor(), forState: .Normal)
                                                                                                                         
                                                                                                                                 Button3.addTarget(self, action: #selector(button3Action), forControlEvents: .TouchUpInside)
                                                                                                                                 
                                                                                                                                         self.view.addSubview(Button3)
                                                                                                                                              }
                                                                                                                                              
                                                                                                                                                   func button1Action()
                                                                                                                                                       {
                                                                                                                                                               let myUrl = NSURL(string: "https://www.google.co.in")
                                                                                                                                                               
                                                                                                                                                                       let request = NSMutableURLRequest(URL: myUrl!)
                                                                                                                                                                              myWebView.loadRequest(request)
                                                                                                                                                                              
                                                                                                                                                                                  }
                                                                                                                                                                                  
                                                                                                                                                                                       func button2Action()
                                                                                                                                                                                           {
                                                                                                                                                                                           
                                                                                                                                                                                                    let myUrl = NSURL(string: "http://stackoverflow.com/questions/tagged/ios")
                                                                                                                                                                                                            let request = NSMutableURLRequest(URL: myUrl!)
                                                                                                                                                                                                                    myWebView.loadRequest(request)
                                                                                                                                                                                                                    
                                                                                                                                                                                                                        }
                                                                                                                                                                                                                        
                                                                                                                                                                                                                            func button3Action()
                                                                                                                                                                                                                                {
                                                                                                                                                                                                                                        let myUrl = NSURL(string: "http://stackoverflow.com/questions/39916960/open-diffrent-webpage-with-button-on-single-viewcontroller")
                                                                                                                                                                                                                                                let request = NSMutableURLRequest(URL: myUrl!)
                                                                                                                                                                                                                                                        myWebView.loadRequest(request)
                                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                            }
                                                                                                                                                                                                                                                            

그리고 info.plist 앱 전송 보안 설정에서 임의로드를 허용하도록 설정하는 것을 잊지 마십시오.여기에 이미지 설명 입력



출처
https://stackoverflow.com/questions/39916960
댓글
공지사항
Total
Today
Yesterday
«   2025/08   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31