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