2016-03-18 16 views
0

içinde http linki olabilir İçeriği görüntülemek için UICollectionView ürününü kullanacak bir uygulama üzerinde çalışıyorum. Hücre ya da etiketin safari içinde açılacak bir bağlantı (http) olmasını istiyorum. 2,1Swift: Hücre veya Etiket, bir UIcollectionView

var str = "Google" 
var attributedString = NSMutableAttributedString(string:str, attributes:[NSLinkAttributeName: NSURL(string: "http://www.google.com")!]) 

yourTextView.attributedText = attributedString 

u UILabel için bu kitaplığı deneyebilirsiniz

hızlı:

import UIKit 

class ViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate { 

var tableData: [String] = ["Data1", "Data2", "Data3"] 
var tableImages: [String] = ["img1.png", "img2.jpg", "img3.jpg"] 






override func viewDidLoad() { 




    // Do any additional setup after loading the view, typically from a nib. 
} 


func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 
    return tableData.count 
} 

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { 
    let cell: colvwCell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! colvwCell 

    cell.lblCell.text = tableData[indexPath.row] 
    cell.imgCell.image = UIImage(named: tableImages [indexPath.row]) 
    return cell 

} 

func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) { 
    print("Cell \(indexPath.row) selected") 

} 

cevap

0

Ben UITextView kullanmayı öneriyoruz göster ve ele dokun. Kod olmalıdır IB içeride UITextView temsilci ayarlamak ve bu

func textView(textView: UITextView, shouldInteractWithURL URL: NSURL, inRange characterRange: NSRange) -> Bool { 
     return true 
} 

fonk uygulamak için gerekli olan minimum ve IB enter image description here

bağlantıların algılanabilmesi için unutma da

@IBOutlet private weak var textView: UITextView! 

override func viewDidLoad() { 
    super.viewDidLoad() 
    textView.linkTextAttributes = [NSForegroundColorAttributeName: UIColor.blueColor()] 

    let text = NSMutableAttributedString() 
    text.beginEditing() 
    text.appendAttributedString(NSAttributedString(string: "google", attributes: [NSLinkAttributeName: NSURL(string: "http://www.google.com")!])) 
    text.endEditing() 

    textView.attributedText = text 
} 

aşağıdaki

İlgili konular