LoginSignup
21
17

More than 5 years have passed since last update.

Swiftでテキストの一部をタップ可能なリンクにする(FRHyperLabel)

Last updated at Posted at 2015-12-28

スクリーンショット 2015-12-28 23.29.32.png

よくユーザー登録画面などに表示されている利用規約などでテキストの一部をタップ可能なリンクにしたい場合などに便利なFRHyperLabelの簡単な使い方

null09264/FRHyperLabel

CocoaPods

pod 'FRHyperLabel'

UILabelにFRHyperLabelを指定

Main_storyboard_と_新規投稿_-_Qiita.png

@IBOutlet weak var textLabel: FRHyperLabel!
textLabel?.text = "ユーザー登録をしたことにより\n利用規約に同意したことになります"
//抜き出したい文字をここで指定
textLabel?.setLinkForSubstring("利用規約", withLinkHandler: { string in
      print("画面遷移など")
})

withAttributeを使い装飾することも可能

スクリーンショット 2015-12-28 23.44.06.png

textLabel?.text = "ユーザー登録をしたことにより\n利用規約に同意したことになります"
textLabel?.setLinkForSubstring("利用規約", withAttribute: [NSForegroundColorAttributeName: UIColor.redColor()], andLinkHandler:  { label, string in
      print("画面遷移など")
})

21
17
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
21
17