iOS 用html创建带下划线的链接(类似下划线按钮的功能)

来源:互联网 发布:致信oa端口 编辑:程序博客网 时间:2024/05/29 13:32

//改变文本的颜色和链接的颜色

 NSString *inf =@"<div><span style='font-size:15px;color: #999999'>提示:16:30前提交当日到账,其余次日到账,免手续费。部分跨行信用卡,3个工作日到账,建议您提前3个工作日还款。请阅读<a class=middle href='shuakaquhao'><font color='red'>信用卡还款说明。</font></a>您可以通过慧支付设备刷卡取号功能获取信用卡号。";

//改变链接线的颜色只能用css(改变连接线的宽度和颜色)

 NSString *fontName = [UIFontsystemFontOfSize:22].fontName;

    NSString *format = [NSStringstringWithFormat:@"<style>A {TEXT-DECORATION: none;padding:0 0 6 0;border-bottom-color:#888;border-bottom-width:5px; border-bottom-style:solid;}</style><style>body{-webkit-tap-highlight-color:transparent;-webkit-touch-callout: none; margin:12;background-color:transparent;font:14px/24px %@}</style>",fontName];


//然后用webView加载html字符串

 NSString *info = [NSStringstringWithFormat:@"%@%@",format,inf];

    [webView loadHTMLString:infobaseURL:nil];

    [self.viewaddSubview:webView];


ps:
//创建一个不带下划线的链接的字符串

NSString *htmlStr = @"<html><head><meta http-equiv='Content-Type' content='text/html; charset=gb2312' /><meta http-equiv='Content-Language' content='zh-cn' /></head><body><a href='/example/html/lastpage.html' style='text-decoration:none'>这是一个不带下划线的链接!</a>fdfdfdfdf佛挡杀佛涣发大号 hfdj大方点发大幅度发发大幅度发</body></html>";

//带下划线链接的html字符串

NSString *htmlStr =@"<html><body><a href=\"http://www.w3school.com.cn\">This is a link</a></body></html>";



0 0
原创粉丝点击