我们如何将样式表放在目标c中的head标签中

时间:2014-12-18 12:39:43

标签: html ios objective-c regex ios8

我想在html中插入样式标记。我的样式标签是finalstyle我想在邮件主体中插入插入。这段代码对我不起作用。最终的风格没有嵌入。

这是我的风格

$1<div ><style type="text/css"> p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 15.0px 'Helvetica Neue'} span.s1 {font-family: 'Helvetica Neue'; font-weight: bold; font-style: normal; font-size: 15.00px; text-decoration: underline} </style></div><br /><div style="border-left: 1px solid grey; padding-left: 15px"> –



replacements = [NSString stringWithFormat:@"$1<div>%@</div><br /><div style=\"border-left: 1px solid grey; padding-left: 15px\">", finalstyle]; 

 NSRegularExpression *regexs = [NSRegularExpression regularExpressionWithPattern:@"(<head.*?>)" options:NSRegularExpressionCaseInsensitive error:&error];
            mailBody = [regexs stringByReplacingMatchesInString:mailBody options:0 range:NSMakeRange(0, [mailBody length]) withTemplate:replacements];;

2 个答案:

答案 0 :(得分:0)

它正在运作。

NSString *fileStyle=@"<style type=\"text/css\"> p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 25.0px 'Helvetica Neue'} span.s1 {font-family: 'Helvetica Neue'; font-weight: bold; font-style: normal; font-size: 15.00px; text-decoration: underline} </style>";

NSString *emailBody = [NSString stringWithFormat:@"<html><head>%@</head><body><p class=\"p1\">sesfes</p></body></html>", fileStyle];

答案 1 :(得分:0)

NSRegularExpression *regexs = [NSRegularExpression regularExpressionWithPattern:@"(<p class=\"p2\".*?>)" options:NSRegularExpressionCaseInsensitive error:&error];
                mailBody = [regexs stringByReplacingMatchesInString:mailBody options:0 range:NSMakeRange(0, [mailBody length]) withTemplate:replacements];;
        NSLog(@"%@",mailBody);