Swift simple implementation of a general terms, disclaimer text + with linked display form

Source: Internet
Author: User

Effect: Img_f08dabe063a6-1.jpeg
Class Disclamerview:UIView {@objc weak var vc:uiviewcontroller?Custom protocol @IBInspectable var diy_protocol:string ="Diyprotocol"Hyperlink Address @IBInspectable var disclamerurlstr:string =" "Terms, Disclaimer Description text @IBInspectable var infostr = Str_disclaimerLink Address description @IBInspectable var linkstr =""The size of the display text (used to determine the size of the display area) @IBInspectable var font =Uifont.systemfont (ofsize:) Lazy var Infotextview:Uitextview = {Let TV =Uitextview () Tv.delegate =Self tv.iseditable =False Tv.backgroundcolor =Uicolor.clear tv.isscrollenabled =FalseSet the margin margin to 10, the left and right margins of each 10, the bottom margin of 0, and the left tv.textcontainerinset =Uiedgeinsetsmake (10,0,0,-5);Self.addsubview (TV)Return TV} () override Func awakefromnib () {Super.awakefromnib ()Self.backgroundcolor =Uicolor.grouptableviewbackground} override Func Draw (_ Rect:CGRect) {Drawing code Let Attri =Nsmutableattributedstring (attributedstring:Nsattributedstring (String:infostr + linkstr, attributes:[Nsattributedstringkey.foregroundcolor:Uicolor.darkgray,NSAttributedStringKey.font:font]))If linkstr! ="" {Attri.addattributes ([Nsattributedstringkey.link: (diy_protocol+"://")], Range: ((attri.string) asNSString). Range (OF:LINKSTR)} Infotextview.attributedtext = AttriLeft and right two days reserved 5 pixels infotextview.frame =CGRect (x:5, Y:0, Width:rect.width-5*2, Height:rect.height)}}extension Disclamerview:uitextviewdelegate{TextView has a super-linked monitor Agent Func TextView (_ TextView:Uitextview, Shouldinteractwith Url:url,In characterrange: nsrange), Bool { //Judgment Hyperlink protocol if Let sch = Url.scheme,sch = = Diy_protocol { //let NDVC = SFNEWSDETAILVC (nibname: "SFNEWSDETAILVC", Bundle:nil) //Ndvc.requsturl = DISCLAMERURLSTR; //if Let VC = VC as? uinavigationcontroller{ //Vc.pushviewcontroller (NDVC, animated:true) //}else{ //Ndvc.ispresent = True 
                                                                 
                                                                  //VC?. Present (NDVC, Animated:true, Completion:nil)/// 
                                                                  } return true} return false}} 
                                                                 
Xib using:
self.disclamerView.linkStr = @"点击查看详情"; // CGFloat dh = [STools getDisclaimerStrContentHeightWithDSize:CGSizeMake(SWIDTH - 5*2, 10000) dFont:self.disclamerView.font] + 18; self.h_disclamerView.constant = dh;
Image.png image.png Pure Code usage
    var disclamerView:DisclamerView = {        let dv = DisclamerView()        dv.backgroundColor = color_background        let dh = STools.getDisclaimerStrContentHeight(dFont: dv.font) + 18        dv.frame = CGRect(x: 0, y: 0,width: swidth, height: dh) dv.vc = self return dv }() self.tableView.tableFooterView = disclamerView

Swift simple implementation of a general terms, disclaimer text + with linked display form

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.